Module ImportFrom alias Import alias identifier ImportFrom alias alias alias ImportFrom alias 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 NameParam NameParam defaults Num Num Num Num Str Num Num Num NameLoad NameLoad NameLoad Num NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore BinOpSub NameLoad BinOpDiv NameLoad BinOpMult AttributeLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr BinOpAdd BinOpMult BinOpSub Num AttributeLoad NameLoad attr NameLoad BinOpMult AttributeLoad NameLoad attr AttributeLoad NameLoad attr If CompareEq AttributeLoad NameLoad attr Num body Assign NameStore AttributeLoad NameLoad attr orelse Assign NameStore BinOpDiv AttributeLoad NameLoad attr BinOpPow BinOpAdd AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AugAssignAdd NameStore BinOpMult NameLoad AttributeLoad NameLoad attr If CompareEq AttributeLoad NameLoad attr Str body Assign NameStore BinOpDiv Num BinOpAdd AttributeLoad NameLoad attr Num Assign AttributeStore NameLoad attr BinOpAdd BinOpMult BinOpSub Num NameLoad AttributeLoad NameLoad attr BinOpMult NameLoad NameLoad orelse If CompareEq AttributeLoad NameLoad attr Str body Assign NameStore BinOpDiv BinOpMult Num BinOpAdd AttributeLoad NameLoad attr Num BinOpMult BinOpAdd AttributeLoad NameLoad attr Num BinOpAdd BinOpMult Num AttributeLoad NameLoad attr Num Assign AttributeStore NameLoad attr BinOpAdd BinOpMult BinOpSub Num NameLoad AttributeLoad NameLoad attr BinOpMult NameLoad NameLoad orelse Assign AttributeStore NameLoad attr NameLoad AugAssignAdd AttributeStore NameLoad attr Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad body Expr Str If NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad If AttributeLoad NameLoad attr body Print Str Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Call NameLoad NameLoad Str Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr If UnaryOpNot NameLoad body Assign AttributeStore NameLoad attr ListLoad Assign AttributeStore NameLoad attr ListLoad Call NameLoad 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 AttributeStore NameLoad attr Call AttributeLoad BinOpSub Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad attr TryExcept body For NameStore Call NameLoad AttributeLoad NameLoad attr body If AttributeLoad NameLoad attr body Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad If CompareEq AttributeLoad NameLoad attr Num body Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad orelse Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Assign NameStore BinOpAdd BinOpMult NameLoad AttributeLoad NameLoad attr BinOpDiv Call AttributeLoad NameLoad attr BinOpPow NameLoad Num Num If CompareEq NameLoad Num body If AttributeLoad NameLoad attr 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 BinOpSub Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad NameLoad attr NameLoad 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 If AttributeLoad NameLoad attr body Print Str 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 NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad Assign TupleStore NameStore NameStore TupleLoad Num Num Assign NameStore Call NameLoad Num BinOpSub AttributeLoad NameLoad attr Num If CompareIsNot AttributeLoad NameLoad attr NameLoad body Raise Call NameLoad Str 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 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 If CompareGt NameLoad Num body AugAssignAdd NameStore NameLoad AugAssignAdd NameStore NameLoad AugAssignAdd NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Return TupleLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad Assign TupleStore NameStore NameStore TupleLoad Num Num If CompareIn AttributeLoad NameLoad attr ListLoad NameLoad Num body For TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad body Assign TupleStore NameStore NameStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr NameLoad NameLoad NameLoad AugAssignAdd NameStore NameLoad If CompareGt NameLoad Num body AugAssignAdd NameStore Num Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad orelse If CompareEq AttributeLoad NameLoad attr Num body Assign NameStore ListLoad Call NameLoad Num Call NameLoad NameLoad orelse Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr BinOpDiv Call NameLoad Call NameLoad NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad For NameStore NameLoad body Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad Index 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 Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num BinOpSub NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad AugAssignAdd NameStore NameLoad AugAssignAdd NameStore AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpDiv NameLoad Call NameLoad NameLoad NameLoad NameLoad Return TupleLoad NameLoad NameLoad 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 shuffle ssvm BaseSSVM utils find_constraint SubgradientSSVM N/A BaseSSVM N/A N/A 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.

    batch_size : int, default=None
        Ignored if n_jobs > 1. If n_jobs=1, inference will be done in mini
        batches of size batch_size. If n_jobs=-1, batch learning will be
        performed, that is the whole dataset will be used to compute each
        subgradient.

    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.

    logger : logger object.

    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.

    shuffle : bool, default=False
        Whether to shuffle the dataset in each iteration.

    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.

    References
    ----------
    * Nathan Ratliff, J. Andrew Bagnell and Martin Zinkevich:
        (Online) Subgradient Methods for Structured Prediction, AISTATS 2007

    * Shalev-Shwartz, Shai and Singer, Yoram and Srebro, Nathan and Cotter,
        Andrew: Pegasos: Primal estimated sub-gradient solver for svm,
        Mathematical Programming 2011
     __init__ N/A N/A self model max_iter C verbose momentum learning_rate n_jobs show_loss_every decay_exponent break_on_no_constraints logger batch_size decay_t0 averaging shuffle N/A 100 1.0 0 0.0 auto 1 0 1 True None None 10 None False N/A N/A N/A N/A BaseSSVM __init__ self model max_iter C verbose verbose n_jobs n_jobs show_loss_every show_loss_every logger logger N/A N/A self averaging averaging N/A N/A self break_on_no_constraints break_on_no_constraints N/A N/A self momentum momentum N/A N/A self learning_rate learning_rate N/A N/A self t 0 N/A N/A self decay_exponent decay_exponent N/A N/A self decay_t0 decay_t0 N/A N/A self batch_size batch_size N/A N/A self shuffle shuffle N/A _solve_subgradient N/A N/A self djoint_feature n_samples w N/A N/A N/A Do a single subgradient step. N/A grad N/A djoint_feature N/A w N/A N/A self C n_samples N/A N/A self grad_old N/A N/A N/A 1 N/A self momentum grad N/A N/A self momentum N/A self grad_old N/A N/A N/A self decay_exponent 0 N/A N/A effective_lr N/A self learning_rate_ N/A N/A effective_lr N/A N/A self learning_rate_ N/A N/A N/A self t N/A self decay_t0 N/A self decay_exponent N/A w N/A effective_lr N/A self grad_old N/A N/A N/A self averaging linear N/A N/A rho N/A 2.0 N/A N/A self t 2.0 N/A N/A self w N/A N/A N/A 1.0 rho N/A self w N/A rho w N/A N/A N/A N/A self averaging squared N/A N/A rho N/A N/A 6.0 N/A N/A self t 1 N/A N/A N/A self t 2 N/A N/A 2 N/A self t 3 N/A N/A self w N/A N/A N/A 1.0 rho N/A self w N/A rho w N/A N/A N/A self w w N/A N/A self t 1.0 N/A w N/A fit N/A N/A self X Y constraints 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 initialize N/A N/A N/A N/A N/A self model initialize X Y N/A N/A self verbose N/A N/A Training primal subgradient structural SVM 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 self w N/A getattr self w N/A N/A np zeros N/A N/A self model size_joint_feature N/A w N/A N/A N/A self w copy N/A N/A warm_start N/A N/A N/A self objective_curve_ N/A N/A N/A self timestamps_ N/A N/A time 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 self timestamps_ N/A N/A N/A N/A N/A np array N/A self timestamps_ N/A time tolist N/A N/A N/A iteration N/A range N/A self max_iter N/A N/A N/A self shuffle N/A N/A N/A X Y N/A shuffle X Y N/A N/A N/A self n_jobs 1 N/A N/A N/A objective positive_slacks w N/A N/A self _sequential_learning X Y w N/A N/A N/A objective positive_slacks w N/A N/A self _parallel_learning X Y w N/A objective N/A N/A objective N/A self C N/A N/A N/A np sum N/A w 2 2.0 N/A N/A positive_slacks 0 N/A N/A N/A self verbose 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 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 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 self verbose N/A N/A Computing final objective 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 _parallel_learning N/A N/A self X Y w N/A N/A N/A n_samples N/A len X N/A N/A objective positive_slacks N/A 0 0 N/A verbose N/A max 0 N/A N/A self verbose 3 N/A N/A N/A self batch_size None N/A N/A N/A ValueError If n_jobs != 1, batch_size needs tobe None 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 n_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 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 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 N/A slack 0 N/A N/A objective slack N/A djoint_feature delta_joint_feature N/A positive_slacks 1 N/A w N/A N/A self _solve_subgradient djoint_feature n_samples w N/A N/A objective positive_slacks w N/A _sequential_learning N/A N/A self X Y w N/A N/A N/A n_samples N/A len X N/A N/A objective positive_slacks N/A 0 0 N/A N/A N/A self batch_size N/A None 1 N/A N/A N/A x y N/A zip X Y N/A N/A N/A y_hat delta_joint_feature slack loss N/A find_constraint N/A self model x y w N/A objective slack N/A N/A slack 0 N/A N/A positive_slacks 1 N/A N/A N/A self _solve_subgradient delta_joint_feature n_samples w N/A N/A N/A N/A self batch_size -1 N/A N/A slices N/A N/A slice 0 N/A len X N/A N/A n_batches N/A int N/A N/A np ceil N/A N/A float N/A len X N/A self batch_size 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 Y_hat N/A N/A N/A self model batch_loss_augmented_inference X_b Y_b w relaxed True N/A delta_joint_feature N/A N/A N/A N/A self model batch_joint_feature X_b Y_b N/A N/A N/A self model batch_joint_feature X_b Y_hat N/A loss N/A N/A np sum N/A N/A N/A self model batch_loss Y_b Y_hat N/A violation N/A N/A np maximum 0 N/A loss N/A N/A np dot w delta_joint_feature N/A objective violation N/A positive_slacks N/A self batch_size N/A N/A N/A self _solve_subgradient N/A delta_joint_feature N/A len X_b n_samples w N/A N/A objective positive_slacks w N/A N/A