BasePlasticity

class model._base.BasePlasticity(outputs=100, num_epochs=100, activation='Linear', optimizer=<class 'plasticity.model.optimizer.Optimizer'>, batch_size=100, weights_init=<class 'plasticity.model.weights.BaseWeights'>, precision=1e-30, epochs_for_convergency=None, convergency_atol=0.01, random_state=None, verbose=True)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

Abstract base class for plasticity models

Parameters
  • outputs (int (default=100)) – Number of hidden units

  • num_epochs (int (default=100)) – Maximum number of epochs for model convergency

  • batch_size (int (default=100)) – Size of the minibatch

  • weights_init (BaseWeights object) – Weights initialization strategy.

  • activation (str (default="Linear")) – Name of the activation function

  • optimizer (Optimizer (default=SGD)) – Optimizer object (derived by the base class Optimizer)

  • precision (float (default=1e-30)) – Parameter that controls numerical precision of the weight updates

  • epochs_for_convergency (int (default=None)) – Number of stable epochs requested for the convergency. If None the training proceeds up to the maximum number of epochs (num_epochs).

  • convergency_atol (float (default=0.01)) – Absolute tolerance requested for the convergency

  • random_state (int (default=None)) – Random seed for batch subdivisions

  • verbose (bool (default=True)) – Turn on/off the verbosity

fit(X, y=None)[source]

Fit the Plasticity model weights.

Parameters
  • X (array-like of shape (n_samples, n_features)) – The training input samples

  • y (array-like, default=None) – The array of labels

Returns

self – Return self

Return type

object

Notes

Note

The model tries to memorize the given input producing a valid encoding.

Warning

If the array of labels is provided, it will be considered as a set of new inputs for the neurons. The labels can be 1D array or multi-dimensional array: the given shape is internally reshaped according to the required dimensions.

fit_transform(X, y=None)[source]

Fit the model model meta-transformer and apply the data encoding transformation.

Parameters
  • X (array-like of shape (n_samples, n_features)) – The training input samples

  • y (array-like, shape (n_samples,)) – The target values

Returns

Xnew – The data encoded according to the model weights.

Return type

array-like of shape (n_samples, encoded_features)

Notes

Warning

If the array of labels is provided, it will be considered as a set of new inputs for the neurons. The labels can be 1D array or multi-dimensional array: the given shape is internally reshaped according to the required dimensions.

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

load_weights(filename)[source]

Load the weight matrix from a binary file.

Parameters

filename (str) – Filename or path

Returns

self – Return self

Return type

object

predict(X, y=None)[source]

Reduce X applying the Plasticity encoding.

Parameters
  • X (array of shape (n_samples, n_features)) – The input samples

  • y (array-like, default=None) – The array of labels

Returns

Xnew – The encoded features

Return type

array of shape (n_values, n_samples)

Notes

Warning

If the array of labels is provided, it will be considered as a set of new inputs for the neurons. The labels can be 1D array or multi-dimensional array: the given shape is internally reshaped according to the required dimensions.

save_weights(filename)[source]

Save the current weights to a binary file.

Parameters

filename (str) – Filename or path

Returns

Return type

True if everything is ok

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)[source]

Apply the data reduction according to the features in the best signature found.

Parameters

X (array-like of shape (n_samples, n_features)) – The input samples

Returns

Xnew – The data encoded according to the model weights.

Return type

array-like of shape (n_samples, encoded_features)