TransientAnalyzer package

Submodules

TransientAnalyzer.EMOneDimGaussian module

class TransientAnalyzer.EMOneDimGaussian.EMOneDimGaussian(n_gaussians=2)

Bases: object

EMOneDimGaussian is the implementation of EM algorithm for parameters estimation of 1D Gaussian Mixture model. See Sridharan, R. 2014. Gaussian mixture models and the EM algorithm for more details.

__init__(n_gaussians=2)
Parameters

n_gaussians (int) – number of gaussians

fit(Y)
Parameters

Y (array-like) – 1D numpy array of values used for MLE

fit_predict(Y)

Does fitting and prediction sequentially using Y

Parameters

Y (array-like) – 1D numpy array of values to be classified

Returns

Array containing cluster assignments for each point in X

Return type

array-like

predict(Y)

Assign each data point to the Gaussian with the highest posterior probability.

Parameters

Y (array-like) – 1D numpy array of values to be classified

Returns

Array containing cluster assignments for each point in X

Return type

array-like

TransientAnalyzer.LinearGibbs module

class TransientAnalyzer.LinearGibbs.LinearGibbs(B_min=1e-06)

Bases: Kernel

LinearGibbs is the GPflow based implementation of Gibbs kernel with the variable lengthscale which changes linearly.

\[k(x, y) = C \sqrt{\frac{2l(x) l(y)}{l(x)^2+l(y)^2}} e^{-\frac{(x-y)^2}{l(x)^2+l(y)^2}}, l(x) = Ax + B\]

The kernel is applicable only to one-dimensional problems.

K(X, Y=None)

K is the covariance matrix

Parameters
  • X (Tensor) – X

  • Y (Tensor, optional) – Y, defaults to None

Returns

covariance matrix K(X,Y), or K(X,X) if Y = None

Return type

Tensor

K_diag(X)

K_diag is the diagonal of kernel K

Parameters

X (Tensor) – X

Returns

Diagonal of kernel

Return type

Tensor

__init__(B_min=1e-06)
Parameters

B_min (float) – minimum value of lengthscale intercept. Defaults to 1e-6

TransientAnalyzer.TransientAnalyzer module

class TransientAnalyzer.TransientAnalyzer.TransientAnalyzer(time, Sig, start_gradient=0, kernel='Gibbs', window_size=20, window_size2=0, prominence=1, t_stim=None, detrend=False, alpha_mult=1, beta=0.25, shift=0, quantile1=0.1, quantile2=0.2, is_fall=None)

Bases: object

The Class of TransientAnalyzer is used to analyze transient signals (calcium transients, spikes, sparks, contractions, etc.).

This class can robustly analyze individual noisy signals. TransientAnalyzer is based on the Gaussian process with the Linear Gibbs kernel of the covariance matrix. The class takes Numpy Arrays of time and signals as input. TransientAnalyser includes automatic detection of the starting points of the transients, approximation of transient using Gaussian process regression (GPR) and determination of signal parameters describing amplitude and kinetics of individual transients. Automatic detection can be superseded by the input of stimulus time points as Numpy array.

There are two parameters which regulate detection of onset times: window_size (default to 20) and prominence(defaults to 1) that can improve the detection of starting point in case of problems. In case of wrong detection of starting point (some kind of displacement) change the window_size. If the number of detection transients is higher (lower) than it actually is (it can be in case of the high noise), decrease (or increase) the prominence. There is also possibility to provide stimuli times (t_stim parameter) instead of automatic detection.

GPR is a type of Bayesian Regression with the prior distribution being a multivariate Gaussian distribution with an arbitrary mean (usually set to 0) and a total N-dimensional covariance matrix K with the elements:

\[K(x, y) = k(x, y)+ \sigma^2 \delta(x, y),\]

where k(x, y) is the covariance matrix, σ is the noise amplitude and δ(x,y) is the Kronecker delta.

Considering the Bayesian framework the aim is to find the posterior distribution, i.e.the prior multivariate Gaussian distribution conditioned on the observed data. The covariance matrix k(x, y) defines the mutual relationship between all points of the true signal.

Since transients signals are non-stationary processes that most often have a fast rise and a slower decay, the kernel of GP being used is LinearGibbs

The class provides the following parameters:
  • Baseline;

  • Amplitude;

  • Rise time at percentiles (x-(100-x)%) defined by user (20-80%, 10-90%, etc.);

  • Time-to-peak (TTP);

  • FDHM - Full Duration at Half Maximum

  • Decay time at percentiles ((100-x)-x%) defined by user (80-20%, 90-10%, etc.);

  • Transients durations at percentiles (100-x%) defined by user (80%, 90%, etc.);

FitAllTransients(disp=False)

FitAllTransients fits transients

Parameters

disp (bool, optional) – shows the progress of transients, defaults to False

GetAllExpTransients()

GetAllExpTransients allows to see all transients which should be analysed

Returns

array of experimental transients and time

Return type

array

GetApproxTransient(idx, dt)

GetApproxTransient provides the approximated transient with the sampling rate provided by the user. Raises error when no approximation was done

Parameters
  • idx (int) – index of transient

  • dt (float) – time step of the approximation transient

Returns

time and transients arrays

Return type

array-like, array-like and array-like or None

GetExpTransient(idx, output=True)

GetExpTransient allows to see one of experimental transients

Parameters
  • idx – index of the signal

  • output – defines whether the baseline of the transient is also provided in the signal array, applies only to the first transient, defaults to True

Returns

two 1-d arrays, which contain time and signal

Return type

array-like, array-like and array-like or None

GetParametersTable(x_label='x', y_label='y')

GetParametersTable allows to get the table with parameters. Table of parameters contains values of t0 - the start time of the transient or of the stimulus, delta t0 - the difference in t0 between two neighboring transients and Delay - the difference between stimulus time and the start of the transient.

param x_label

name of x axis

type x_label

str

param y_label

name of y axis

type y_label

str

return

the table with parameters

rtype

pandas DataFrame

GetTransientsTable(x_label='x', y_label='y')

GetTransientsTable provides the table with the input and approximated traces

Parameters
  • x_label (str) – name of x axis

  • y_label (str) – name of y axis

Returns

Table with the transients

Return type

DataFrame

ParametersToExcel(filename, x_label='x', y_label='y')

ParametersToExcel saves parameters to an excel file

Parameters
  • x_label (str) – name of x axis

  • y_label (str) – name of y axis

  • filename (string) – name of the file which you want to save

SetProminence(value)

SetProminence allows to change the parameter prominence that measures how much a peak stands out from the surrounding baseline

Parameters

value (int) – prominence

SetWindowSize(value)

SetWindowSize changes window size of box filter window

Parameters

value (int) – window size of the box filter

__init__(time, Sig, start_gradient=0, kernel='Gibbs', window_size=20, window_size2=0, prominence=1, t_stim=None, detrend=False, alpha_mult=1, beta=0.25, shift=0, quantile1=0.1, quantile2=0.2, is_fall=None)
Parameters
  • time (array_like) – array of the values of the time during contraction

  • Sig (array_like) – array of the values of the transients

  • start_gradient (float, optional) – starting point for the heavy ball algorithm used for the transient’s start detection

  • kernel (str, optional) – kernel used for analyze, can be chosen between RBF and Gibbs, defaults to “Gibbs”

  • window_size (int, optional) – size of box filter window for transients start detection, can be modified in case of the bad detection of transients start, defaults to 20

  • window_size2 (float, optional) – size of box filter window for smoothing transient in order to detect the transients start. The values less or equal to zero mean no usage of the filter. defaults to 0

  • prominence (float, optional) – measures how much a peak stands out from the surrounding baseline, can be used when no or extra transients are detected, defaults to 1

  • t_stim (array_like, optional) – stimulation times, defaults to None

  • detrend (bool) – defines whether to detrend the data or not, defaults to False

  • alpha_mult (float) – defines the multiplier of learning rate, important to change if the estimated t0 goes to infinitively large values, defaults to 1

  • beta (float) – “inertion” parameter used in transients start detection, defaults to 0.25

  • shift (int) – shift(in data points) to the left so that the estimated starting time is before the actual start of transient

  • quantile1 (float) – the first quantile for parameters of transients, will be used for the detection of rise,decay times and durations as the ones between quantile1 and 1 - quantile1 percents of the corresponding transient phase, defaults to 0.1

  • quantile2 (float) – the second quantile for parameters of transients, will be used for the detection of rise,decay times and durations as the ones between quantile1 and 1 - quantile1 percents of the corresponding transient phase, defaults to 0.2

  • is_fall (bool) – defines whether the transients are falling or not. If the parameter is None, it will be defined automatically by the gaussian mixture model. Defaults to None

Module contents