Module ImportFrom alias Import alias identifier ImportFrom alias alias alias ImportFrom alias ImportFrom alias ImportFrom alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Num Num Num Num Str Num Num Num Num NameLoad NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad body Expr Str If CompareGt AttributeLoad NameLoad attr Num body Print Str If NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr If UnaryOpNot NameLoad body Assign AttributeStore NameLoad attr Call NameLoad NameLoad Str Call AttributeLoad AttributeLoad NameLoad attr attr Num Num keyword AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr ListLoad Call NameLoad Assign AttributeStore NameLoad attr ListLoad If CompareEq AttributeLoad NameLoad attr Str body Assign AttributeStore NameLoad attr BinOpMult AttributeLoad NameLoad attr Call NameLoad NameLoad orelse Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr orelse Assign SubscriptStore AttributeLoad NameLoad attr Index Num BinOpSub Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call NameLoad NameLoad TryExcept body For NameStore Call NameLoad AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpSub Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Num Assign NameStore Num If CompareEq AttributeLoad NameLoad attr Num body For TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore BinOpSub Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign NameStore BinOpAdd UnaryOpUSub Call AttributeLoad NameLoad attr NameLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad AugAssignAdd NameStore Call AttributeLoad NameLoad attr NameLoad Num If CompareGt NameLoad Num body AugAssignAdd NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad orelse If CompareEq AttributeLoad NameLoad attr Num body Assign NameStore Call NameLoad orelse Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr BinOpDiv Call NameLoad Call NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad For NameStore NameLoad body Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore BinOpSub AttributeLoad NameLoad attr Num Assign NameStore Call Call NameLoad keyword AttributeLoad NameLoad attr keyword NameLoad GeneratorExp Call Call NameLoad NameLoad AttributeLoad NameLoad attr NameLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr For TupleStore NameStore NameStore NameStore Call NameLoad NameLoad NameLoad NameLoad body Assign TupleStore NameStore NameStore NameStore NameStore NameLoad AugAssignAdd NameStore NameLoad AugAssignAdd NameStore NameLoad If CompareGt NameLoad Num body AugAssignAdd NameStore Num AugAssignDiv NameStore Call NameLoad Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad AugAssignMult NameStore AttributeLoad NameLoad attr AugAssignAdd NameStore BinOpDiv Call AttributeLoad NameLoad attr BinOpPow AttributeLoad NameLoad attr Num Num If CompareEq NameLoad Num body Print Str If AttributeLoad NameLoad attr body Break If CompareGt AttributeLoad NameLoad attr Num body Print NameLoad Print BinOpMod Str NameLoad Print BinOpMod Str TupleLoad NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If CompareGt AttributeLoad NameLoad attr Num body Print AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad If CompareIsNot AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad handlers ExceptHandler type NameLoad body Pass Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpSub Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad NameLoad attr NameLoad NameLoad If CompareIsNot AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad Str If AttributeLoad NameLoad attr body If AttributeLoad NameLoad attr body Print BinOpMod Str SubscriptLoad AttributeLoad NameLoad attr Index Num If BoolOpAnd AttributeLoad NameLoad attr CompareEq AttributeLoad NameLoad attr Num body Print BinOpMod Str AttributeLoad AttributeLoad NameLoad attr attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Return ListComp Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If Call NameLoad AttributeLoad NameLoad attr Str body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr orelse Assign NameStore ListComp Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr comprehension TupleStore NameStore NameStore Call NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad Assign NameStore ListComp Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad comprehension NameStore NameLoad Return BinOpSub Num BinOpDiv Call AttributeLoad NameLoad attr NameLoad Call NameLoad Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Assign NameStore Call Call NameLoad keyword AttributeLoad NameLoad attr keyword BinOpSub AttributeLoad NameLoad attr Num GeneratorExp Call Call NameLoad NameLoad AttributeLoad NameLoad attr NameLoad NameLoad AttributeLoad NameLoad attr comprehension TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad Call NameLoad Call NameLoad NameLoad Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Num Assign NameStore BinOpAdd BinOpMult Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr BinOpDiv Call AttributeLoad NameLoad attr BinOpPow AttributeLoad NameLoad attr Num Num Return NameLoad decorator_list decorator_list
N/A time time N/A numpy np sklearn.externals.joblib Parallel delayed cpu_count sklearn.utils gen_even_slices subgradient_ssvm SubgradientSSVM utils find_constraint_latent SubgradientLatentSSVM N/A SubgradientSSVM N/A N/A Latent Variable Structured SVM solver using subgradient descent.

    Implements a margin rescaled with l1 slack penalty.
    By default, a constant learning rate is used.
    It is also possible to use the adaptive learning rate found by AdaGrad.

    This class implements online subgradient descent. If n_jobs != 1,
    small batches of size n_jobs are used to exploit parallel inference.
    If inference is fast, use n_jobs=1.

    Parameters
    ----------
    model : StructuredModel
        Object containing model structure. Has to implement
        `loss`, `inference` and `loss_augmented_inference`.

    max_iter : int, default=100
        Maximum number of passes over dataset to find constraints and perform
        updates.

    C : float, default=1.
        Regularization parameter

    verbose : int, default=0
        Verbosity.

    learning_rate : float or 'auto', default='auto'
        Learning rate used in subgradient descent. If 'auto', the pegasos
        schedule is used, which starts with ``learning_rate = n_samples * C``.

    momentum : float, default=0.0
        Momentum used in subgradient descent.

    n_jobs : int, default=1
        Number of parallel jobs for inference. -1 means as many as cpus.

    show_loss_every : int, default=0
        Controlls how often the hamming loss is computed (for monitoring
        purposes). Zero means never, otherwise it will be computed very
        show_loss_every'th epoch.

    decay_exponent : float, default=1
        Exponent for decaying learning rate. Effective learning rate is
        ``learning_rate / (decay_t0 + t)** decay_exponent``. Zero means no decay.

    decay_t0 : float, default=10
        Offset for decaying learning rate. Effective learning rate is
        ``learning_rate / (decay_t0 + t)** decay_exponent``.

    break_on_no_constraints : bool, default=True
        Break when there are no new constraints found.

    averaging : string, default=None
        Whether and how to average weights. Possible options are 'linear', 'squared' and None.
        The string reflects the weighting of the averaging:

            - linear: ``w_avg ~ w_1 + 2 * w_2 + ... + t * w_t``

            - squared: ``w_avg ~ w_1 + 4 * w_2 + ... + t**2 * w_t``

        Uniform averaging is not implemented as it is worse than linear
        weighted averaging or no averaging.



    Attributes
    ----------
    w : nd-array, shape=(model.size_joint_feature,)
        The learned weights of the SVM.

    ``loss_curve_`` : list of float
        List of loss values if show_loss_every > 0.

    ``objective_curve_`` : list of float
       Primal objective after each pass through the dataset.

    ``timestamps_`` : list of int
       Total training time stored before each iteration.

     __init__ N/A N/A self model max_iter C verbose momentum learning_rate n_jobs show_loss_every decay_exponent decay_t0 break_on_no_constraints logger averaging N/A 100 1.0 0 0.0 auto 1 0 1 10 True None None N/A N/A N/A N/A SubgradientSSVM __init__ self model max_iter C verbose verbose n_jobs n_jobs show_loss_every show_loss_every decay_exponent decay_exponent momentum momentum learning_rate learning_rate break_on_no_constraints break_on_no_constraints logger logger decay_t0 decay_t0 averaging averaging N/A fit N/A N/A self X Y H_init warm_start initialize N/A None False True N/A N/A Learn parameters using subgradient descent.

        Parameters
        ----------
        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.

        constraints : None
            Discarded. Only for API compatibility currently.

        warm_start : boolean, default=False
            Whether to restart a previous fit.

        initialize : boolean, default=True
            Whether to initialize the model for the data.
            Leave this true except if you really know what you are doing.
         N/A N/A N/A self verbose 0 N/A N/A Training latent subgradient structural SVM N/A initialize N/A N/A N/A N/A N/A self model initialize X Y N/A N/A self grad_old N/A N/A np zeros N/A N/A self model size_joint_feature N/A N/A warm_start N/A N/A N/A self w N/A getattr self w N/A N/A N/A np random normal 0 1 size N/A N/A self model size_joint_feature N/A N/A self timestamps_ N/A N/A time N/A N/A self objective_curve_ N/A N/A N/A N/A self learning_rate auto N/A N/A N/A self learning_rate_ N/A N/A self C N/A len X N/A N/A N/A self learning_rate_ N/A self learning_rate N/A N/A N/A N/A self timestamps_ N/A 0 N/A N/A time N/A N/A self timestamps_ N/A -1 N/A w N/A N/A N/A self w copy N/A n_samples N/A len X N/A N/A N/A iteration N/A range N/A self max_iter N/A N/A N/A N/A N/A self timestamps_ append N/A N/A time N/A N/A self timestamps_ N/A 0 N/A positive_slacks 0 N/A objective 0.0 N/A N/A N/A self n_jobs 1 N/A N/A N/A x y N/A zip X Y N/A N/A h N/A N/A N/A self model latent x y w N/A h_hat N/A N/A N/A self model loss_augmented_inference x h w relaxed True N/A delta_joint_feature N/A N/A N/A N/A self model joint_feature x h N/A N/A N/A self model joint_feature x h_hat N/A slack N/A N/A N/A N/A np dot delta_joint_feature w N/A N/A N/A self model loss h h_hat N/A objective N/A N/A np maximum slack 0 N/A N/A slack 0 N/A N/A positive_slacks 1 N/A w N/A N/A self _solve_subgradient delta_joint_feature n_samples w N/A N/A N/A N/A self n_jobs -1 N/A N/A n_jobs N/A cpu_count N/A N/A n_jobs N/A self j_jobs N/A n_batches N/A int N/A N/A np ceil N/A N/A float N/A len X n_jobs N/A slices N/A gen_even_slices n_samples n_batches N/A batch slices N/A N/A X_b N/A X N/A batch N/A Y_b N/A Y N/A batch N/A verbose N/A N/A self verbose 1 N/A candidate_constraints N/A N/A Parallel n_jobs N/A self n_jobs verbose verbose N/A N/A N/A delayed find_constraint_latent N/A self model x y w N/A N/A x y N/A zip X_b Y_b N/A djoint_feature N/A N/A np zeros N/A N/A self model size_joint_feature N/A N/A x y constraint N/A zip X_b Y_b candidate_constraints N/A N/A N/A y_hat delta_joint_feature slack loss constraint N/A objective slack N/A djoint_feature delta_joint_feature N/A N/A slack 0 N/A N/A positive_slacks 1 N/A djoint_feature N/A float N/A len X_b N/A w N/A N/A self _solve_subgradient djoint_feature n_samples w N/A objective N/A self C N/A objective N/A N/A N/A np sum N/A N/A self w 2 2.0 N/A N/A positive_slacks 0 N/A N/A No additional constraints N/A N/A self break_on_no_constraints N/A N/A N/A N/A N/A self verbose 0 N/A N/A self N/A N/A iteration %d iteration N/A N/A positive slacks: %d, objective: %f N/A positive_slacks objective N/A N/A N/A N/A self objective_curve_ append objective N/A N/A N/A self verbose 2 N/A N/A N/A self w N/A N/A N/A self _compute_training_loss X Y iteration N/A N/A N/A self logger None N/A N/A N/A N/A self logger self iteration N/A N/A N/A KeyboardInterrupt N/A N/A N/A N/A N/A N/A self timestamps_ append N/A N/A time N/A N/A self timestamps_ N/A 0 N/A N/A N/A N/A self objective_curve_ append N/A N/A self _objective X Y N/A N/A N/A self logger None N/A N/A N/A N/A self logger self final N/A N/A self verbose N/A N/A N/A self objective_curve_ N/A N/A N/A final objective: %f N/A N/A self objective_curve_ N/A -1 N/A N/A N/A self verbose N/A N/A self n_jobs 1 N/A N/A N/A calls to inference: %d N/A N/A self model inference_calls N/A self N/A predict N/A N/A self X N/A N/A N/A prediction N/A N/A SubgradientSSVM predict self X N/A N/A N/A N/A N/A self model label_from_latent h N/A h prediction N/A predict_latent N/A N/A self X N/A N/A N/A N/A N/A SubgradientSSVM predict self X N/A score N/A N/A self X Y N/A N/A N/A Compute score as 1 - loss over whole data set.

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

        Parameters
        ----------
        X : iterable
            Evaluation data.

        Y : iterable
            True labels.

        Returns
        -------
        score : float
            Average of 1 - loss over training examples.
         N/A N/A hasattr N/A self model batch_loss N/A N/A losses N/A N/A N/A self model batch_loss Y N/A N/A N/A self model batch_inference X N/A self w N/A N/A losses N/A N/A N/A N/A self model loss y N/A N/A N/A self model inference y N/A self w N/A N/A y y_pred N/A zip Y N/A N/A self predict X N/A max_losses N/A N/A N/A N/A self model max_loss y N/A y Y N/A N/A 1.0 N/A N/A N/A np sum losses N/A float N/A N/A np sum max_losses N/A _objective N/A N/A self X Y N/A N/A N/A constraints N/A N/A Parallel n_jobs N/A self n_jobs verbose N/A N/A self verbose 1 N/A N/A N/A delayed find_constraint_latent N/A self model x y N/A self w N/A N/A x y N/A zip X Y N/A slacks N/A N/A list N/A zip constraints N/A 2 N/A slacks N/A N/A np maximum slacks 0 N/A objective N/A N/A N/A N/A np sum slacks N/A self C N/A N/A N/A np sum N/A N/A self w 2 2.0 N/A objective N/A N/A