pyhrf.rfir module¶
-
class
pyhrf.rfir.
RFIREstim
(hrf_nb_coeffs=42, hrf_dt=0.6, drift_type='cosine', stop_crit1=0.0001, stop_crit2=1e-05, nb_its_max=5, nb_iterations=500, nb_its_min=1, average_bold=False, taum=0.01, lambda_reg=100.0, fixed_taum=False, discarded_scan_indexes=None, output_fit=False)¶ Bases:
pyhrf.xmlio.Initable
Class handling the estimation of HRFs from fMRI data. Analysis is voxel-wise and can be multissession (heteroscedastic noise and session dependent drift). Simultaneous analysis of several conditions is treated. One HRF is considered at each voxel.
-
Compute_INV_R_and_R_and_DET_R
()¶ both computes self.InvR and self.DetR requires:
- K-1
- InvR initialized
-
Compute_onset_matrix3
()¶ computes the onset matrix. Each stimulus onset is considered over a period of LengthOnsets seconds if (LengthOnsets>DetlaT) and a time step otherwise. requires:
- X initialized
- OnsetList
- TR
- DeltaT
- K
- LengthOnsets
- where ‘self.X[i][m,n,k]’ is such that:
- session i (in 0:I-1)
- condition m (in 0:M-1)
- data nb n (in 0:Ni[i]-1)
- hrf coef nb k (in 0:K-2)
-
CptFctQ
(CptType)¶ Computes the function Q(Theta’, ilde{Theta};y) at a given iteration requires:
- All parameters and hyperparameters
- Sigma
- InvR
- CptType = ‘K_Km1’ or ‘K_K’
-
CptSigma
()¶ Computes the Sigma at a given iteration requires:
- InvR
- TauM
- rb
- X
- M
- remark:
- self.Sigma[m*SBS:(m+1)*SBS,n*SBS:(n+1)*SBS]] -> (m,n)^th block of Sigma in session i
-
EM_solver
(POI)¶ requires: * everything in the class is supposed initialized
-
InitMatrixAndVectors
(POI)¶ initialize to zeros: X, y, P, l, h, InvR, Sigma initialize to ones: TauM, rb (<-scalar) requires:
I / Ni / K / M / Qi
-
InitStorageMat
()¶ initialization of the matrices that will store all voxel resuls requires:
input signals must have been read (in ReadRealSignal)
-
ReadPointOfInterestData
(POI)¶ Initialize the parameters for a voxel analysis. The voxel ID is ‘POI’ in ‘ConsideredCoord’ initialized in ‘ReadRealSignal’ requires:
input signals must have been read (in ReadRealSignal)
-
StoreRes
(POI)¶ Store results computed in the voxel defined in POI requires:
- the estimation at this voxel must have been performed
-
buildCosMat
(fctNb, tr, ny)¶ build a cosine low frequency basis in P (adapted from samplerbase.py) requires:
- fctNb: columns number in the current session
- tr: the time resolution of the BOLD data (in second)
- ny: number of data for the current session
-
buildLowFreqMat
()¶ build the low frequency basis matrix P requires:
- self.OrthoBtype
- self.Qi
- self.TR
- self.Ni
- self.I
-
buildPolyMat
(fctNb, tr, ny)¶ build a polynomial low frequency basis in P (adapted from samplerbase.py) requires:
- fctNb: columns number in the current session
- tr: the time resolution of the BOLD data (in second)
- ny: number of data for the current session
- problems:
- there may have no constant column in the orthogonal matrix (the algorithm suppose there is one such column)
- the columns number is not always as expected
-
clean_memory
()¶ Clean all objects that are useless for outputs
-
compute_fit
(POI)¶
-
cpt_XSigmaX
(tempTerm2i, SBS, i)¶
-
default_nb_its
= 500¶
-
default_stop_crit1
= 0.0001¶
-
default_stop_crit2
= 1e-05¶
-
getOutputs
()¶
-
linkToData
(data)¶
-
parametersComments
= {'hrf_dt': 'Required HRF temporal resolution', 'hrf_nb_coeffs': 'Number of values in the discrete HRF. Discretization is homogeneous HRF time length is then: nb_hrf_coeffs * hrf_dt ', 'drift_type': 'Basis type in the drift model. Either "cosine" or "poly"'}¶
-
parametersToShow
= ['hrf_nb_coeffs', 'hrf_dt', 'drift_type', 'nb_iterations']¶
-
run
()¶ function to launch the analysis
-
-
pyhrf.rfir.
init_dict
()¶
-
pyhrf.rfir.
rfir
(func_data, fir_duration=42, fir_dt=0.6, nb_its_max=100, nb_its_min=5, fixed_taum=False, lambda_reg=100.0)¶ Fit a Regularized FIR on functional data func_data: - multisession voxel-based fwd model: y = sum Xh + Pl + b - heteroscedastic noise - session dependent drift coefficients - one HRF per condition - solved by Expectation-Minimization (EM) (iterative scheme)
Reference: “Unsupervised robust non-parametric estimation of the hemodynamic response function for any fMRI experiment.” Ciuciu, J.-B. Poline, G. Marrelec, J. Idier, Ch. Pallier, and H. Benali. IEEE Trans. Med. Imag., 22(10):1235-1251, Oct. 2003.
Parameters: - *func_data* (pyhrf.core.FmriData) –
- *fir_duration* (float) – FIR duration in seconds
- *fir_dt* (float) – FIR temporal resolution
- *fixed_taum* (bool) – enable faster (drafter) RFIR version where the HRF variance hyper-parameter is fixed.
- *lambda_reg* (float) – amount of temporal regularization for the HRF. Only used if fixed_taum is true.
- *nb_its_min* – minimum number of iterations for the EM
- *nb_its_max* – maximum number of iterations for the EM
Returns: dict of xndarray instances
The returned dict contains: {“”:
“”:}