mvpa2.mappers.detrend.PolyDetrendMapper

Inheritance diagram of PolyDetrendMapper

class mvpa2.mappers.detrend.PolyDetrendMapper(polyord=1, chunks_attr=None, opt_regs=None, **kwargs)

Mapper for regression-based removal of polynomial trends.

Noteworthy features are the possibility for chunk-wise detrending, optional regressors, and the ability to use positional information about the samples from the dataset.

Any sample attribute from the to be mapped dataset can be used to define chunks that shall be detrended separately. The number of chunks is determined from the number of unique values of the attribute and all samples with the same value are considered to be in the same chunk.

It is possible to provide a list of additional sample attribute names that will be used as confound regressors during detrending. This, for example, allows to use fMRI motion correction parameters to be considered.

Finally, it is possible to use positional information about the dataset samples for the detrending. This is useful, for example, if the samples in the dataset are not equally spaced out over the acquisition time-window. In that case an actually linear trend in the data would be distorted and not properly removed. By setting the inspace argument to the name of a samples attribute that carries this information, the mapper will take this into account and shift the polynomials accordingly. If inspace is given, but the dataset doesn’t contain such an attribute evenly spaced coordinates are generated and this information is stored in the mapped dataset.

Notes

The mapper only support mapping of datasets, not plain data. Moreover, reverse mapping, or subsequent forward-mapping of partial datasets are currently not implemented.

Examples

>>> from mvpa2.datasets import dataset_wizard
>>> from mvpa2.mappers.detrend import PolyDetrendMapper
>>> samples = np.array([[1.0, 2, 3, 3, 2, 1],
...                    [-2.0, -4, -6, -6, -4, -2]]).T
>>> chunks = [0, 0, 0, 1, 1, 1]
>>> ds = dataset_wizard(samples, chunks=chunks)
>>> dm = PolyDetrendMapper(chunks_attr='chunks', polyord=1)
>>> # the mapper will be auto-trained upon first use
>>> mds = dm.forward(ds)
>>> # total removal all all (chunk-wise) linear trends
>>> np.sum(np.abs(mds)) < 0.00001
True

Available conditional attributes:

  • calling_time+: Time (in seconds) it took to call the node
  • raw_results: Computed results before invoking postproc. Stored only if postproc is not None.
  • training_time+: Time (in seconds) it took to train the learner

(Conditional attributes enabled by default suffixed with +)

Parameters :

polyord : int or list, optional

Order of the Legendre polynomial to remove from the data. This will remove every polynomial up to and including the provided value. For example, 3 will remove 0th, 1st, 2nd, and 3rd order polynomials from the data. np.B.: The 0th polynomial is the baseline shift, the 1st is the linear trend. If you specify a single int and chunks_attr is not None, then this value is used for each chunk. You can also specify a different polyord value for each chunk by providing a list or ndarray of polyord values the length of the number of chunks.

chunks_attr : str or None

If None, the whole dataset is detrended at once. Otherwise, the given samples attribute (given by its name) is used to define chunks of the dataset that are processed individually. In that case, all the samples within a chunk should be in contiguous order and the chunks should be sorted in order from low to high – unless the dataset provides information about the coordinate of each sample in the space that should be spanned be the polynomials (see inspace argument).

opt_regs : list or None

Optional list of sample attribute names that should be used as additional regressors. One example would be to regress out motion parameters.

space : str or None

If not None, a samples attribute of the same name is added to the mapped dataset that stores the coordinates of each sample in the space that is spanned by the polynomials. If an attribute of that name is already present in the input dataset its values are interpreted as sample coordinates in the space that should be spanned by the polynomials.

enable_ca : None or list of str

Names of the conditional attributes which should be enabled in addition to the default ones

disable_ca : None or list of str

Names of the conditional attributes which should be disabled

auto_train : bool

Flag whether the learner will automatically train itself on the input dataset when called untrained.

force_train : bool

Flag whether the learner will enforce training on the input dataset upon every call.

postproc : Node instance, optional

Node to perform post-processing of results. This node is applied in __call__() to perform a final processing step on the to be result dataset. If None, nothing is done.

descr : str

Description of the instance

NeuroDebian

NITRC-listed