inputs: @verbose
def gamma_map(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8, xyz_same_gamma=True, maxit=10000, tol=1e-06, update_mode=1, gammas=None, pca=True, return_residual=False, return_as_dipoles=False, verbose=None):
targets: """Hierarchical Bayes (Gamma-MAP) sparse source localization method.
    Models each source time course using a zero-mean Gaussian prior with an
    unknown variance (gamma) parameter. During estimation, most gammas are
    driven to zero, resulting in a sparse source estimate, as in
    [1]_ and [2]_.
    For fixed-orientation forward operators, a separate gamma is used for each
    source time course, while for free-orientation forward operators, the same
    gamma is used for the three source time courses at each source space point
    (separate gammas can be used in this case by using xyz_same_gamma=False).
    Parameters
    evoked : instance of Evoked
    Evoked data to invert.
    forward : dict
    Forward operator.
    noise_cov : instance of Covariance
    Noise covariance to compute whitener.
    alpha : float
    Regularization parameter (noise variance).
    loose : float in [0, 1]
    Value that weights the source variances of the dipole components
    that are parallel (tangential) to the cortical surface. If loose
    is 0 or None then the solution is computed with fixed orientation.
    If loose is 1, it corresponds to free orientations.
    depth: None | float in [0, 1]
    Depth weighting coefficients. If None, no depth weighting is performed.
    xyz_same_gamma : bool
    Use same gamma for xyz current components at each source space point.
    Recommended for free-orientation forward solutions.
    maxit : int
    Maximum number of iterations.
    tol : float
    Tolerance parameter for convergence.
    update_mode : int
    Update mode, 1: MacKay update (default), 2: Modified MacKay update.
    gammas : array, shape=(n_sources,)
    Initial values for posterior variances (gammas). If None, a
    variance of 1.0 is used.
    pca : bool
    If True the rank of the data is reduced to the true dimension.
    return_residual : bool
    If True, the residual is returned as an Evoked instance.
    return_as_dipoles : bool
    If True, the sources are returned as a list of Dipole instances.
   ..."""
    _check_reference(evoked)
    if ((loose is None) and (not is_fixed_orient(forward))):
        forward = deepcopy(forward)
        _to_fixed_ori(forward)
    if (is_fixed_orient(forward) or (not xyz_same_gamma)):
        group_size = 1
    else:
        group_size = 3
    (gain, gain_info, whitener, source_weighting, mask) = _prepare_gain(forward, evoked.info, noise_cov, pca, depth, loose, None, None)
    sel = [evoked.ch_names.index(name) for name in gain_info['ch_names']]
    M = evoked.data[sel]
    logger.info('Whitening    data    matrix.')
    M = np.dot(whitener, M)
    (X, active_set) = _gamma_map_opt(M, gain, alpha, maxit=maxit, tol=tol, update_mode=update_mode, gammas=gammas, group_size=group_size, verbose=verbose)
    if (len(active_set) == 0):
        raise Exception('No    active    dipoles    found.    alpha    is    too    big.')
    M_estimated = np.dot(gain[:, active_set], X)
    n_dip_per_pos = (1 if is_fixed_orient(forward) else 3)
    X = _reapply_source_weighting(X, source_weighting, active_set, n_dip_per_pos)
    if return_residual:
        residual = _compute_residual(forward, evoked, X, active_set, gain_info)
    if ((group_size == 1) and (not is_fixed_orient(forward))):
        active_src = np.unique((active_set // 3))
        in_pos = 0
        if (len(X) < (3 * len(active_src))):
            X_xyz = np.zeros(((3 * len(active_src)), X.shape[1]), dtype=X.dtype)
            for ii in range(len(active_src)):
                for jj in range(3):
                    if (in_pos >= len(active_set)):
                        break
                    if (((active_set[in_pos] + jj) % 3) == 0):
                        X_xyz[((3 * ii) + jj)] = X[in_pos]
                        in_pos += 1
            X = X_xyz
    tmin = evoked.times[0]
    tstep = (1.0 / evoked.info['sfreq'])
    if return_as_dipoles:
        out = _make_dipoles_sparse(X, active_set, forward, tmin, tstep, M, M_estimated, active_is_idx=True)
    else:
        out = _make_sparse_stc(X, active_set, forward, tmin, tstep,...