dnnbrain.brain.core module¶
- class dnnbrain.brain.core.BrainDecoder(brain_activ=None, map_type=None, estimator=None, cv=5, scoring=None)¶
Bases:
objectDecode brain activation to DNN activation or behavior data.
- decode_behavior(beh_data)¶
Decode brain activation to behavior data.
- Parameters
beh_data (ndarray) – Behavior data with shape as (n_stim, n_beh).
- Returns
decode_dict – It depends on map type.
map type
key
value
uv
score
If estimator type is correlation, it’s an array with shape as
(n_beh,).
Each element is the maximal pearson r among all measurements
correlating to the corresponding behavior.
If estimator type is regressor or classifier, it’s an array
with shape as (n_beh, cv).
Each row contains scores of each cross validation fold, when
using the measurement at the maximal location to predict the
corresponding behavior.location
An array with shape as (n_beh,).
Each element is a location of the measurement which makes the
maximal score.model
An array with shape as (n_beh,).
Each element is a model fitted by the measurement at the
maximal location and the corresponding behavior.
Note: not exist when estimator type is correlationconf_m
An array with shape as (n_beh, cv).
Each row contains confusion matrices (n_label, n_label) of
each cross validation fold, when using the measurement at the
maximal location to predict the corresponding behavior.
Note: only exists when estimator type is classifiermv
score
An array with shape as (n_beh, cv).
Each row contains scores of each cross validation fold, when
using all measurements to predict the corresponding behavior.model
An array with shape as (n_beh,).
Each element is a model fitted by all measurements and the
corresponding behavior.conf_m
An array with shape as (n_beh, cv).
Each row contains confusion matrices (n_label, n_label) of
each cross validation fold, when using all measurements to
predict the corresponding behavior.
Note: only exists when estimator type is classifier- Return type
dict
- decode_dnn(dnn_activ)¶
Decode brain activation to DNN activation.
- Parameters
dnn_activ (Activation) – DNN activation.
- Returns
decode_dict – It depends on map type.
Map type
First key
First value
Second key
Second value
uv
layer
(str)
score
If estimator type is correlation, it’s an array with shape
as (n_chn, n_row, n_col) of max scores.
If estimator type is regressor, it’s an array with shape
as (n_chn, n_row, n_col, cv).
The forth dimension contains scores of each cross
validation fold of the max scores.location
An array with shape as (n_chn, n_row, n_col).
Locations of measurement indicators with max scores.model
An array with shape as (n_chn, n_row, n_col).
fitted models of the max scores.
Note: only exists when model is regressormv
layer
(str)
score
An array with shape as (n_chn, n_row, n_col, cv).
The forth dimension contains scores of each
cross validation fold at each unit.model
An array with shape as (n_chn, n_row, n_col).
Each element is a model fitted at the corresponding unit.- Return type
dict
- set_activ(brain_activ)¶
Set brain activation
- Parameters
brain_activ (ndarray) – Brain activation with shape as (n_vol, n_meas). For voxel-wise, n_meas is the number of voxels. For ROI-wise, n_meas is the number of ROIs.
- set_mapper(map_type, estimator, cv, scoring)¶
Set mapper parameters.
- Parameters
map_type (str) – choices=(uv, mv). uv: univariate mapping. mv: multivariate mapping.
estimator (str | sklearn estimator or pipeline) –
If is str, it is a name of a estimator used to do mapping. If is ‘corr’, it just uses correlation rather than prediction.
And the map_type must be ‘uv’.
cv (int) – the number of cross validation folds.
scoring (str or callable) – the method to evaluate the predictions on the test set.
- class dnnbrain.brain.core.BrainEncoder(brain_activ=None, map_type=None, estimator=None, cv=5, scoring=None)¶
Bases:
objectEncode DNN activation or behavior data to brain activation.
- encode_behavior(beh_data)¶
Encode behavior data to brain activation.
- Parameters
beh_data (ndarray) – Behavior data with shape as (n_stim, n_beh).
- Returns
encode_dict – It depends on map type.
Map type
First key
First value
Second key
Second value
uv
layer
(str)
score
If estimator type is correlation, it’s an array with shape
as (n_meas,) of max scores.
If estimator type is regressor, it’s an array with shape as
(n_meas, cv).
The second dimension contains scores of each
cross validation fold at maximal location.location
An array with shape as (n_meas,).
Max locations of the max scores.model
An array with shape as (n_meas,).
Fitted models of the max scores.
Note: only exists when model is regressor.mv
layer
(str)
score
An array with shape as (n_meas, cv).
The second dimension contains scores of each cross
validation fold.model
An array with shape as (n_meas,).
Each element is a model fitted at the corresponding
measurement.- Return type
dict
- encode_dnn(dnn_activ, iter_axis=None)¶
Encode DNN activation to brain activation.
- Parameters
dnn_activ (Activation) – DNN activation.
iter_axis (None or str) –
Iterate along the specified axis. Different map types have different operation.
map type
iter_axis
description
uv
channel
Summarize the maximal prediction score for each channel
row_col
Summarize the maximal prediction score for each position (row_idx, col_idx)
None
Summarize the maximal prediction score for the whole layer
mv
channel
Multivariate prediction using all units in each channel
row_col
Multivariate prediction using all units in each position (row_idx, col_idx)
None
Multivariate prediction using all units in the whole layer
- Returns
encode_dict – It depends on map type.
Map type
First key
First value
Second key
Second value
uv
layer
(str)
score
If estimator type is correlation, it’s an array with shape
as (n_iter, n_meas).
Each element is the maximal pearson r among all features at
corresponding iteration correlating to the corresponding
measurement.
If estimator type is regressor, it’s an array with shape as
(n_iter, n_meas, cv).
For each iteration and measurement, the third axis contains
scores of each cross validation folds, when using the
feature with maximal score to predict the corresponding
measurement.location
An array with shape as (n_iter, n_meas, 3)
Max locations of the max scores, the size 3 of the third
dimension means channel, row and column respectively.model
An array with shape as (n_iter, n_meas).
Fitted models of the max scores.
Note: only exists when estimator type is regressormv
layer
(str)
score
A array with shape as (n_iter, n_meas, cv).
The third dimension means scores of each cross validation
folds at each iteration and measurement.model
A array with shape as (n_iter, n_meas).
Each element is a model fitted at the corresponding
iteration and measurement.- Return type
dict
- set_activ(brain_activ)¶
Set brain activation
- Parameters
brain_activ (ndarray) – Brain activation with shape as (n_vol, n_meas). For voxel-wise, n_meas is the number of voxels. For ROI-wise, n_meas is the number of ROIs.
- set_mapper(map_type, estimator, cv, scoring)¶
Set UnivariateMapping or MultivariateMapping
- Parameters
map_type (str) – choices=(uv, mv) uv: univariate mapping mv: multivariate mapping
estimator (str | sklearn estimator or pipeline) –
If is str, it is a name of a estimator used to do mapping. If is ‘corr’, it just uses correlation rather than prediction.
And the map_type must be ‘uv’.
NOTE: The estimator type can only be regressor or correlation
cv (int) – the number of cross validation folds.
scoring (str or callable) – the method to evaluate the predictions on the test set.
- class dnnbrain.brain.core.ROI(rois=None, value=None)¶
Bases:
objectA class used to encapsulate and manipulate ROI data of brain
- delete(rois)¶
Delete data according to ROI names
- Parameters
rois (str, list) – ROI names.
- get(rois)¶
Get data according to ROI names
- Parameters
rois (str, list) – ROI names.
- Returns
arr – ROI data with shape as (n_vol, n_roi).
- Return type
ndarray
- load(fname, rois=None)¶
Load from ROI file.
- Parameters
fname (str) – File name with suffix as .roi.h5
rois (str, list) – ROI names of interest.
- save(fname)¶
Save to ROI file.
- Parameters
fname (str) – File name with suffix as .roi.h5
- set(rois, value, index=None)¶
Set ROI data with names
- Parameters
rois (str, list) – ROI names.
value (ndarray) – ROI data.
index (int) – The position where the data is set.