Model module

Module that defines PCM Model classes and NoiseModel classes

Model Classes

class model.Model(name)

Abstract PCM Model Class

Parameters:

name ([str]) – Name of the the model

get_prior()

Returns prior mean and precision

predict(theta)

Prediction function: Needs to be implemented

class model.FixedModel(name, G)

Fixed PCM with a rigid predicted G matrix and no parameters

Parameters:
  • name (string) – name of the particular model for indentification

  • G (numpy.ndarray) – 2-dimensional array giving the predicted second moment

predict(theta=None)

Calculation of G

Returns:
  • G (np.ndarray) – 2-dimensional (K,K) array of predicted second moment

  • dG_dTheta (None)

class model.ComponentModel(name, Gc)

Component model class G = sum (exp(theta_i) * Gc_i)

Parameters:
  • name (string) – name of the particular model for indentification

  • Gc (numpy.ndarray) – 3-dimensional array with compoments of G

predict(theta)

Calculation of G

Parameters:

theta (numpy.ndarray) – Vector of model parameters

Returns:
  • G (np.ndarray) – 2-dimensional (K,K) array of predicted second moment

  • dG_dTheta (np.ndarray) – 3-d (n_param,K,K) array of partial matrix derivatives of G in respect to theta

set_theta0(G_hat)

Sets theta0 based on the crossvalidated second-moment

Parameters:

G_hat (numpy.ndarray) – Crossvalidated estimate of G

class model.FeatureModel(name, Ac)

Feature model: A = sum (theta_i * Ac_i) G = A*A’

Parameters:
  • name (string) – name of the particular model for indentification

  • Ac (numpy.ndarray) – 3-dimensional array with components of A

predict(theta)

Calculation of G

Parameters:

theta (np.ndarray) – Vector of model parameters

Returns:
  • G (np.ndarray) – 2-dimensional (K,K) array of predicted second moment

  • dG_dTheta (np.ndarray) – 3-d (n_param,K,K) array of partial matrix derivatives of G in respect to theta

class model.CorrelationModel(name, within_cov=None, num_items=1, corr=None, cond_effect=False)

Correlation model class for a fixed or flexible correlation model it models the correlation between different items across 2 experimental conditions. Using this paramaterization: var(x) = exp(theta_x)

var(y) = exp(theta_y)

cov(x,y) = sqrt(var(x)*var(y))* r

r = (exp(2*theta_z)-1)/(exp(2*theta_z)+1); % Fisher inverse

Parameters:
  • name (string) – name of the particular model for indentification

  • within_cov (numpy.ndarray or None) – how to model within condition cov-ariance between items

  • num_items (int) – Number of items within each condition

get_correlation(theta)

Returns the correlations from a set of fitted parameters

Parameters:

theta (numpy.ndarray) – n_param vector or n_param x n_subj matrix of model parameters

Returns:

correlations (numpy.ndarray) – Correlation value

predict(theta)

Calculation of G for a correlation model

Parameters:

theta (numpy.ndarray) – Vector of model parameters

Returns:
  • G (np.ndarray) – 2-dimensional (K,K) array of predicted second moment

  • dG_dTheta (np.ndarray) – 3-d (n_param,K,K) array of partial matrix derivatives of G in respect to theta

set_theta0(G_hat)

Sets theta0 based on the crossvalidated second-moment

Parameters:

G_hat (numpy.ndarray) – Crossvalidated estimate of G

class model.FreeModel(name, n_cond)

Free model class: Second moment matrix is G = A*A’, where A is a upper triangular matrix that is flexible

Parameters:
  • name (string) – name of the particular model for indentification

  • n_cond (int) – number of conditions for free model

predict(theta)

Calculation of G

Parameters:

theta (numpy.ndarray) – Vector of model parameters

Returns:
  • G (np.ndarray) – 2-dimensional (K,K) array of predicted second moment

  • dG_dTheta (np.ndarray) – 3-d (n_param,K,K) array of partial matrix derivatives of G in respect to theta

set_theta0(G_hat)

Sets theta0 based on the crossvalidated second-moment

Parameters:

G_hat (numpy.ndarray) – Crossvalidated estimate of G

Noise Model Classes

class model.NoiseModel

Abstract PCM Noise model class

class model.IndependentNoise

Simple Indepdennt noise model (i.i.d) the only parameter is the noise variance

derivative(theta, n=0)

Returns the derivative of S in respect to it’s own parameters

Parameters:
  • theta ([np.array]) – Array like of noiseparamters

  • n (int, optional) – Number of parameter to get derivate for. Defaults to 0.

Returns:

d (np-array) – derivative of S in respective to theta

inverse(theta)

Returns S^{-1}

Parameters:

theta ([np.array]) – Array like of noiseparamters

Returns:

s (double) – Inverse of noise variance (scalar)

predict(theta)

Prediction function returns S - predicted noise covariance matrix

Parameters:

theta ([np.array]) – Array like of noiseparamters

Returns:

s (double) – Noise variance (for simplicity as a scalar)

set_theta0(Y, Z, X=None)

Makes an initial guess on noise paramters

Parameters:
  • Y ([np.array]) – Data

  • Z ([np.array]) – Random Effects matrix

  • X ([np.array], optional) – Fixed effects matrix.

class model.BlockPlusIndepNoise(part_vec)

This noise model uses correlated noise per partition (block) plus independent noise per observation For beta-values from an fMRI analysis, this is an adequate model

Parameters:

part_vec ([np.array]) – vector indicating the block membership for each observation

derivative(theta, n=0)

Returns the derivative of S in respect to it’s own parameters

Parameters:
  • theta (np.array) – Array like of noiseparamters

  • n (int, optional) – Number of parameter to get derivate for. Defaults to 0.

Returns:

d (np.array) – derivative of S in respective to theta

inverse(theta)

Returns S^{-1}

Parameters:

theta (np.array) – Array like of noiseparamters

Returns:

iS (np.array) – Inverse of noise covariance

predict(theta)

Prediction function returns S - predicted noise covariance matrix

Parameters:

theta ([np.array]) – Array like of noiseparamters

Returns:

s (np.array) – Noise covariance matrix

set_theta0(Y, Z, X=None)

Makes an initial guess on noise parameters :param Y: Data :type Y: [np.array] :param Z: Random Effects matrix :type Z: [np.array] :param X: Fixed effects matrix. :type X: [np.array], optional