TimescaleGroup#
- class pypillometry.TimescaleGroup(models, **kwargs)[source]#
Bases:
objectGroup of recordings whose timescale models are estimated together (experimental).
The parameters of the recordings are treated as draws from a normal distribution with a group mean and a (diagonal) covariance, which are estimated together with the parameters of each recording (empirical Bayes, see
pypillometry.signal.gaussmarkov.hierarchical). The group mean is the typical mix of time scales; the estimate of each recording is shrunk towards it where the recording itself is uninformative (the variance of single atoms), and stays where the data determine it (the fast component, the noise, the total slow variance).- Parameters:
models (dict or list) – the recordings:
TimescaleModelobjects, orEyeDataobjects, from which models are made with **kwargs. The keys of a dict are the names of the recordings (for a list: the names of the objects). All models need the same structure (time scales, binocular or not).**kwargs – arguments of
TimescaleModelfor the EyeData objects (e.g.,eyes="left",binocular=True)
- Attributes:
- modelsdict
name ->
TimescaleModel. Afterfit(), their estimates are the shrunk ones (model.fits) and the estimates without pooling are inmodel.individual.- bankTimescaleBank
the common structure
Notes
Every unit of every model (each eye of each recording, unless the models are binocular or use one eye) counts as one independent member of the group.
Examples
>>> g = pp.TimescaleGroup({"s1": d1, "s2": d2, "s3": d3}, eyes="left") >>> g.fit() >>> g.group_summary() >>> g.models["s1"].plot.decomposition() >>> new = pp.TimescaleModel(d4, eyes="left").fit(prior=g.prior)
Methods
Estimate the group distribution and the parameters of all recordings.
Group from files that are read one at a time, so that only the reduced data of each recording stay in memory.
Table of the group distribution.
Table of the estimates of all recordings.
Details
- classmethod from_files(files, preprocess=None, **kwargs)[source]#
Group from files that are read one at a time, so that only the reduced data of each recording stay in memory.
- Parameters:
files (dict or list of str) – the files (read with
read_file()); the keys of a dict are the names of the recordings (for a list: the file names without directory and extension)preprocess (callable, optional) – function that takes the
EyeDataobject of a file and returns the object to model, e.g. with blinks detected and the periods outside the task excluded**kwargs – arguments of
TimescaleModel
- Return type:
- Returns:
its models keep no reference to the data; pass the data to
TimescaleModel.interpolate()andTimescaleModel.store()
- fit(n_iter=5, tol=0.01, cov='diag', n_jobs=None)[source]#
Estimate the group distribution and the parameters of all recordings.
- Parameters:
n_iter (int) – maximum number of iterations (default 5)
tol (float) – stop when the group mean changes by less than this
cov ({"diag", "full"}) – covariance of the parameters between recordings: independent (default) or with correlations (for large groups)
n_jobs (int, optional) – number of parallel processes (see
fit_group()); None (default): all cores but one; negative as in joblib (-1: all cores)
- Return type:
- Returns:
the group itself (fitted)
Notes
Each iteration fits every recording once (about a minute per 20 minutes of data and process).
- group_summary()[source]#
Table of the group distribution.
- Return type:
- Returns:
one row per parameter:
meanandsdof the entries of the parameter vector (logs, and \(u = \log(v + v_0)\) for the atoms) andtypical,lowandhigh: the group mean and the mean minus/plus one standard deviation on the natural scale (standard deviations in log-%, length scales in ms)
- summary(cutoff='10 s', individual=False)[source]#
Table of the estimates of all recordings.
- Parameters:
- Return type:
- Returns:
one row per recording and unit (see
TimescaleModel.summary())
- property plot: TimescaleGroupPlots#
plots of the group (
TimescaleGroupPlots)
- property prior: GaussianPrior#
The group distribution as a prior for the fit of other recordings of the same kind,
TimescaleModel(d).fit(prior=g.prior).