Importing Data

mrestimator.input_handler(items, **kwargs)[source]

Helper function that attempts to detect provided input and convert it to the format used by the toolbox. Ideally, you provide the native format, a numpy.ndarray of shape(numtrials, datalength).

Not implemented yet: All trials should have the same data length, otherwise they will be padded.

The toolbox uses two dimensional ndarrays for providing the data to/from functions. This allows to consistently access trials and data via the first and second index, respectively.

Parameters:
  • items (str, list or ndarray) – A string is assumed to be the path to file that is then imported as pickle or plain text. Wildcards should work. Alternatively, you can provide a list or ndarray containing strings or already imported data. In the latter case, input_handler attempts to convert it to the right format.
  • kwargs – Keyword arguments passed to numpy.loadtxt() when filenames are detected (see numpy documentation for a full list). For instance, you can provide usecols=(1,2) if your files have multiple columns and only the column 1 and 2 contain trial data you want to use. The input handler adds each column in each file to the list of trials.
Returns:

ndarray – containing your data (hopefully) formatted correctly. Access via [trial, datapoint]

Example

# import a single file
prepared = mre.input_handler('/path/to/yourfiles/trial_1.csv')
print(prepared.shape)

# or from a list of files
myfiles = ['~/data/file_0.csv', '~/data/file_1.csv']
prepared = mre.input_handler(myfiles)

# all files matching the wildcard, but only columns 3 and 4
prepared = mre.input_handler('~/data/file_*.csv', usecols=(3, 4))

# access your data, e.g. measurement 10 of trial 3
pt = prepared[3, 10]
mrestimator.simulate_branching(m, a=None, h=None, length=10000, numtrials=1, subp=1, seed='random')[source]

Simulates a branching process with Poisson input. Returns data in the trial structure.

Per default, the function discards the first few time steps to produce stationary activity. If a drive is passed as h=0, the recording starts instantly (and produces exponentially decaying activity).

Parameters:
  • m (float) – Branching parameter.
  • a (float) – Stationarity activity of the process. Only considered if no drive h is specified.
  • h (array, optional) – Specify a custom drive (possibly changing) for every time step. If h is given, its length takes priority over the length parameter. If the first or only value of h is zero, the recording starts instantly with set activity a and the resulting timeseries will not be stationary in the beginning.
  • length (int, optional) – Number of steps for the process, thereby sets the total length of the generated time series. Overwritten if drive h is set as an array.
  • numtrials (int, optional) – Generate ‘numtrials’ trials. Default is 1.
  • seed (int, optional) – Initialise the random number generator with a seed. Per default, seed='random' and the generator is seeded randomly (hence each call to simulate_branching() returns different results). seed=None skips (re)seeding.
  • subp (float, optional) – Subsample the activity with the probability subp (calls simulate_subsampling() before returning).
Returns:

ndarray – with numtrials time series, each containging length entries of activity. Per default, one trial is created with 10000 measurements.

mrestimator.simulate_subsampling(data, prob=0.1, seed='random')[source]

Apply binomial subsampling.

Parameters:
  • data (ndarray) – Data (in trial structre) to subsample. Note that data will be cast to integers. For instance, if your activity is normalised consider multiplying with a constant.
  • prob (float) – Subsample to probability prob. Default is 0.1.
  • seed (int, optional) – Initialise the random number generator with a seed. Per default set to random: seed randomly (hence each call to simulate_branching() returns different results). Set seed=None to keep the rng device state.