Derivative

class gtda.curves.Derivative(order=1, n_jobs=None)[source]

Derivatives of multi-channel curves.

A multi-channel (integer sampled) curve is a 2D array of shape (n_channels, n_bins), where each row represents the y-values in one of the channels. This transformer computes the n-th order derivative of each channel in each multi-channel curve in a collection, by discrete differences. The output is another collection of multi-channel curves.

Parameters
  • order (int, optional, default: 1) – Order of the derivative to be taken.

  • n_jobs (int or None, optional, default: None) – The number of jobs to use for the computation. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

n_channels_

Number of channels present in the 3D array passed to fit.

Type

int

__init__(order=1, n_jobs=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(X, y=None)[source]

Compute n_channels_. Then, return the estimator.

This function is here to implement the usual scikit-learn API and hence work in pipelines.

Parameters
  • X (ndarray of shape (n_samples, n_channels, n_bins)) – Input data. Collection of multi-channel curves.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

self

Return type

object

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
  • X (ndarray of shape (n_samples, n_channels, n_bins)) – Input data. Collection of multi-channel curves.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

Xt – Output collection of multi-channel curves given by taking discrete differences of order order in each channel in the curves in X.

Return type

ndarray of shape (n_samples, n_channels, n_bins - order)

fit_transform_plot(X, y=None, sample=0, **plot_params)

Fit to data, then apply transform_plot.

Parameters
  • X (ndarray of shape (n_samples, ..)) – Input data.

  • y (ndarray of shape (n_samples,) or None) – Target values for supervised problems.

  • sample (int) – Sample to be plotted.

  • **plot_params – Optional plotting parameters.

Returns

Xt – Transformed one-sample slice from the input.

Return type

ndarray of shape (1, ..)

get_params(deep=True)

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

plot(Xt, sample=0, channels=None, plotly_params=None)[source]

Plot a sample from a collection of derivatives of multi-channel curves arranged as in the output of transform.

Parameters
  • Xt (ndarray of shape (n_samples, n_channels, n_bins)) – Collection of multi-channel curves, such as returned by transform.

  • sample (int, optional, default: 0) – Index of the sample in Xt to be plotted.

  • channels (list, tuple or None, optional, default: None) – Which channels to include in the plot. None means plotting the first n_channels_ channels.

  • plotly_params (dict or None, optional, default: None) – Custom parameters to configure the plotly figure. Allowed keys are "traces" and "layout", and the corresponding values should be dictionaries containing keyword arguments as would be fed to the update_traces and update_layout methods of plotly.graph_objects.Figure.

Returns

fig – Plotly figure.

Return type

plotly.graph_objects.Figure object

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

object

transform(X, y=None)[source]

Compute derivatives of multi-channel curves.

Parameters
  • X (ndarray of shape (n_samples, n_channels, n_bins)) – Input collection of multi-channel curves.

  • y (None) – There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns

Xt – Output collection of multi-channel curves given by taking discrete differences of order order in each channel in the curves in X.

Return type

ndarray of shape (n_samples, n_channels, n_bins - order)

transform_plot(X, sample=0, **plot_params)

Take a one-sample slice from the input collection and transform it. Before returning the transformed object, plot the transformed sample.

Parameters
  • X (ndarray of shape (n_samples, ..)) – Input data.

  • sample (int) – Sample to be plotted.

  • **plot_params – Optional plotting parameters.

Returns

Xt – Transformed one-sample slice from the input.

Return type

ndarray of shape (1, ..)