Emission Module

Emission Model Classes

class emissions.EmissionModel(K=4, N=10, P=20, num_subj=None, X=None)[source][source]

Abstract class for emission models

Estep(sub=None)[source][source]

Implemnents E-step and returns

Parameters:

sub (list) – List of indices of subjects to use. Default=all (None)

Returns:

emloglik (np.array) – emission log likelihood log p(Y|u,theta_E) a numsubjxPxK matrix

Mstep(U_hat)[source][source]

Implements M-step for the model

initialize(data, X=None)[source][source]
Initializes the emission model with data set.

The data are stored in the object itself call clear() to remove.

Parameters:
  • data (pt.tensor, ndarray) – numsubj x N x P data tensor

  • X (array, optional) – Design matrix. Defaults to None.

random_params()[source][source]

Sets parameters to random values

class emissions.MultiNomial(K=4, P=20, params=None)[source][source]

Multinomial emission model with coupling strength theta_s

Estep(Y=None, sub=None)[source][source]
Estep: Returns log p(Y|U) for each value of U, up to a constant

Collects the sufficient statistics for the M-step specify which subject to optimize

Parameters:
  • Y (pt.tensor, optional) – numsubj x N x P data tensor. Defaults to None.

  • sub (list, optional) – List of indices of subjects to use. Defaults to None.

Returns:

LL (pt.tensor) – the expected log likelihood for emission model, shape (nSubject * K * P)

Mstep(U_hat)[source][source]
Performs the M-step on a specific U-hat. In this emission model,

the parameters need to be updated are V and sigma2.

Parameters:

U_hat (pt.tensor) – the posterior mean of U, shape (nSubject * K * P)

initialize(Y)[source][source]

Stores the data in emission model itself Calculates sufficient stats on the data that does not depend on u, and allocates memory for the sufficient stats that does.

sample(U, signal=None)[source][source]

Generate random data given this emission model :param U: The prior arrangement U from arrangement model :type U: pt.tensor

Returns:

Y (pt.tensor) – sampled data Y (compressed form)

class emissions.MixGaussian(K=4, N=10, P=20, num_subj=None, X=None, params=None, std_V=True)[source][source]

Mixture of Gaussians with isotropic noise

Estep(Y=None, sub=None)[source][source]
Estep: Returns log p(Y|U) for each value of U, up to a constant

Collects the sufficient statistics for the M-step specify which subject to optimize

Parameters:
  • Y (pt.tensor, optional) – numsubj x N x P data tensor. Defaults to None.

  • sub (list, optional) – List of indices of subjects to use. Defaults to None.

Returns:

the expected log likelihood for emission model,

shape (nSubject * K * P)

Return type:

LL (pt.tensor)

Mstep(U_hat)[source][source]

Performs the M-step on a specific U-hat. In this emission model, the parameters need to be updated are V and sigma2.

initialize(data, X=None)[source][source]
Stores the data in emission model itself. Calculates

sufficient stats on the data that does not depend on u, and allocates memory for the sufficient stats that does.

Parameters:
  • data (pt.tensor) – numsubj x N x P data tensor

  • X (pt.tensor, optional) – Design matrix of the tasks.

random_params()[source][source]

In this mixture gaussians, the parameters are parcel-specific mean V_k and variance. Here, we assume the variance is equally across different parcels. Therefore, there are total k+1 parameters in this mixture model. We set the initial random parameters for gaussian mixture here.

sample(U, signal=None)[source][source]

Generate random data given this emission model

Parameters:

U (pt.tensor) – prior arrangement U from arrangement model. numsubj x N x P tensor of assignments

Returns:

Y (pt.tensor) – numsubj x N x P tensor of sample data

class emissions.MixVMF(K=4, N=10, P=20, num_subj=None, X=None, part_vec=None, params=None, uniform_kappa=None, parcel_specific_kappa=False, subject_specific_kappa=False, subjects_equal_weight=False)[source][source]

Mixture of von Mises-Fisher distribution emission model

Estep(Y=None, sub=None)[source][source]
Estep: Returns log p(Y|U) for each voxel and value of U,

up to a constant. Collects the sufficient statistics for the M-step

Parameters:
  • Y (pt.tensor) – Data (optional)

  • sub (pt.tensor) – vector of integer indices specify which subject to estimate (optional)

Returns:
  • LL (pt.tensor) – the expected log likelihood for emission model,

  • shape (nSubject * K * P)

Mstep(U_hat)[source][source]
Performs the M-step on a specific U-hat. In this emission model,

the parameters need to be updated are Vs (unit norm projected on the N-1 sphere) and kappa (concentration value).

Parameters:

U_hat – the expected log likelihood from the arrangement model

Returns:

Update all the object’s parameters

initialize(data)[source][source]
Calculates the sufficient stats on the data that does not depend on U,

and allocates memory for the sufficient stats that does. For the VMF, it length-standardizes the data to length one. If part_vec is exist, then the raw data needs to be partitioned and normalize in each partition. After that, we restore Y to its original shape (num_sub, N, P). The new data for further fitting is X^T (shape M, N) * Y which has a shape (num_sub, M, P) Note: The shape of X (N, M) - N is # of observations, M is # of conditions

Parameters:

data – the input data array (or torch tensor). shape (n_subj, N, P)

Returns: None. Store the data in emission model itself.

Class attributes:
self.num_part: Number of available partitions per voxels. numsubj x 1 x P tensor

used in M step

random_params()[source][source]
In this mixture vmf model, the parameters are parcel-specific direction V_k

and concentration value kappa_k.

Returns: None, just passes the random parameters to the model

sample(U, signal=None)[source][source]

Draw data sample from this model and given parameters

Parameters:
  • U (pt.tensor) – num_subj x P arrangement for each subject

  • signal (pt.tensor) – num_subj x P signal for each subject

Returns: The samples data from this distribution

Functions for Emission Models

emissions.build_emission_model(K, atlas, emission, x_matrix, part_vec, V=None, em_params={})[source][source]

Builds an emission model based on the specification

Parameters:
  • K (int) – number of voxels

  • atlas (object) – the atlas object for the arrangement model

  • emission (str) – the emission model type

  • x_matrix (ndarray) – the design matrix associated with an emission model

  • part_vec (ndarray) – A partition vector of the data

  • V (torch.tensor or numpy.ndarray) – the mean direction parameter for VMF emission model or the mean response parameter for GMM emission model. If None, the parameter for current building emission model will be randomly initialized. If V is given, the parameter ‘V’ is fixed throughout the modeling learning.

  • em_params (dictionary) – Parameters passed to the emission model constructor

Returns:

em_model (object) – the emission model object