pyhrf.vbjde.vem_tools module

TOOLS and FUNCTIONS for VEM JDE Used in different versions of VEM

pyhrf.vbjde.vem_tools.A_Entropy(Sigma_A, M, J)
pyhrf.vbjde.vem_tools.Compute_FreeEnergy(y_tilde, m_A, Sigma_A, mu_Ma, sigma_Ma, m_H, Sigma_H, AuxH, R, R_inv, sigmaH, sigmaG, m_C, Sigma_C, mu_Mc, sigma_Mc, m_G, Sigma_G, AuxG, q_Z, neighboursIndexes, Beta, Gamma, gamma, gamma_h, gamma_g, sigma_eps, XX, W, J, D, M, N, K, hyp, Gamma_X, Gamma_WX, plot=False, bold=False, S=1)
pyhrf.vbjde.vem_tools.H_Entropy(Sigma_H, D)
pyhrf.vbjde.vem_tools.PolyMat(Nscans, paramLFD, tr)

Build polynomial basis

pyhrf.vbjde.vem_tools.Q_Entropy(q_Z, M, J)
pyhrf.vbjde.vem_tools.Q_expectation_Ptilde(q_Z, neighboursIndexes, Beta, gamma, K, M)
pyhrf.vbjde.vem_tools.RF_Entropy(Sigma_RF, D)
pyhrf.vbjde.vem_tools.RF_expectation_Ptilde(m_X, Sigma_X, sigmaX, R, R_inv, D)
pyhrf.vbjde.vem_tools.RL_Entropy(Sigma_RL, M, J)
pyhrf.vbjde.vem_tools.RL_expectation_Ptilde(m_X, Sigma_X, mu_Mx, sigma_Mx, q_Z)
pyhrf.vbjde.vem_tools.Z_Entropy(q_Z, M, J)
pyhrf.vbjde.vem_tools.beta_gradient(beta, labels_proba, labels_neigh, neighbours_indexes, gamma, gradient_method='m1')

Computes the gradient of the beta function

Parameters:
  • beta (float) –
  • labels_proba (ndarray) –
  • labels_neigh (ndarray) –
  • neighbours_indexes (ndarray) –
  • gamma (float) –
  • gradient_method (str) – for testing purposes
Returns:

gradient – the gradient estimated in beta

Return type:

float

pyhrf.vbjde.vem_tools.beta_maximization(beta, labels_proba, neighbours_indexes, gamma)

Computes the Beta Maximization step of the JDE VEM algorithm

Parameters:
  • beta (ndarray) – initial value of beta
  • labels_proba (ndarray) –
  • neighbours_indexes (ndarray) –
  • gamma (float) –
Returns:

  • beta (float) – the new value of beta
  • success (bool) – True if the maximization has succeeded

pyhrf.vbjde.vem_tools.buildFiniteDiffMatrix(order, size, regularization=None)

Build the finite difference matrix used for the hrf regularization prior.

Parameters:
  • order (int) – difference order (see numpy.diff function)
  • size (int) – size of the matrix
  • regularization (array like, optional) – one dimensional vector of factors used for regularizing the hrf
Returns:

diffMat – the finite difference matrix

Return type:

ndarray, shape (size, size)

pyhrf.vbjde.vem_tools.computeFit(m_H, m_A, X, J, N)
pyhrf.vbjde.vem_tools.computeFit_asl(H, m_A, G, m_C, W, XX)

Compute Fit

pyhrf.vbjde.vem_tools.compute_contrasts(condition_names, contrasts, m_A, m_C, Sigma_A, Sigma_C, M, J)
pyhrf.vbjde.vem_tools.compute_mat_X_2(nbscans, tr, lhrf, dt, onsets, durations=None)
pyhrf.vbjde.vem_tools.constraint_norm1_b(Ftilde, Sigma_F, positivity=False, perfusion=None)

Constrain with optimization strategy

pyhrf.vbjde.vem_tools.contrasts_mean_var_classes(contrasts, condition_names, nrls_mean, nrls_covar, nrls_class_mean, nrls_class_var, nb_contrasts, nb_classes, nb_voxels)

Computes the contrasts nrls from the conditions nrls and the mean and variance of the gaussian classes of the contrasts (in the cases of all inactive conditions and all active conditions) :param def_contrasts: TODO. :type def_contrasts: OrderedDict :param condition_names: TODO. :type condition_names: list :param nrls_mean: TODO. :type nrls_mean: ndarray, shape (nb_voxels, nb_conditions) :param nrls_covar: TODO. :type nrls_covar: ndarray, shape (nb_conditions, nb_conditions, nb_voxels) :param nrls_class_mean: TODO. :type nrls_class_mean: ndarray, shape (nb_conditions, nb_classes) :param nrls_class_var: TODO. :type nrls_class_var: ndarray, shape (nb_conditions, nb_classes) :param nb_contrasts: :type nb_contrasts: int :param nb_classes: :type nb_classes: int

Returns:
  • contrasts_mean (ndarray, shape (nb_voxels, nb_contrasts))
  • contrasts_var (ndarray, shape (nb_voxels, nb_contrasts))
  • contrasts_class_mean (ndarray, shape (nb_contrasts, nb_classes))
  • contrasts_class_var (ndarray, shape (nb_contrasts, nb_classes))
pyhrf.vbjde.vem_tools.cosine_drifts_basis(nb_scans, param_lfd, tr)

Build cosine drifts basis

nb_scans : int param_lfd : int

TODO

tr : float

Returns:drifts_basis – K is determined by the scipy.linalg.orth function and corresponds to the effective rank of the matrix it is applied to (see function’s docstring)
Return type:ndarray, shape (nb_scans, K)
pyhrf.vbjde.vem_tools.covariance_matrix(order, D, dt)
pyhrf.vbjde.vem_tools.create_conditions(onsets, durations, nb_conditions, nb_scans, hrf_len, tr, dt)

Generate the occurences matrix

Parameters:
  • onsets (dict) – dictionary of onsets
  • durations (dict) – # TODO
  • nb_conditions (int) –
  • nb_scans (int) –
  • hrf_len (int) –
  • tr (float) –
  • dt (float) –
Returns:

  • X (dict) – dictionary of the occurence matrix
  • occurence_matrix (ndarray)
  • condition_names (list)

pyhrf.vbjde.vem_tools.create_neighbours(graph)

Transforms the graph list in ndarray. This is for performances purposes. Sets the empty neighbours to -1.

graph
: ndarray of lists
each graph[i] represents the list of neighbours of the ith voxel

nb_voxels : int

Returns:neighbours_indexes
Return type:ndarray
pyhrf.vbjde.vem_tools.drifts_coeffs_fit(signal, drift_basis)

# TODO

Parameters:
  • signal (ndarray, shape (nb_scans, nb_voxels)) –
  • drift_basis (ndarray, shape (nb_scans, int)) –
Returns:

drift_coeffs

Return type:

ndarray, shape

pyhrf.vbjde.vem_tools.expectation_A_asl(H, G, m_C, W, XX, Gamma, Gamma_X, q_Z, mu_Ma, sigma_Ma, J, y_tilde, Sigma_H, sigma_eps_m)

Expectation-A step: p_A = argmax_h(E_pc,pq,ph,pg[log p(a|y, h, c, g, q; theta)])

propto exp(E_pc,ph,pg[log p(y|h, a, c, g; theta)] + E_pq[log p(a|q; mu_Ma, sigma_Ma)])

Returns: m_A, Sigma_A of probability distribution p_A of the current iteration

pyhrf.vbjde.vem_tools.expectation_A_ms(m_A, Sigma_A, H, G, m_C, W, XX, Gamma, Gamma_X, q_Z, mu_Ma, sigma_Ma, J, y_tilde, Sigma_H, sigma_eps_m, N, M, D, S)

Expectation-A step: p_A = argmax_h(E_pc,pq,ph,pg[log p(a|y, h, c, g, q; theta)])

propto exp(E_pc,ph,pg[log p(y|h, a, c, g; theta)] + E_pq[log p(a|q; mu_Ma, sigma_Ma)])

Returns: m_A, Sigma_A of probability distribution p_A of the current iteration

pyhrf.vbjde.vem_tools.expectation_C_asl(G, H, m_A, W, XX, Gamma, Gamma_X, q_Z, mu_Mc, sigma_Mc, J, y_tilde, Sigma_G, sigma_eps_m)

Expectation-C step: p_C = argmax_h(E_pa,pq,ph,pg[log p(a|y, h, a, g, q; theta)])

propto exp(E_pa,ph,pg[log p(y|h, a, c, g; theta)] + E_pq[log p(c|q; mu_Mc, sigma_Mc)])

Returns: m_C, Sigma_C of probability distribution p_C of the current iteration

pyhrf.vbjde.vem_tools.expectation_C_ms(m_C, Sigma_C, G, H, m_A, W, XX, Gamma, Gamma_X, q_Z, mu_Mc, sigma_Mc, J, y_tilde, Sigma_G, sigma_eps_m, N, M, D, S)

Expectation-C step: p_C = argmax_h(E_pa,pq,ph,pg[log p(a|y, h, a, g, q; theta)])

propto exp(E_pa,ph,pg[log p(y|h, a, c, g; theta)] + E_pq[log p(c|q; mu_Mc, sigma_Mc)])

Returns: m_C, Sigma_C of probability distribution p_C of the current iteration

pyhrf.vbjde.vem_tools.expectation_G_asl(Sigma_C, m_C, m_A, H, XX, W, WX, Gamma, Gamma_WX, XW_Gamma_WX, J, y_tilde, cov_noise, R_inv, sigmaG, prior_mean_term, prior_cov_term)

Expectation-G step: p_G = argmax_g(E_pa,pc,ph[log p(g|y, a, c, h; theta)])

propto exp(E_pa,pc,ph[log p(y|h, a, c, g; theta) + log p(g; sigmaG)])

Returns: m_G, Sigma_G of probability distribution p_G of the current iteration

pyhrf.vbjde.vem_tools.expectation_G_ms(Sigma_C, m_C, m_A, H, XX, W, WX, Gamma, Gamma_WX, XW_Gamma_WX, J, y_tilde, cov_noise, R_inv, sigmaG, prior_mean_term, prior_cov_term, N, M, D, S)

Expectation-G step: p_G = argmax_g(E_pa,pc,ph[log p(g|y, a, c, h; theta)])

propto exp(E_pa,pc,ph[log p(y|h, a, c, g; theta) + log p(g; sigmaG)])

Returns: m_G, Sigma_G of probability distribution p_G of the current iteration

pyhrf.vbjde.vem_tools.expectation_H_asl(Sigma_A, m_A, m_C, G, XX, W, Gamma, Gamma_X, X_Gamma_X, J, y_tilde, cov_noise, R_inv, sigmaH, prior_mean_term, prior_cov_term)

Expectation-H step: p_H = argmax_h(E_pa,pc,pg[log p(h|y, a, c, g; theta)])

propto exp(E_pa,pc,pg[log p(y|h, a, c, g; theta) + log p(h; sigmaH)])

Returns: m_H, Sigma_H of probability distribution p_H of the current iteration

pyhrf.vbjde.vem_tools.expectation_H_ms(Sigma_A, m_A, m_C, G, XX, W, Gamma, Gamma_X, X_Gamma_X, J, y_tilde, cov_noise, R_inv, sigmaH, prior_mean_term, prior_cov_term, N, M, D, S)

Expectation-H step: p_H = argmax_h(E_pa,pc,pg[log p(h|y, a, c, g; theta)])

propto exp(E_pa,pc,pg[log p(y|h, a, c, g; theta) + log p(h; sigmaH)])

Returns: m_H, Sigma_H of probability distribution p_H of the current iteration

pyhrf.vbjde.vem_tools.expectation_H_ms_concat(Sigma_A, m_A, m_C, G, XX, W, Gamma, Gamma_X, X_Gamma_X, J, y_tilde, cov_noise, R_inv, sigmaH, prior_mean_term, prior_cov_term, S)

Expectation-H step: p_H = argmax_h(E_pa,pc,pg[log p(h|y, a, c, g; theta)])

propto exp(E_pa,pc,pg[log p(y|h, a, c, g; theta) + log p(h; sigmaH)])

Returns: m_H, Sigma_H of probability distribution p_H of the current iteration

pyhrf.vbjde.vem_tools.expectation_Ptilde_Likelihood(y_tilde, m_A, Sigma_A, H, Sigma_H, m_C, Sigma_C, G, Sigma_G, XX, W, sigma_eps, Gamma, J, D, M, N, Gamma_X, Gamma_WX)
pyhrf.vbjde.vem_tools.expectation_Q_asl(Sigma_A, m_A, Sigma_C, m_C, sigma_Ma, mu_Ma, sigma_Mc, mu_Mc, Beta, p_q_t, p_Q, neighbours_indexes, graph, M, J, K)
pyhrf.vbjde.vem_tools.expectation_Q_async_asl(Sigma_A, m_A, Sigma_C, m_C, sigma_Ma, mu_Ma, sigma_Mc, mu_Mc, Beta, p_q_t, p_Q, neighbours_indexes, graph, M, J, K)
pyhrf.vbjde.vem_tools.expectation_Q_ms(Sigma_A, m_A, Sigma_C, m_C, sigma_Ma, mu_Ma, sigma_Mc, mu_Mc, Beta, p_q_t, p_Q, neighbours_indexes, graph, M, J, K, S)
pyhrf.vbjde.vem_tools.expectation_ptilde_hrf(hrf_mean, hrf_covar, sigma_h, hrf_regu_prior, hrf_regu_prior_inv, hrf_len)
pyhrf.vbjde.vem_tools.expectation_ptilde_labels(labels_proba, neighbours_indexes, beta, nb_conditions, nb_classes)
pyhrf.vbjde.vem_tools.expectation_ptilde_likelihood(data_drift, nrls_mean, nrls_covar, hrf_mean, hrf_covar, occurence_matrix, noise_var, noise_struct, nb_voxels, nb_scans)

likelihood # TODO

Parameters:
  • data_drift (ndarray, shape (nb_scans, nb_voxels)) – This is the BOLD data minus the drifts (y_tilde in the paper)
  • nrls_mean (ndarray, shape (nb_voxels, nb_conditions)) –
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels)) –
  • hrf_mean (ndarray, shape (hrf_len,)) –
  • hrf_covar (ndarray, shape (hrf_len, hrf_len)) –
  • occurence_matrix (ndarray, shape (nb_conditions, nb_scans, hrf_len)) –
  • noise_var (ndarray, shape (nb_voxels,)) –
  • noise_struct (ndarray, shape (nb_scans, nb_scans)) –
  • nb_voxels (int) –
  • nb_scans (int) –
Returns:

ptilde_likelyhood

Return type:

float

pyhrf.vbjde.vem_tools.expectation_ptilde_nrls(labels_proba, nrls_class_mean, nrls_class_var, nrls_mean, nrls_covar)
pyhrf.vbjde.vem_tools.fit_hrf_two_gammas(hrf_mean, dt, duration)

Fits the estimated HRF to the standard two gammas model.

Parameters:hrf_mean (ndarray, shape (hrf_len,)) –
Returns:
  • delay_of_response (float)
  • delay_of_undershoot (float)
  • dispersion_of_response (float)
  • dispersion_of_undershoot (float)
  • ratio_resp_under (float)
  • delay (float)
pyhrf.vbjde.vem_tools.free_energy_computation(nrls_mean, nrls_covar, hrf_mean, hrf_covar, hrf_len, labels_proba, data_drift, occurence_matrix, noise_var, noise_struct, nb_conditions, nb_voxels, nb_scans, nb_classes, nrls_class_mean, nrls_class_var, neighbours_indexes, beta, sigma_h, hrf_regu_prior, hrf_regu_prior_inv, gamma, hrf_hyperprior)

Compute the free energy.

Returns:free_energy
Return type:float
pyhrf.vbjde.vem_tools.fun(Beta, p_Q, Qtilde_sumneighbour, neighboursIndexes, gamma)

function to minimize

pyhrf.vbjde.vem_tools.grad_fun(Beta, p_Q, Qtilde_sumneighbour, neighboursIndexes, gamma)

function to minimize

pyhrf.vbjde.vem_tools.hrf_entropy(hrf_covar, hrf_len)

Compute the entropy of the heamodynamic response function.

Parameters:
  • hrf_covar (ndarray, shape (hrf_len, hrf_len)) – Covariance matrix of the HRF
  • hrf_len (int) – size of the HRF
Returns:

entropy

Return type:

float

pyhrf.vbjde.vem_tools.hrf_expectation(nrls_covar, nrls_mean, occurence_matrix, noise_struct, hrf_regu_prior_inv, sigmaH, nb_voxels, y_tilde, noise_var, prior_mean_term=0.0, prior_cov_term=0.0)

Computes the E-H step of the JDE-VEM algorithm.

Expectation-H step: p_H = argmax_h(E_pa[log p(h|y, a ; theta)])

propto exp(E_pa[log p(y|h, a; theta) + log p(h; sigmaH)])
Parameters:
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels)) –
  • nrls_mean (ndarray, shape (nb_voxels, nb_conditions)) –
  • occurence_matrix (ndarray, shape (nb_conditions, nb_scans, hrf_len)) –
  • noise_struct (ndarray, shape (nb_scans, nb_scans)) –
  • hrf_regu_prior_inv (ndarray, shape (hrf_len, hrf_len)) – inverse of the hrf regularization prior matrix R
  • sigmaH (float) –
  • nb_voxels (int) –
  • y_tilde (ndarray, shape (nb_scans, nb_voxels)) –
  • noise_var (ndarray, shape (nb_voxels,)) –
  • prior_mean_term (float, optional) –
  • prior_cov_term (float, optional) –
Returns:

  • hrf_mean (ndarray, shape (hrf_len,))
  • hrf_covar (ndarray, shape (hrf_len, hrf_len))

pyhrf.vbjde.vem_tools.labels_entropy(labels_proba)

Compute the labels entropy.

Parameters:
  • labels_proba (ndarray, shape (nb_conditions, nb_classes, nb_voxels)) – Probability of each voxel to be in one class
  • nb_conditions (int) –
  • nb_voxels (int) –
Returns:

entropy

Return type:

float

pyhrf.vbjde.vem_tools.labels_expectation(nrls_covar, nrls_mean, nrls_class_var, nrls_class_mean, beta, labels_proba, neighbours_indexes, nb_conditions, nb_classes, nb_voxels=None, parallel=True, nans_init=False)

Computes the E-Z (or E-Q) step of the JDE-VEM algorithm.

Parameters:
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels)) –
  • nrls_mean (ndarray, shape (nb_voxels, nb_conditions)) –
  • nrls_class_var (ndarray, shape (nb_conditions, nb_classes)) –
  • nrls_class_mean (ndarray, shape (nb_conditions, nb_classes)) –
  • beta (ndarray, shape) –
  • labels_proba (ndarray, shape (nb_conditions, nb_classes, nb_voxels)) –
  • neighbours_indexes (ndarray, shape (nb_voxels, max(len(a) for a in graph))) – This is the version of graph array where arrays from graph smaller than the maximum ones are filled with -1
  • nb_conditions (int) –
  • nb_classes (int) –
Returns:

labels_proba

Return type:

ndarray, shape (nb_conditions, nb_classes, nb_voxels)

pyhrf.vbjde.vem_tools.maximization_LA_asl(Y, m_A, m_C, XX, WP, W, WP_Gamma_WP, H, G, Gamma)
pyhrf.vbjde.vem_tools.maximization_Mu_asl(H, G, matrix_covH, matrix_covG, sigmaH, sigmaG, sigmaMu, Omega, R_inv)
pyhrf.vbjde.vem_tools.maximization_beta_m2_asl(beta, p_Q, Qtilde_sumneighbour, Qtilde, neighboursIndexes, maxNeighbours, gamma, MaxItGrad, gradientStep)
pyhrf.vbjde.vem_tools.maximization_beta_m2_scipy_asl(Beta, p_Q, Qtilde_sumneighbour, Qtilde, neighboursIndexes, maxNeighbours, gamma, MaxItGrad, gradientStep)

Maximize beta

pyhrf.vbjde.vem_tools.maximization_beta_m4_asl(beta, p_Q, Qtilde_sumneighbour, Qtilde, neighboursIndexes, maxNeighbours, gamma, MaxItGrad, gradientStep)
pyhrf.vbjde.vem_tools.maximization_class_proba(labels_proba, nrls_mean, nrls_covar)
pyhrf.vbjde.vem_tools.maximization_drift_coeffs(data, nrls_mean, occurence_matrix, hrf_mean, noise_struct, drift_basis)
pyhrf.vbjde.vem_tools.maximization_mu_sigma_asl(q_Z, m_X, Sigma_X)
pyhrf.vbjde.vem_tools.maximization_mu_sigma_ms(q_Z, m_X, Sigma_X, M, J, S, K)
pyhrf.vbjde.vem_tools.maximization_noise_var(occurence_matrix, hrf_mean, hrf_covar, nrls_mean, nrls_covar, noise_struct, data_drift, nb_scans)

Computes the M-sigma_epsilone step of the JDE-VEM algorithm.

pyhrf.vbjde.vem_tools.maximization_sigmaH(D, Sigma_H, R, m_H)
pyhrf.vbjde.vem_tools.maximization_sigmaH_prior(D, Sigma_H, R, m_H, gamma_h)
pyhrf.vbjde.vem_tools.maximization_sigma_asl(D, Sigma_H, R_inv, m_H, use_hyp, gamma_h)
pyhrf.vbjde.vem_tools.maximization_sigma_noise_asl(XX, m_A, Sigma_A, H, m_C, Sigma_C, G, Sigma_H, Sigma_G, W, y_tilde, Gamma, Gamma_X, Gamma_WX, N)

Maximization sigma_noise

pyhrf.vbjde.vem_tools.maximum(iterable)

Return the maximum and the indice of the maximum of an iterable.

iterable : iterable or numpy array

Returns tuple :

iter_max : the maximum iter_max_indice : the indice of the maximum
pyhrf.vbjde.vem_tools.mult(v1, v2)

Multiply two vectors.

The first vector is made vertical and the second one horizontal. The result will be a matrix of size len(v1), len(v2).

Parameters:
Returns:

x

Return type:

ndarray, shape (len(v1), len(v2))

pyhrf.vbjde.vem_tools.norm1_constraint(function, variance)

Returns the function constrained with optimization strategy.

Parameters:
  • function (array_like) – function to optimize under norm1 constraint
  • variance (array_like) – variance of the function, must be the same size
Returns:

optimized_function

Return type:

numpy array

Raises:

ValueError – If len(variance) != len(function)

pyhrf.vbjde.vem_tools.normpdf(x, mu, sigma)
pyhrf.vbjde.vem_tools.nrls_entropy(nrls_covar, nb_conditions)

Compute the entropy of neural response levels.

Parameters:
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels)) – Covariance of the NRLs
  • nb_conditions (int) –
  • nb_voxels (int) –
Returns:

entropy

Return type:

float

pyhrf.vbjde.vem_tools.nrls_expectation(hrf_mean, nrls_mean, occurence_matrix, noise_struct, labels_proba, nrls_class_mean, nrls_class_var, nb_conditions, y_tilde, nrls_covar, hrf_covar, noise_var)

Computes the E-A step of the JDE-VEM algorithm.

p_A = argmax_h(E_pc,pq,ph,pg[log p(a|y, h, c, g, q; theta)])
propto exp(E_pc,ph,pg[log p(y|h, a, c, g; theta)] + E_pq[log p(a|q; mu_Ma, sigma_Ma)])

# TODO: add formulas using reST

Parameters:
  • hrf_mean (ndarray, shape (hrf_len,)) –
  • nrls_mean (ndarray, shape (nb_voxels, nb_conditions)) –
  • occurence_matrix (ndarray, shape (nb_conditions, nb_scans, hrf_len)) –
  • noise_struct (ndarray, shape (nb_scans, nb_scans)) –
  • labels_proba (ndarray, shape (nb_conditions, nb_classes, nb_voxels)) –
  • nrls_class_mean (ndarray, shape (nb_conditions, nb_classes)) –
  • nrls_class_var (ndarray, shape (nb_conditions, nb_classes)) –
  • hrf_len (int) –
  • nb_voxels (int) –
  • nb_conditions (int) –
  • nb_classes (int) –
  • y_tilde (ndarray, shape (nb_scans, nb_voxels)) – BOLD data minus drifts
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels)) –
  • hrf_covar (ndarray, shape (hrf_len, hrf_len)) –
  • noise_var (ndarray, shape (nb_voxels,)) –
Returns:

  • nrls_mean (ndarray, shape (nb_voxels, nb_conditions))
  • nrls_covar (ndarray, shape (nb_conditions, nb_conditions, nb_voxels))

pyhrf.vbjde.vem_tools.plot_convergence(ni, M, cA, cC, cH, cG, cAH, cCG, SUM_q_Z, mua1, muc1, FE)
pyhrf.vbjde.vem_tools.plot_response_functions_it(ni, NitMin, M, H, G, Mu=None, prior=None)
pyhrf.vbjde.vem_tools.polyFit(signal, tr, order, p)
pyhrf.vbjde.vem_tools.poly_drifts_basis(nb_scans, param_lfd, tr)

Build polynomial drifts basis

Parameters:
  • nb_scans (int) –
  • param_lfd (int) – TODO
  • tr (float) –
Returns:

drifts_basis – K is determined by the scipy.linalg.orth function and corresponds to the effective rank of the matrix it is applied to (see function’s docstring)

Return type:

ndarray, shape (nb_scans, K)

pyhrf.vbjde.vem_tools.ppm_contrasts(contrasts_mean, contrasts_var, contrasts_class_mean, contrasts_class_var, threshold_a='std_inact', threshold_g=0.95)

Computes the ppm for the given contrast using either the standard deviation of the “all inactive conditions” class gaussian (default) or the intersection of the [all inactive conditions] and [all active conditions] classes gaussians as threshold for the PPM_a and 0.95 (default) for the PPM_g. Be carefull, this computation considers the mean of the inactive class as zero.

Parameters:
  • contrasts_mean (ndarray, shape (nb_voxels, nb_contrasts)) –
  • contrasts_var (ndarray, shape (nb_voxels, nb_contrasts)) –
  • contrasts_class_mean (ndarray, shape (nb_contrasts, nb_classes)) –
  • contrasts_class_var (ndarray, shape (nb_contrasts, nb_classes)) –
  • threshold_a (str, optional) – if “std_inact” (default) uses the standard deviation of the [all inactive conditions] gaussian class as PPM_a threshold, if “intersect” uses the intersection of the [all inactive/all active conditions] gaussian classes
  • threshold_g (float, optional) – the threshold of the PPM_g
Returns:

  • ppm_a_contrasts (ndarray, shape (nb_voxels, nb_contrasts))
  • ppm_g_contrasts (ndarray, shape (nb_voxels, nb_contrasts))

pyhrf.vbjde.vem_tools.ppms_computation(elements_mean, elements_var, class_mean, class_var, threshold_a='std_inact', threshold_g=0.9)

Considering the elements_mean and elements_var from a gaussian distribution, comutes the posterior probability maps considering for the alpha threshold, either the standard deviation of the [all inactive conditions] class guassian or the intersection of the [all (in)active conditions] classes guassians; and for the gamma threshold 0.9 (default) Be carefull, this computation considers the mean of the inactive class as zero.

Notes

nb_elements refers either to the number of contrats (for the PPMs contrasts computation) or for the number of conditions (for the PPMs nrls computation)

Parameters:
  • elements_mean (ndarray, shape (nb_voxels, nb_elements)) –
  • elements_var (ndarray, shape (nb_voxels, nb_elements)) –
  • class_mean (ndarray, shape (nb_elements, nb_classes)) –
  • class_var (ndarray, shape (nb_elements, nb_classes)) –
  • threshold_a (str, optional) – if “std_inact” (default) uses the standard deviation of the [all inactive conditions] gaussian class as PPM_a threshold, if “intersect” uses the intersection of the [all inactive/all active conditions] gaussian classes
  • threshold_g (float, optional) – the threshold of the PPM_g
Returns:

  • ppm_a (ndarray, shape (nb_voxels, nb_elements))
  • ppm_g (ndarray, shape (nb_voxels, nb_elements))

pyhrf.vbjde.vem_tools.roc_curve(dvals, labels, rocN=None, normalize=True)

Compute ROC curve coordinates and area

  • dvals - a list with the decision values of the classifier
  • labels - list with class labels, in {0, 1}

returns (FP coordinates, TP coordinates, AUC )

pyhrf.vbjde.vem_tools.sum_over_neighbours(neighbours_indexes, array_to_sum)

Sums the array_to_sum over the neighbours in the graph.