org.apache.ignite.ml.nn

## Class MultilayerPerceptron

- java.lang.Object
- - org.apache.ignite.ml.nn.MultilayerPerceptron

- All Implemented Interfaces:
    Serializable, AutoCloseable, IgniteModel<Matrix,Matrix>, Model<Matrix,Matrix>, Parametrized<MultilayerPerceptron>, SmoothParametrized<MultilayerPerceptron>

      public final class MultilayerPerceptron
      extends Object
      implements SmoothParametrized<MultilayerPerceptron>

  Class encapsulating logic of multilayer perceptron.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MultilayerPerceptron(MLPArchitecture arch)` Construct MLP from given architecture.
    `MultilayerPerceptron(MLPArchitecture arch, MLPInitializer initializer)` Construct MLP from given architecture and parameters initializer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `MultilayerPerceptron` | `add(MultilayerPerceptron above)` Create MLP where this MLP output is fed as input to added MLP.
    `MLPArchitecture` | `architecture()` Get architecture of this MLP.
    `double` | `bias(int layerIdx, int neuronIdx)` Get the bias of given neuron in given layer.
    `Vector` | `biases(int layerIdx)` Get biases of layer with given index.
    `MLPState` | `computeState(Matrix val)` Perform forward pass and return state of outputs of each layer.
    `Vector` | `differentiateByParameters(IgniteFunction<Vector,IgniteDifferentiableVectorToDoubleFunction> loss, Matrix inputsBatch, Matrix truthBatch)` Compose function in the following way: feed output of this model as input to second argument to loss function.
    `Matrix` | `forwardPass(Matrix val, MLPState state, boolean writeState)` Perform forward pass and if needed write state of outputs of each layer.
    `boolean` | `hasBiases(int layerIdx)` Checks if layer with given index has biases.
    `int` | `layersCount()` Get count of layers in this MLP.
    `Vector` | `parameters()` Get parameters vector.
    `int` | `parametersCount()` Get count of parameters of this model.
    `Matrix` | `predict(Matrix val)` Makes a prediction for the given objects.
    `MultilayerPerceptron` | `setBias(int layerIdx, int neuronIdx, double val)` Set the bias of given neuron in given layer.
    `MultilayerPerceptron` | `setBiases(int layerIdx, Vector bias)` Sets the biases of layer with a given index.
    `MultilayerPerceptron` | `setParameters(Vector vector)` Set parameters.
    `MultilayerPerceptron` | `setWeight(int layerIdx, int fromNeuron, int toNeuron, double val)` Set the weight of neuron with given index in previous layer to neuron with given index in given layer.
    `MultilayerPerceptron` | `setWeights(int layerIdx, Matrix weights)` Sets the weighs of layer with a given index.
    `String` | `toString()`
    `String` | `toString(boolean pretty)`
    `double` | `weight(int layerIdx, int fromNeuron, int toNeuron)` Get the weight of neuron with given index in previous layer to neuron with given index in given layer.
    `Matrix` | `weights(int layerIdx)` Get weights of layer with given index.
    `default M` | `withParameters(Vector vector)` Return new model with given parameters vector.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.ignite.ml.IgniteModel

      `andBefore, andThen, andThen, close, combine`

- - ### Constructor Detail

    - #### MultilayerPerceptron

          public MultilayerPerceptron(MLPArchitecture arch,
                                      MLPInitializer initializer)

      Construct MLP from given architecture and parameters initializer.
      Parameters:
        `arch` - Architecture.
        `initializer` - Parameters initializer.

    - #### MultilayerPerceptron

          public MultilayerPerceptron(MLPArchitecture arch)

      Construct MLP from given architecture.
      Parameters:
        `arch` - Architecture.

  - ### Method Detail

    - #### computeState

          public MLPState computeState(Matrix val)

      Perform forward pass and return state of outputs of each layer.
      Parameters:
        `val` - Value to perform computation on.
      Returns:
        MLP state after computation.

    - #### forwardPass

          public Matrix forwardPass(Matrix val,
                                    MLPState state,
                                    boolean writeState)

      Perform forward pass and if needed write state of outputs of each layer.
      Parameters:
        `val` - Value to perform computation on.
        `state` - State object to write state into.
        `writeState` - Flag indicating need to write state.

    - #### predict

          public Matrix predict(Matrix val)

      Makes a prediction for the given objects.
      Specified by:
        `predict` in interface `Model<Matrix,Matrix>`
      Parameters:
        `val` - Matrix containing objects.
      Returns:
        Matrix with predicted vectors.

    - #### add

          public MultilayerPerceptron add(MultilayerPerceptron above)

      Create MLP where this MLP output is fed as input to added MLP.
      Parameters:
        `above` - Added MLP.
      Returns:
        New MLP where this MLP output is fed as input to added MLP.

    - #### weights

          public Matrix weights(int layerIdx)

      Get weights of layer with given index. Proper indexes are in [1, layersCount).
      Parameters:
        `layerIdx` - Layer index.
      Returns:
        Weights of layer with given index.

    - #### biases

          public Vector biases(int layerIdx)

      Get biases of layer with given index. Proper indexes are in [1, layersCount).
      Parameters:
        `layerIdx` - Layer index.
      Returns:
        Biases of layer with given index.

    - #### hasBiases

          public boolean hasBiases(int layerIdx)

      Checks if layer with given index has biases.
      Parameters:
        `layerIdx` - Layer index.
      Returns:
        Value of predicate 'layer with layerIdx has biases'.

    - #### setBiases

          public MultilayerPerceptron setBiases(int layerIdx,
                                                Vector bias)

      Sets the biases of layer with a given index.
      Parameters:
        `layerIdx` - Layer index.
        `bias` - New values for biases.
      Returns:
        This MLP with updated biases.

    - #### setBias

          public MultilayerPerceptron setBias(int layerIdx,
                                              int neuronIdx,
                                              double val)

      Set the bias of given neuron in given layer.
      Parameters:
        `layerIdx` - Layer index.
        `neuronIdx` - Neuron index.
        `val` - New value of bias.
      Returns:
        This MLP with updated biases.

    - #### bias

          public double bias(int layerIdx,
                             int neuronIdx)

      Get the bias of given neuron in given layer.
      Parameters:
        `layerIdx` - Layer index.
        `neuronIdx` - Neuron index.
      Returns:
        Bias with specified coordinates.

    - #### setWeights

          public MultilayerPerceptron setWeights(int layerIdx,
                                                 Matrix weights)

      Sets the weighs of layer with a given index.
      Parameters:
        `layerIdx` - Layer index.
        `weights` - New values for weights.
      Returns:
        This MLP with updated weights.

    - #### setWeight

          public MultilayerPerceptron setWeight(int layerIdx,
                                                int fromNeuron,
                                                int toNeuron,
                                                double val)

      Set the weight of neuron with given index in previous layer to neuron with given index in given layer.
      Parameters:
        `layerIdx` - Layer index.
        `fromNeuron` - Neuron index in previous layer.
        `toNeuron` - Neuron index in current layer.
        `val` - New value of weight.
      Returns:
        This MLP with updated weights.

    - #### weight

          public double weight(int layerIdx,
                               int fromNeuron,
                               int toNeuron)

      Get the weight of neuron with given index in previous layer to neuron with given index in given layer.
      Parameters:
        `layerIdx` - Layer index.
        `fromNeuron` - Neuron index in previous layer.
        `toNeuron` - Neuron index in current layer.
      Returns:
        Weight with specified coordinates.

    - #### layersCount

          public int layersCount()

      Get count of layers in this MLP.
      Returns:
        Count of layers in this MLP.

    - #### architecture

          public MLPArchitecture architecture()

      Get architecture of this MLP.
      Returns:
        Architecture of this MLP.

    - #### differentiateByParameters

          public Vector differentiateByParameters(IgniteFunction<Vector,IgniteDifferentiableVectorToDoubleFunction> loss,
                                                  Matrix inputsBatch,
                                                  Matrix truthBatch)

      Compose function in the following way: feed output of this model as input to second argument to loss function. After that we have a function g of three arguments: input, ground truth, parameters. If we consider function h(w) = 1 / M sum_{i=1}^{M} g(w, input_i, groundTruth_i), where M is number of entries in batch, we get function of one argument: parameters vector w. This function is being differentiated.
      Specified by:
        `differentiateByParameters` in interface `SmoothParametrized<MultilayerPerceptron>`
      Parameters:
        `loss` - Loss function.
        `inputsBatch` - Batch of inputs.
        `truthBatch` - Batch of ground truths.
      Returns:
        Gradient of h at current point in parameters space.

    - #### parameters

          public Vector parameters()

      Get parameters vector.
      Returns:
        Parameters vector.

    - #### setParameters

          public MultilayerPerceptron setParameters(Vector vector)

      Set parameters.
      Parameters:
        `vector` - Parameters vector.

    - #### parametersCount

          public int parametersCount()

      Get count of parameters of this model.
      Returns:
        Count of parameters of this model.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toString

          public String toString(boolean pretty)

      Specified by:
        `toString` in interface `IgniteModel<Matrix,Matrix>`
      Parameters:
        `pretty` - Use pretty mode.

    - #### withParameters

          public M withParameters(Vector vector)

      Return new model with given parameters vector.
      Parameters:
        `vector` - Parameters vector.

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.11.0
Release Date | : September 11 2021