pyoselm.layer.RandomLayer

class pyoselm.layer.RandomLayer(n_hidden=20, alpha=0.5, random_state=None, activation_func='tanh', activation_args=None, user_components=None, rbf_width=1.0)[source]

RandomLayer is a transformer that creates a feature mapping of the inputs that corresponds to a layer of hidden units with randomly generated components.

The transformed values are a specified function of input activations that are a weighted combination of dot product (multilayer perceptron) and distance (rbf) activations:

input_activation = alpha * mlp_activation + (1-alpha) * rbf_activation

mlp_activation(x) = dot(x, weights) + bias rbf_activation(x) = rbf_width * ||x - center||/radius

alpha and rbf_width are specified by the user

weights and biases are taken from normal distribution of mean 0 and sd of 1

centers are taken uniformly from the bounding hyperrectangle of the inputs, and radii are max(||x-c||)/sqrt(n_centers*2)

The input activation is transformed by a transfer function that defaults to numpy.tanh if not specified, but can be any callable that returns an array of the same shape as its argument (the input activation array, of shape [n_samples, n_hidden]). Functions provided are ‘sine’, ‘tanh’, ‘tribas’, ‘inv_tribas’, ‘sigmoid’, ‘hardlim’, ‘softlim’, ‘gaussian’, ‘multiquadric’, or ‘inv_multiquadric’.

Parameters
  • n_hidden (int, optional (default=20)) – Number of units to generate

  • alpha (float, optional (default=0.5)) – Mixing coefficient for distance and dot product input activations: activation = alpha*mlp_activation + (1-alpha)*rbf_width*rbf_activation

  • rbf_width (float, optional (default=1.0)) – multiplier on rbf_activation

  • user_components (dictionary, optional (default=None)) –

    dictionary containing values for components that would otherwise be randomly generated. Valid key/value pairs are as follows:

    ’radii’ : array-like of shape [n_hidden] ‘centers’: array-like of shape [n_hidden, n_features] ‘biases’ : array-like of shape [n_hidden] ‘weights’: array-like of shape [n_features, n_hidden]

  • activation_func ({callable, string} optional (default='tanh')) –

    Function used to transform input activation

    It must be one of ‘tanh’, ‘sine’, ‘tribas’, ‘inv_tribas’, ‘sigmoid’, ‘hardlim’, ‘softlim’, ‘gaussian’, ‘multiquadric’, ‘inv_multiquadric’ or a callable. If None is given, ‘tanh’ will be used.

    If a callable is given, it will be used to compute the activations.

  • activation_args (dictionary, optional (default=None)) – Supplies keyword arguments for a callable activation_func

  • random_state (int, RandomState instance or None (default=None)) – Control the pseudo random number generator used to generate the hidden unit weights at fit time.

`input_activations_`

Array containing dot(x, hidden_weights) + bias for all samples

Type

numpy array of shape [n_samples, n_hidden]

`components_`

bias_weights_ : numpy array of shape [n_hidden] hidden_weights_ : numpy array of shape [n_features, n_hidden]

Type

dictionary containing two keys:

__init__(n_hidden=20, alpha=0.5, random_state=None, activation_func='tanh', activation_args=None, user_components=None, rbf_width=1.0)[source]

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

Methods

__init__([n_hidden, alpha, random_state, …])

Initialize self.

activation_func_names()

Get list of internal activation function names

fit(X[, y])

Generate a random hidden layer.

fit_transform(X[, y])

Fit to data, then transform it.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(X[, y])

Generate the random hidden layer’s activations given X as input.

classmethod activation_func_names()

Get list of internal activation function names

fit(X, y=None)

Generate a random hidden layer.

Parameters
  • X ({array-like, sparse matrix} of shape [n_samples, n_features]) – Training set: only the shape is used to generate random component values for hidden units

  • y (not used: placeholder to allow for usage in a Pipeline.) –

Returns

Return type

self

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 (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns

X_new – Transformed array.

Return type

ndarray array of shape (n_samples, n_features_new)

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

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). 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

estimator instance

transform(X, y=None)

Generate the random hidden layer’s activations given X as input.

Parameters
  • X ({array-like, sparse matrix}, shape [n_samples, n_features]) – Data to transform

  • y (not used: placeholder to allow for usage in a Pipeline.) –

Returns

X_new

Return type

numpy array of shape [n_samples, n_components]