TfELM
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
KELMLayer.KELMLayer Class Reference

Public Member Functions

 __init__ (self, Kernel kernel, activation='tanh', act_params=None, C=1.0, nystrom_approximation=False, landmark_selection_method='random', **params)
 
 build (self, input_shape)
 
 fit (self, x, y)
 
 predict (self, x)
 
 predict_proba (self, x)
 
 calc_output (self, x)
 
 __str__ (self)
 
 count_params (self)
 
 to_dict (self)
 
 load (cls, attributes)
 

Public Attributes

 K
 
 error_history
 
 feature_map
 
 name
 
 beta
 
 input
 
 output
 
 nystrom_approximation
 
 landmark_selection_method
 
 activation
 
 C
 
 denoising
 
 denoising_param
 
 kernel
 

Detailed Description

    Kernel Extreme Learning Machine (KELM) Layer.

    This class implements a single layer of the Kernel Extreme Learning Machine.

    Parameters:
    -----------
        kernel (object): Instance of a kernel function.
        activation (str, optional): Name of the activation function. Defaults to 'tanh'.
        act_params (dict, optional): Parameters for the activation function.
        C (float, optional): Regularization parameter. Defaults to 1.0.
        nystrom_approximation (bool, optional): Whether to use Nystrom approximation for large datasets.
            Defaults to False.
        landmark_selection_method (str, optional): Method for landmark selection if using Nystrom approximation.
            Defaults to 'random'.

    Attributes:
    -----------
        K (tensor): Kernel matrix.
        error_history (list): History of errors during training.
        feature_map (tensor): Feature map.
        name (str): Name of the layer.
        beta (tensor): Weights of the layer.
        input (tensor): Input data.
        output (tensor): Output data.
        nystrom_approximation (bool): Indicates whether Nystrom approximation is used.
        landmark_selection_method (str): Method for landmark selection.
        activation (function): Activation function.
        C (float): Regularization parameter.
        kernel (object): Instance of a kernel function.
        denoising (str, optional): Denoising method. Defaults to None.
        denoising_param (float, optional): Denoising parameter. Defaults to None.

    Methods:
    -----------
        build(input_shape): Build the layer with the given input shape.
        fit(x, y): Fit the layer to the input-output pairs.
        predict(x): Predict the output for the input data.
        predict_proba(x): Predict class probabilities for the input data.
        calc_output(x): Calculate the output for the input data.
        count_params(): Count the number of trainable and non-trainable parameters.
        to_dict(): Convert the layer attributes to a dictionary.
        load(attributes): Load the layer from a dictionary of attributes.

    Examples:
    -----------
    Initialize a Kernel (it can be instanced as Kernel class and its subclasses like CombinedProductKernel)

    >>> kernel = CombinedProductKernel([Kernel("rational_quadratic"), Kernel("exponential")])

    Initialize a Kernel Extreme Learning Machine (KELM) layer

    >>> layer = KELMLayer(kernel, 'mish')

    Initialize a Kernel Extreme Learning Machine (KELM) layer with Nystrom kernel matrix approximation

    >>> layer = KELMLayer(kernel, 'mish', nystrom_approximation=True)

    Initialize a Kernel Extreme Learning Machine (KELM) model

    >>> model = KELMModel(layer)

Member Function Documentation

◆ build()

KELMLayer.KELMLayer.build ( self,
input_shape )
    Build the layer with the given input shape.

    This method initializes the layer by creating a kernel matrix placeholder
    of appropriate dimensions based on the input shape.

    Args:
    -----------
        input_shape (tuple): Shape of the input data.

    Example:
    -----------
        >>> kelm = KELMLayer(number_neurons=1000, activation='mish')
        >>> kelm.build(x.shape)

◆ calc_output()

KELMLayer.KELMLayer.calc_output ( self,
x )
    Calculate the output for the input data.

    This method calculates the output for the given input data.

    Args:
    -----------
        x (tensor): Input data.

    Returns:
    -----------
        tensor: Calculated output.

◆ count_params()

KELMLayer.KELMLayer.count_params ( self)
    Count the number of trainable and non-trainable parameters.

    This method counts the number of trainable and non-trainable parameters
    in the layer.

    Returns:
    -----------
        dict: Dictionary containing the counts of trainable, non-trainable,
            and total parameters.

◆ fit()

KELMLayer.KELMLayer.fit ( self,
x,
y )
    Fit the layer to the input-output pairs.

    This method fits the layer to the given input-output pairs by calculating
    the kernel matrix, applying regularization, and computing the weights.

    Args:
    -----------
        x (tensor): Input data.
        y (tensor): Target values.

    Example:
    -----------
        >>> kelm = KELMLayer(number_neurons=1000, activation='mish')
        >>> kelm.build(x.shape)
        >>> kelm.fit(train_data, train_targets)

◆ load()

KELMLayer.KELMLayer.load ( cls,
attributes )
    Load the layer from a dictionary of attributes.

    This class method loads the layer from a dictionary of attributes.

    Args:
    -----------
        attributes (dict): Dictionary containing the layer attributes.

    Returns:
    -----------
        object: Instance of the loaded layer.

◆ predict()

KELMLayer.KELMLayer.predict ( self,
x )
    Predict the output for the input data.

    This method predicts the output for the given input data.

    Args:
    -----------
        x (tensor): Input data.

    Returns:
    -----------
        tensor: Predicted output.

    Example:
    -----------
        >>> kelm = KELMLayer(number_neurons=1000, activation='mish')
        >>> kelm.build(x.shape)
        >>> kelm.fit(train_data, train_targets)
        >>> pred = kelm.predict(test_data)

◆ predict_proba()

KELMLayer.KELMLayer.predict_proba ( self,
x )
    Predict class probabilities for the input data.

    This method predicts class probabilities for the given input data.

    Args:
    -----------
        x (tensor): Input data.

    Returns:
    -----------
        numpy.ndarray: Predicted class probabilities.

    Example:
    -----------
    >>> elm = ELMLayer(number_neurons=1000, activation='mish')
    >>> elm.build(x.shape)
    >>> elm.fit(train_data, train_targets)
    >>> pred = elm.predict_proba(test_data)

◆ to_dict()

KELMLayer.KELMLayer.to_dict ( self)
    Convert the layer attributes to a dictionary.

    This method converts the layer's attributes to a dictionary.

    Returns:
    -----------
        dict: Dictionary containing the layer attributes.

The documentation for this class was generated from the following file: