Utilities Functions

get_cov(rel_pos, rsq, kappa, lmd, random_seed=None)[source]

Compute Covariances

Compute covariances at the position specified in rel_pos recursively using the function sample_cov satisfying the rsq and the eigen values in kappa and lmd.

Parameters
  • rel_pos (list) – position of relevant components

  • rsq (list) – A list of coefficient of determination

  • kappa (list) – A list of eigenvalues related to response variables

  • lmd (list) – A list of eigenvalues related to predictor variables

  • random_seed (int) – An integer for random state

Returns

A matrix of dimension equals to the length of kappa by length of lmd with computed covariances at the position specified in rel_pos.

Return type

np.array

get_eigen(rate, nvar, min_value=0.0001)[source]

Compute eigen values using exponential decay function.

\[\lambda_i = \text{exp}^{-\gamma(i-1)}\]
Parameters
  • rate – rate of exponential decay factor

  • nvar – Number of variables (number of eigenvalues to compute)

  • min_value – Lower limit for smallest eigenvalue

Returns

A list of eigenvalues

get_relpred(n_pred, n_relpred, pos_relcomp, random_state=None)[source]

Identify relevant predictors through sampling

Get relevant and irrelevant position of predictor variables. The irrelevant components index are the one which are not in pos_relcomp. The number of extra components are defined in n_relpred.

Parameters
  • n_pred (int) – Number of predictor variables

  • n_relpred (list) – List of number of predictors relevant for each response

  • pos_relcomp (list) – List of List containing the position index of relevant components

  • random_state (int) – An integer for random state

Returns

A dictionary with relevant and irrelevant position index of predictors

Return type

dict

get_rotate(mat, pred_pos, random_state=None)[source]

Fill up a block of matrix mat based on position index in pred_pos. The block will be an orthogonal rotation matrix.

Parameters
  • mat (np.array) – A matrix possibly a square matrix as covariance

  • pred_pos (list) – A list of position index for the block rotation

  • random_state (int) – An integer for random state to control randomness

Returns

A matrix of same size as mat but filled with an orthogonal block

Return type

np.array

get_rotation(rel_irrel_pred, random_state=None)[source]

Create orthogonal rotation matrix

Creates an orthogonal rotation matrix from dictionary of relevant and irrelevant positions using get_rotate function.

Parameters

rel_irrel_pred (dict) – A dictionary of relevant and irrelevant position (possibly obtained from the function get_relpred.

Returns

An orthogonal rotation matrix

Return type

np.array

parse_param(parm: Optional[Union[str, int]])[source]

Parse the parameters from string to a nested list

Parameters

parm (str, int) – Either integer, float (in some cases) or mostly string

Returns

A nested list of parsed parameters

Return type

list

sample_cov(lmd, rsq, pos, kappa, alpha_)[source]

Compute covariance satisfying given parameters

Compute covariance from a sample of uniform distribution satisfying rsq, a set of lmd and kappa

Parameters
  • lmd (set or list) – A set of eigenvalue of predictors at position specified by pos.

  • rsq (float) – Coefficient of determination

  • pos (list) – Position index of in which covariance need to be non-zero

  • kappa (list) – Eigenvalue corresponding to response (univariate) or response component (multivariate)

  • alpha – A sample from univariate distribution between -1 and 1

Returns

An array of computed covariances of length equals to lmd.

Return type

np.array

sample_extra_pos(rs, n_extra_pos, extra_pos, irrel_pos)[source]

Sample Extra Position Required

Sample position index of extra relevant predictors from irrelevant predictors in irrel_pos.

Parameters
  • rs (np.random.mtrand.RandomState) – A numpy RandomSeed object

  • n_extra_pos (int) – An integer for number of extra position index to sample

  • extra_pos (list) – A list container for collecting extra relevant components

  • irrel_pos (list) – A list or set of irrelevant position indices

Returns

a list of relevant and irrelevant position indices

Return type

list