class pystruct.learners.LatentSSVM(base_ssvm, latent_iter=5, logger=None)[source]

Stuctured SVM solver for latent-variable models.

This is a hard-EM-style algorithm that alternates between latent variable completion for the ground truth and learning the parameters with the latent variables held fixed using the base_ssvm solver.

The model is expected to know how to initialize itself - it should provide a init_latent procedure. Optionally the H_init parameter can be passed to fit, to explicitly initialize the latent variables in the first iteration.

If the base_ssvm is an n-slack SSVM, the current constraints will be adjusted after recomputing the latent variables H. If the base_ssvm is a 1-slack SSVM, the inference cache will be reused. Both methods drastically speed up learning.

If base_ssvm is an 1-slack SSVM, this corresponds to the approach of Yu and Joachims, Learning Structural SVMs with Latent Variables.


base_ssvm : object

SSVM solver instance for solving the completed problem.

latent_iter : int (default=5)

Number of iterations in the completion / refit loop.

logger : object

Logger instance.


w : nd-array, shape=(model.size_joint_feature,)

The learned weights of the SVM.


fit(X, Y[, H_init, initialize]) Learn parameters using the concave-convex procedure.
get_params([deep]) Get parameters for this estimator.
score(X, Y) Compute score as 1 - loss over whole data set.
set_params(**params) Set the parameters of this estimator.
__init__(base_ssvm, latent_iter=5, logger=None)[source]
fit(X, Y, H_init=None, initialize=True)[source]

Learn parameters using the concave-convex procedure.

If no H_init is given, the latent variables are initialized using the init_latent method of the model.


X : iterable

Traing instances. Contains the structured input objects. No requirement on the particular form of entries of X is made.

Y : iterable

Training labels. Contains the strctured labels for inputs in X. Needs to have the same length as X.

H_init : iterable, optional

Initial values for the latent variables.

initialize : boolean, default=True

Whether to initialize the model for the data. Leave this true except if you really know what you are doing.


Get parameters for this estimator.


deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.


params : mapping of string to any

Parameter names mapped to their values.

score(X, Y)[source]

Compute score as 1 - loss over whole data set.

Returns the average accuracy (in terms of model.loss) over X and Y.


X : iterable

Evaluation data.

Y : iterable

True labels.


score : float

Average of 1 - loss over training examples.


Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self :