Arrangement Module

Arrangement Model Classes

class arrangements.ArrangementModel(K, P)[source][source]

Abstract arrangement model class

map_to_arrange(emloglik)[source][source]

Maps emission log likelihoods to the internal size of the representation: Empty

Parameters:

emloglik (list) – List of emission logliklihoods

Returns:

emloglik_comb (ndarray) – ndarray of emission logliklihoods

map_to_full(Uhat)[source][source]

Placeholder

Parameters:

Uhat (ndarray) – tensor of estimated arrangement

Returns:

Uhat (ndarray) – tensor of estimated arrangements

class arrangements.ArrangeIndependent(K=3, P=100, spatial_specific=True, remove_redundancy=False)[source][source]

Independent arrangement model

Estep(emloglik, gather_ss=True)[source][source]

Estep for the spatial arrangement model

Parameters:
  • emloglik – (pt.tensor) emission log likelihood log p(Y|u,theta_E) a numsubj x K x P matrix

  • gather_ss – (bool) Gather Sufficient statistics for M-step (default = True)

Returns:
  • Uhat (pt.tensor) – posterior p(U|Y) a numsubj x K x P matrix

  • ll_A (pt.tensor) – Expected log-liklihood of the arrangement model

Mstep()[source][source]

M-step for the spatial arrangement model. Update the pi for arrangement model uses the epos_Uhat statistic that is put away from the last e-step.

marginal_prob()[source][source]

Returns marginal probabilty for every node under the model

Returns:

pi (pt.tensor) – marginal probability under the model

random_params()[source][source]

Sets prior parameters to random starting values

sample(num_subj=10)[source][source]

Samples a number of subjects from the prior. In this i.i.d arrangement model we assume each node has no relation with other nodes, which means it equals to sample from the prior pi.

Parameters:

num_subj (int) – the number of subjects to sample

Returns:

U (pt.tensor) – the sampled data for subjects

class arrangements.ArrangeIndependentSymmetric(K, indx_full, indx_reduced, same_parcels=False, spatial_specific=True, remove_redundancy=False)[source][source]

Independent arrangement model with symmetry constraint. It has two sizes: P and K (number of nodes / parcels for arrangement model) P_full and K_full (number of location / parcels for data)

Estep(emloglik, gather_ss=True)[source][source]

Estep for the spatial arrangement model

Parameters:
  • emloglik (pt.tensor) – emission log likelihood log p(Y|u,theta_E) a numsubj x K x P matrix

  • gather_ss (bool) – Gather Sufficient statistics for M-step (default = True)

Returns:
  • Uhat (pt.tensor) – posterior p(U|Y) a numsubj x K x P matrix

  • ll_A (pt.tensor) – Expected log-liklihood of the arrangement model

map_to_arrange(emloglik)[source][source]

Maps emission log likelihoods to the internal size of the representation

Parameters:

emloglik (list) – List of emission logliklihoods (K_full x P_full)

Returns:

emloglik_comb (ndarray) – ndarray of emission logliklihoods ()

map_to_full(Uhat)[source][source]

Remapping evidence from an arrangement space to a emission space (here it doesn’t do anything)

Parameters:

Uhat (ndarray) – tensor of estimated arrangement ((num_subj x K x P) or (K x P))

Returns:

Uhat (ndarray) – tensor of estimated arrangements ((num_subj x K_full x P_full) or (K_full x P_full))

marginal_prob()[source][source]

Returns marginal probability for every node under the model

Returns:

pi (pt.tensor) – marginal probability under the model

sample(num_subj=10)[source][source]

Samples a number of subjects from the prior. In this i.i.d arrangement model we assume each node has no relation with other nodes, which means it equals to sample from the prior pi.

Parameters:

num_subj (int) – the number of subjects to sample

Returns:

U (pt.tensor) – the sampled data for subjects

class arrangements.ArrangeIndependentSeparateHem(K, indx_hem, spatial_specific=True, remove_redundancy=False)[source][source]

Independent arrangement model without symmetry constraint, but like a symmetric model, it keeps the parcels (and emission models) for the left and right hemishere separate. P is the same to the full data, K (parcels for arrangement model) K_full (parcels for data)

Parameters:
  • K (int) – Number of different parcels

  • indx_hem (ndarray/tensor) – 1 x P array of indices for the hemisphere -1 - Left; 0 - Midline; 1 - Right

  • spatially_specific (bool) – Use a spatially specific model (default True)

  • remove_redundancy (bool) – Code with K probabilities with K or K-1 parameters?

map_to_arrange(emloglik)[source][source]

Maps emission log likelihoods to the internal size of the representation

Parameters:

emloglik (list) – List of emission logliklihoods

Returns:

emloglik_comb (ndarray) – ndarray of emission logliklihoods

map_to_full(Uhat)[source][source]

remapping evidence from an arrangement space to emission space

Parameters:

Uhat (ndarray) – tensor of estimated arrangement

Returns:

Umap (ndarray) – tensor of estimated arrangements

Functions for Arrangement Models

arrangements.sample_multinomial_pt(p, num_subj=1, kdim=0, compress=False)[source][source]

Samples from a multinomial distribution using pytorch built in multinomial distribution sampler

Parameters:
  • p (pt.tensor) – Tensor of probabilities

  • num_subj (int) – Number of subjects to sample

  • kdim (int) – Dimension of K

  • compress (bool) – Whether to compress the output or not

Returns:

samples (pt.tensor) – Samples from the multinomial distribution

arrangements.sample_multinomial(p, shape=None, kdim=0, compress=False)[source][source]

Samples from a multinomial distribution. fast smpling from matrix probability without looping

Parameters:
  • p (tensor) – Tensor of probilities, which sums to 1 on the dimension kdim

  • shape (tuple) – Shape of the output data (in uncompressed form) Smaller p will be broadcasted to target shape

  • kdim (int) – Number of dimension of p that indicates the different categories (default 0)

  • compress (bool) – Return as int (True) or indicator (false)

Returns:

samples (tensor) – Samples either in indicator coding (compress = False) or as ints (compress = False)

arrangements.expand_mn(u, K)[source][source]

Expands a N x P multinomial vector to an N x K x P tensor of indictor variables

Parameters:
  • u (2d-tensor) – N x nv matrix of samples from [int]

  • K (int) – Number of categories

Returns:

U (3d-tensor) – N x K x nv matrix of indicator variables [default float]

arrangements.expand_mn_1d(U, K)[source][source]

Expands a P long multinomial vector to an K x P tensor of indictor variables

Parameters:
  • U (1d-tensor) – P vector of samples from [int]

  • K (int) – Number of categories

Returns:

U (2d-tensor) – K x P matrix of indicator variables [default float]

arrangements.compress_mn(U)[source][source]

Compresses a N x K x P tensor of indictor variables to a N x P multinomial tensor

Parameters:

U (3d-tensor) – N x K x P matrix of indicator variables

Returns:

u (2d-tensor) – N x P matrix of category labels [int]

arrangements.build_arrangement_model(U, prior_type='prob', atlas=None, sym_type='asym', model_type='independent', Wc=None, theta=None, epos_iter=5, num_chain=20)[source][source]

Builds an arrangment model based on a set of probability

Parameters:
  • U (tensor or ndarray) – A K x P matrix of group probability

  • prior_type (str) – the type of prior, either ‘prob’ or ‘logpi’ (default: ‘prob’) if ‘prob’, the input is the marginal probability K x P matrix, which the columns sum to 1. If ‘logpi’, the input is the group prior in log-space

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

  • sym_type (str) – the symmetry type of the arrangement model (default: ‘asym’)

  • model_type (str) – the arrangement model type (default: ‘independent’)

Returns:

ar_model (object) – the arrangement model object