예제 #1
0
def perm_prfx(domain,
              graphs,
              features,
              nb_parcel,
              ldata,
              initial_mask=None,
              nb_perm=100,
              niter=5,
              dmax=10.,
              lamb=100.0,
              chunksize=1.e5,
              verbose=1):
    """
    caveat: assumes that the functional dimension is 1
    """
    from ..utils.reproducibility_measures import ttest
    # permutations for the assesment of the results
    prfx0 = []
    adim = domain.coord.shape[1]
    nb_subj = len(ldata)
    for q in range(nb_perm):
        feature = []
        sldata = []
        for s in range(nb_subj):
            lf = features[s].copy()
            swap = (rand() > 0.5) * 2 - 1
            lf[:, 0:-adim] = swap * lf[:, 0:-adim]
            sldata.append(swap * ldata[s])
            feature.append(lf)

        # optimization part
        all_labels, proto_anat = _optim_hparcel(feature,
                                                domain,
                                                graphs,
                                                nb_parcel,
                                                lamb,
                                                dmax,
                                                niter,
                                                initial_mask,
                                                chunksize=chunksize)
        labels = -np.ones((domain.size, nb_subj)).astype(np.int)
        for s in range(nb_subj):
            labels[initial_mask[:, s] > -1, s] = all_labels[s]

        # compute the group-level labels
        template_labels = voronoi(domain.coord, proto_anat)

        # create the parcellation
        pcl = MultiSubjectParcellation(domain,
                                       individual_labels=labels,
                                       template_labels=template_labels)
        pdata = pcl.make_feature('functional',
                                 np.rollaxis(np.array(ldata), 1, 0))
        prfx = ttest(np.squeeze(pdata))
        if verbose:
            print q, prfx.max(0)
        prfx0.append(prfx.max(0))

    return prfx0
예제 #2
0
def perm_prfx(domain, graphs, features, nb_parcel, ldata, initial_mask=None,
              nb_perm=100, niter=5, dmax=10., lamb=100.0, chunksize=1.e5,
              verbose=1):
    """
    caveat: assumes that the functional dimension is 1
    """
    from ..utils.reproducibility_measures import ttest
    # permutations for the assesment of the results
    prfx0 = []
    adim = domain.coord.shape[1]
    nb_subj = len(ldata)
    for q in range(nb_perm):
        feature = []
        sldata = []
        for s in range(nb_subj):
            lf = features[s].copy()
            swap = (rand() > 0.5) * 2 - 1
            lf[:, 0:-adim] = swap * lf[:, 0:-adim]
            sldata.append(swap * ldata[s])
            feature.append(lf)

        # optimization part
        all_labels, proto_anat = _optim_hparcel(
            feature, domain, graphs, nb_parcel, lamb, dmax, niter,
            initial_mask, chunksize=chunksize)
        labels = - np.ones((domain.size, nb_subj)).astype(np.int)
        for s in range(nb_subj):
            labels[initial_mask[:, s] > -1, s] = all_labels[s]

        # compute the group-level labels
        template_labels = voronoi(domain.coord, proto_anat)

        # create the parcellation
        pcl = MultiSubjectParcellation(domain, individual_labels=labels,
                                       template_labels=template_labels)
        pdata = pcl.make_feature('functional',
                                 np.rollaxis(np.array(ldata), 1, 0))
        prfx = ttest(np.squeeze(pdata))
        if verbose:
            print q, prfx.max(0)
        prfx0.append(prfx.max(0))

    return prfx0
예제 #3
0
def hparcel(domain, ldata, nb_parcel, nb_perm=0, niter=5, mu=10., dmax=10.,
            lamb=100.0, chunksize=1.e5, verbose=0, initial_mask=None):
    """
    Function that performs the parcellation by optimizing the
    inter-subject similarity while retaining the connectedness
    within subject and some consistency across subjects.

    Parameters
    ----------
    domain: discrete_domain.DiscreteDomain instance,
            yields all the spatial information on the parcelled domain
    ldata: list of (n_subj) arrays of shape (domain.size, dim)
           the feature data used to inform the parcellation
    nb_parcel: int,
               the number of parcels
    nb_perm: int, optional,
             the number of times the parcellation and prfx
             computation is performed on sign-swaped data
    niter: int, optional,
           number of iterations to obtain the convergence of the method
           information in the clustering algorithm
    mu: float, optional,
        relative weight of anatomical information
    dmax: float optional,
          radius of allowed deformations
    lamb: float optional
          parameter to control the relative importance of space vs function
    chunksize; int, optional
               number of points used in internal sub-sampling
    verbose: bool, optional,
             verbosity mode
    initial_mask: array of shape (domain.size, nb_subj), optional
                  initial subject-depedent masking of the domain

    Results
    -------
    Pa: the resulting parcellation structure appended with the labelling
    """
    # a various parameters
    nbvox = domain.size
    nb_subj = len(ldata)
    if initial_mask is None:
        initial_mask = np.ones((nbvox, nb_subj), np.int)

    graphs = []
    feature = []

    for s in range(nb_subj):
        # build subject-specific models of the data
        lnvox = np.sum(initial_mask[:, s] > - 1)
        lac = domain.coord[initial_mask[:, s] > - 1]
        beta = np.reshape(ldata[s], (lnvox, ldata[s].shape[1]))
        lf = np.hstack((beta, mu * lac / (1.e-15 + np.std(domain.coord, 0))))
        feature.append(lf)
        g = wgraph_from_coo_matrix(domain.topology)
        g.remove_trivial_edges()
        graphs.append(g)

    # main function
    all_labels, proto_anat = _optim_hparcel(
        feature, domain, graphs, nb_parcel, lamb, dmax, niter, initial_mask,
        chunksize=chunksize, verbose=verbose)

    # write the individual labelling
    labels = - np.ones((nbvox, nb_subj)).astype(np.int)
    for s in range(nb_subj):
        labels[initial_mask[:, s] > -1, s] = all_labels[s]

    # compute the group-level labels
    template_labels = voronoi(domain.coord, proto_anat)

    # create the parcellation
    pcl = MultiSubjectParcellation(domain, individual_labels=labels,
                                   template_labels=template_labels,
                                   nb_parcel=nb_parcel)
    pcl.make_feature('functional', np.rollaxis(np.array(ldata), 1, 0))

    if nb_perm > 0:
        prfx0 = perm_prfx(domain, graphs, feature, nb_parcel, ldata,
                          initial_mask, nb_perm, niter, dmax, lamb, chunksize)
        return pcl, prfx0
    else:
        return pcl
예제 #4
0
def hparcel(domain,
            ldata,
            nb_parcel,
            nb_perm=0,
            niter=5,
            mu=10.,
            dmax=10.,
            lamb=100.0,
            chunksize=1.e5,
            verbose=0,
            initial_mask=None):
    """
    Function that performs the parcellation by optimizing the
    inter-subject similarity while retaining the connectedness
    within subject and some consistency across subjects.

    Parameters
    ----------
    domain: discrete_domain.DiscreteDomain instance,
            yields all the spatial information on the parcelled domain
    ldata: list of (n_subj) arrays of shape (domain.size, dim)
           the feature data used to inform the parcellation
    nb_parcel: int,
               the number of parcels
    nb_perm: int, optional,
             the number of times the parcellation and prfx
             computation is performed on sign-swaped data
    niter: int, optional,
           number of iterations to obtain the convergence of the method
           information in the clustering algorithm
    mu: float, optional,
        relative weight of anatomical information
    dmax: float optional,
          radius of allowed deformations
    lamb: float optional
          parameter to control the relative importance of space vs function
    chunksize; int, optional
               number of points used in internal sub-sampling
    verbose: bool, optional,
             verbosity mode
    initial_mask: array of shape (domain.size, nb_subj), optional
                  initial subject-depedent masking of the domain

    Returns
    -------
    Pa: the resulting parcellation structure appended with the labelling
    """
    # a various parameters
    nbvox = domain.size
    nb_subj = len(ldata)
    if initial_mask is None:
        initial_mask = np.ones((nbvox, nb_subj), np.int)

    graphs = []
    feature = []

    for s in range(nb_subj):
        # build subject-specific models of the data
        lnvox = np.sum(initial_mask[:, s] > -1)
        lac = domain.coord[initial_mask[:, s] > -1]
        beta = np.reshape(ldata[s], (lnvox, ldata[s].shape[1]))
        lf = np.hstack((beta, mu * lac / (1.e-15 + np.std(domain.coord, 0))))
        feature.append(lf)
        g = wgraph_from_coo_matrix(domain.topology)
        g.remove_trivial_edges()
        graphs.append(g)

    # main function
    all_labels, proto_anat = _optim_hparcel(feature,
                                            domain,
                                            graphs,
                                            nb_parcel,
                                            lamb,
                                            dmax,
                                            niter,
                                            initial_mask,
                                            chunksize=chunksize,
                                            verbose=verbose)

    # write the individual labelling
    labels = -np.ones((nbvox, nb_subj)).astype(np.int)
    for s in range(nb_subj):
        labels[initial_mask[:, s] > -1, s] = all_labels[s]

    # compute the group-level labels
    template_labels = voronoi(domain.coord, proto_anat)

    # create the parcellation
    pcl = MultiSubjectParcellation(domain,
                                   individual_labels=labels,
                                   template_labels=template_labels,
                                   nb_parcel=nb_parcel)
    pcl.make_feature('functional', np.rollaxis(np.array(ldata), 1, 0))

    if nb_perm > 0:
        prfx0 = perm_prfx(domain, graphs, feature, nb_parcel, ldata,
                          initial_mask, nb_perm, niter, dmax, lamb, chunksize)
        return pcl, prfx0
    else:
        return pcl