Module Expr Str ImportFrom alias Import alias identifier ImportFrom alias FunctionDef arguments args NameParam defaults body Expr Str Return BinOpPow SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Index Num Num decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad Call AttributeLoad NameLoad attr TupleLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Num Return Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str If UnaryOpNot BoolOpOr NameLoad NameLoad body Raise Call NameLoad Str Assign NameStore BinOpSub Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad If NameLoad body Assign NameStore BinOpMult Num Call AttributeLoad NameLoad attr NameLoad NameLoad If UnaryOpNot NameLoad body Return NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad If UnaryOpNot NameLoad body Return NameLoad Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr BinOpMult SubscriptLoad NameLoad Slice Num SubscriptLoad NameLoad Slice Num keyword Num Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num attr Return BinOpAdd NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults Num body Expr Str If UnaryOpNot CompareLtELtE Num NameLoad Num body Raise Call NameLoad BinOpMod Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Slice Num For NameStore Call NameLoad BinOpSub SubscriptLoad AttributeLoad NameLoad attr Index Num Num body Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad AugAssignAdd SubscriptStore NameLoad Slice Num SubscriptLoad NameLoad Slice Num AugAssignSub SubscriptStore NameLoad Slice Num Num SubscriptLoad NameLoad Slice Num If CompareGt Call NameLoad NameLoad Num body AugAssignSub SubscriptStore NameLoad Index Num SubscriptLoad NameLoad Index Num AugAssignMult NameStore BinOpSub Num NameLoad AugAssignSub NameStore BinOpMult NameLoad SubscriptLoad NameLoad Index Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults Num body Expr Str If UnaryOpNot CompareLtELtE Num NameLoad Num body Raise Call NameLoad BinOpMod Str NameLoad Assign NameStore BinOpAdd ListLoad BinOpAdd AttributeLoad NameLoad attr Num Call NameLoad AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword AttributeLoad NameLoad attr Assign NameStore ListLoad Num Call NameLoad NameLoad Num For NameStore Call NameLoad AttributeLoad NameLoad attr body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign SubscriptStore NameLoad Index Num BinOpAdd NameLoad Num Expr Call AttributeLoad NameLoad attr Num Call NameLoad NameLoad AugAssignMult SubscriptStore NameLoad Slice Num BinOpSub Num NameLoad Assign SubscriptStore NameLoad Index Num BinOpMult NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareNotEq Call AttributeLoad NameLoad attr Call NameLoad NameLoad body Raise Call NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Index NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad AugAssignMult NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad AugAssignAdd NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore BinOpAdd Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad Slice Num SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult NameLoad NameLoad Assign NameStore CompareGt NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr UnaryOpUSub SubscriptLoad NameLoad Index NameLoad Assign SubscriptStore NameLoad Index UnaryOpInvert NameLoad BinOpAdd UnaryOpUSub SubscriptLoad NameLoad Index UnaryOpInvert NameLoad Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index UnaryOpInvert NameLoad Assign NameStore Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore BinOpAdd Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad Slice Num SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult NameLoad NameLoad Assign NameStore Call NameLoad NameLoad keyword NameLoad Assign NameStore BinOpMult BinOpSub NameLoad Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Slice Num Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index Num Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list Assign NameStore Call NameLoad NameLoad keyword NameLoad keyword NameLoad FunctionDef arguments args NameParam defaults body Expr Str Return SubscriptLoad Call NameLoad NameLoad keyword Num Slice Num decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad Call AttributeLoad NameLoad attr TupleLoad NameLoad ListLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num keyword Num decorator_list
N/A N/A 
Common functions and base classes.

 functools partial N/A numpy np scipy linalg spectral_norm_squared N/A N/A X N/A N/A N/A Computes square of the operator 2-norm (spectral norm) of X

    This corresponds to the Lipschitz constant of the gradient of the
    squared-loss function:

        w -> .5 * ||y - Xw||^2

    Parameters
    ----------
    X : ndarray, shape (n_samples, n_features)
      Design matrix.

    Returns
    -------
    lipschitz_constant : float
      The square of the spectral norm of X.

     N/A N/A N/A N/A N/A linalg svdvals X N/A 0 2 N/A _logistic_loss_lipschitz_constant N/A N/A X N/A N/A N/A Compute the Lipschitz constant (upper bound) for the gradient of the
    logistic sum:

         w -> \sum_i log(1+exp(-y_i*(x_i*w + v)))

     N/A X N/A N/A np hstack N/A X N/A N/A np ones N/A N/A N/A X shape N/A 0 1 N/A N/A spectral_norm_squared X N/A _squared_loss N/A N/A X y w compute_energy compute_grad N/A True False N/A N/A Compute the MSE error, and optionally, its gradient too.

    The cost / energy function is

        MSE = .5 * ||y - Xw||^2

    A (1 / n_samples) factor is applied to the MSE.

    Parameters
    ----------
    X : ndarray, shape (n_samples, n_features)
        Design matrix.

    y : ndarray, shape (n_samples,)
        Target / response vector.

    w : ndarray shape (n_features,)
        Unmasked, ravelized weights map.

    compute_energy : bool, optional (default True)
        If set then energy is computed, otherwise only gradient is computed.

    compute_grad : bool, optional (default False)
        If set then gradient is computed, otherwise only energy is computed.

    Returns
    -------
    energy : float
        Energy (returned if `compute_energy` is set).

    gradient : ndarray, shape (n_features,)
        Gradient of energy (returned if `compute_grad` is set).

     N/A N/A N/A compute_energy compute_grad N/A N/A N/A RuntimeError At least one of compute_energy or compute_grad must be True. N/A residual N/A N/A N/A np dot X w y N/A compute_energy N/A N/A energy N/A 0.5 N/A N/A np dot residual residual N/A N/A compute_grad N/A N/A energy N/A grad N/A N/A np dot N/A X T residual N/A N/A compute_energy N/A N/A grad N/A N/A energy grad N/A _tv_l1_from_gradient N/A N/A spatial_grad N/A N/A N/A Energy contribution due to penalized gradient, in TV-L1 model.

    Parameters
    ----------
    spatial_grad : ndarray, shape (4, nx, ny, nx)
       precomputed "gradient + id" array

    Returns
    -------
    out : float
        Energy contribution due to penalized gradient.
     N/A tv_term N/A N/A np sum N/A N/A np sqrt N/A N/A np sum N/A N/A spatial_grad N/A -1 N/A spatial_grad N/A -1 axis 0 N/A l1_term N/A N/A N/A N/A np abs N/A spatial_grad N/A -1 sum N/A N/A l1_term tv_term N/A _div_id N/A N/A grad l1_ratio N/A 0.5 N/A N/A Compute divergence + id of image gradient + id

    Parameters
    ----------
    grad : ndarray, shape (4, nx, ny, nz, ...)
        where `img_shape` is the shape of the brain bounding box, and
        n_axes = len(img_shape).

    l1_ratio : float in the interval [0, 1]; optional (default .5)
        Constant that mixes L1 and spatial prior terms in the penalization.

    Returns
    -------
    res : ndarray, shape (nx, ny, nz, ...)
        The computed divergence + id operator.

    Raises
    ------
    RuntimeError

     N/A N/A N/A 0.0 l1_ratio 1.0 N/A N/A N/A RuntimeError N/A l1_ratio must be in the interval [0, 1]; got %s l1_ratio N/A res N/A N/A np zeros N/A N/A grad shape N/A 1 N/A d N/A range N/A N/A N/A grad shape N/A 0 1 N/A N/A this_grad N/A N/A np rollaxis N/A grad N/A d d N/A this_res N/A N/A np rollaxis res d N/A N/A this_res N/A -1 N/A this_grad N/A -1 N/A N/A this_res N/A 1 -1 N/A this_grad N/A -2 N/A N/A N/A len this_grad 1 N/A N/A N/A this_res N/A -1 N/A this_grad N/A -2 N/A res N/A 1.0 l1_ratio N/A res N/A l1_ratio N/A grad N/A -1 N/A res N/A _gradient_id N/A N/A img l1_ratio N/A 0.5 N/A N/A Compute gradient + id of an image

    Parameters
    ----------
    img : ndarray, shape (nx, ny, nz, ...)
        N-dimensional image

    l1_ratio : float in the interval [0, 1]; optional (default .5)
        Constant that mixes L1 and spatial prior terms in the penalization.

    Returns
    -------
    gradient : ndarray, shape (4, nx, ny, nz, ...).
        Spatial gradient of the image: the i-th component along the first
        axis is the gradient along the i-th axis of the original array img.

    Raises
    ------
    RuntimeError

     N/A N/A N/A 0.0 l1_ratio 1.0 N/A N/A N/A RuntimeError N/A l1_ratio must be in the interval [0, 1]; got %s l1_ratio N/A shape N/A N/A N/A N/A img ndim 1 N/A list N/A img shape N/A gradient N/A N/A np zeros shape dtype N/A np float N/A slice_all N/A 0 N/A slice None -1 N/A d N/A range N/A img ndim N/A N/A N/A gradient N/A slice_all N/A N/A np diff img axis d N/A N/A slice_all N/A 0 N/A d 1 N/A N/A N/A slice_all insert 1 N/A slice None N/A N/A gradient N/A -1 N/A 1.0 l1_ratio N/A N/A gradient N/A -1 N/A l1_ratio img N/A gradient N/A _unmask N/A N/A w mask N/A N/A N/A Unmask an image into whole brain, with off-mask voxels set to 0.

    Parameters
    ----------
    w : ndarray, shape (n_features,)
      The image to be unmasked.

    mask : ndarray, shape (nx, ny, nz)
      The mask used in the unmasking operation. It is required that
      mask.sum() == n_features.

    Returns
    -------
    out : 3d of same shape as `mask`.
        The unmasked version of `w`
     N/A N/A N/A N/A mask sum N/A len w N/A N/A N/A ValueError Expecting mask.sum() == len(w). N/A out N/A N/A np zeros N/A mask shape dtype N/A w dtype N/A N/A out N/A mask w N/A out N/A _sigmoid N/A N/A t copy N/A True N/A N/A Helper function: return 1. / (1 + np.exp(-t)) N/A copy N/A N/A t N/A N/A np copy t N/A t -1.0 N/A t N/A N/A np exp t t N/A t 1.0 N/A t N/A N/A np reciprocal t t N/A t N/A _logistic N/A N/A X y w N/A N/A N/A Compute the logistic function of the data: sum(sigmoid(yXw))

    Parameters
    ----------
    X : ndarray, shape (n_samples, n_features)
        Design matrix.

    y : ndarray, shape (n_samples,)
        Target / response vector. Each entry must be +1 or -1.

    w : ndarray, shape (n_features,)
        Unmasked, ravelized input map.

    Returns
    -------
    energy : float
        Energy contribution due to logistic data-fit term.
     N/A z N/A N/A N/A np dot X N/A w N/A -1 N/A w N/A -1 N/A yz N/A y z N/A idx N/A yz 0 N/A out N/A N/A np empty_like yz N/A N/A out N/A idx N/A N/A np log1p N/A N/A np exp N/A N/A yz N/A idx N/A N/A out N/A N/A idx N/A N/A N/A yz N/A N/A idx N/A N/A np log1p N/A N/A np exp N/A yz N/A N/A idx N/A out N/A N/A out sum N/A out N/A _logistic_loss_grad N/A N/A X y w N/A N/A N/A Computes the derivative of logistic N/A z N/A N/A N/A np dot X N/A w N/A -1 N/A w N/A -1 N/A yz N/A y z N/A z N/A _sigmoid yz copy False N/A z0 N/A N/A z 1.0 y N/A grad N/A N/A np empty N/A w shape N/A N/A grad N/A -1 N/A N/A np dot N/A X T z0 N/A N/A grad N/A -1 N/A N/A np sum z0 N/A grad N/A N/A _squared_loss_grad N/A partial _squared_loss compute_energy False compute_grad True _gradient N/A N/A w N/A N/A N/A Pure spatial gradient N/A N/A N/A _gradient_id w l1_ratio 0.0 N/A -1 N/A _div N/A N/A v N/A N/A N/A Pure spatial divergence N/A N/A _div_id N/A N/A np vstack N/A v N/A N/A N/A np zeros_like N/A v N/A 0 l1_ratio 0.0 N/A