pyconstruct.learners.BaseSSG

class pyconstruct.learners.BaseSSG(domain=None, model=None, *, inference='loss_augmented_map', alpha=0.0001, train_loss='hinge', structured_loss=None, n_jobs=1, shuffle=True, warm_start=False, verbose=True, batch_size=None, validate=True, random_state=None, **kwargs)

Base implementation of a learner with the subgradient algorithm.

This class implements the backbone of a learner that uses the Stochastic Subgradient descent method [1] for updating the weights of a linear model. The partial_fit method takes care of making inference and calling a gradient step for each example in the batch. Implementations may use different methods for making a gradient step.

Parameters:
  • domain (BaseDomain) – The domain of the data.
  • inference (str in ['map', 'loss_augmented_map']) – Which type of inference to perform when learning.
  • alpha (float) – The regularization coefficient.
  • train_loss (str in ['hinge', 'logistic', 'exponential']) – The training loss. The derivative of this loss is used to rescale the margin of the examples when making an update.
  • structured_loss (function (y, y) -> float) – The structured loss to compute on the objects.
  • n_jobs (int) – The number of parallel jobs used when calculating the gradient steps.
  • shuffle (bool) – Wheter to shuffle the data prior to fitting.
  • warm_start (bool) – If True, the model is not reinitialized upon a second call to the fit method, and the parameters of the fit method are reused.
  • verbose (bool) – Whether to print the training losses when fitting.
  • batch_size (None or int) – The size of the batches used when fitting the data. If None, the batch size will be equal to n_jobs.
  • validate (bool) – Whether to validate the model using the training examples prior to the update. Only used when verbose is True.
  • random_state (None, int, RandomState) – The random number generator seed.

References

[1]Ratliff, Nathan D., J. Andrew Bagnell, and Martin A. Zinkevich. “(Online) Subgradient Methods for Structured Prediction.” Artificial Intelligence and Statistics. 2007.

Methods

decision_function(X, Y, **kwargs)
fit(X, Y, **kwargs) Fit a model with data (X, Y).
get_params([deep]) Get parameters for this estimator.
loss(X, Y, Y_pred, **kwargs)
partial_fit(X, Y[, Y_pred, Y_phi, Y_pred_phi]) Updates the current model with a mini-batch (X, Y).
phi(X, Y, **kwargs) Computes the feature vector for the given input and output objects.
predict(X, *args, **kwargs) Computes the prediction of the current model for the given input.
score(X, Y[, Y_pred]) Compute the score as the average loss over the examples.
set_params(**params) Set the parameters of this estimator.