NeuralNetwork class

Neural Network class

Constructor parameters

  • inputLenght - Lenght of the input data List
  • layers - List of Layer with lenght >= 1
  • loss - Loss function to minimize
  • optimizer - optional parameter, Optimizer for the NeuralNetwork
  • name - optional parameter, name of the NeuralNetwork
  • useAccuracyMetric - optional parameter, add accuracy metric computation while fitting (learning) or evaluating (testing). Can be used only for classsification tasks, with both One-Hot encoded and labeled target class representation.

Example

NeuralNetwork nnClasses = NeuralNetwork(784, // input length of 28 by 28 image
  [
    LayerNormalization(), // preprocess normalization of data records
    Dense(128, activation: Activation.elu()), // 1st hidden layer
    Dense(32, activation: Activation.leakyReLU()), // 2nd hidden layer
    // ...
    LayerNormalization(),
    Dense(10, activation: Activation.softmax()) // output layer for ten classes
  ],
  loss: Loss.mse(), /// for sparse can be [Loss.sparseCrossEntropy()]
  optimizer: SGD(learningRate: 0.05, momentum: 0.99),
  useAccuracyMetric: true) /// set [true] to compute classififcation accuracy

NeuralNetwork nnRegression = NeuralNetwork(10, // input length of customer features
  [
    Dense(32, activation: Activation.elu()), // hidden layer
    LayerNormalization()
    Dense(1, activation: Activation.softmax()) // output layer
  ],
  loss: Loss.mae(),
  optimizer: SGD(learningRate: 0.3, momentum: 0),
  useAccuracyMetric: false) /// use [false] for regression tasks

Constructors

NeuralNetwork(int inputLength, List<Layer> layers, {required Loss loss, Optimizer? optimizer, String? name, bool useAccuracyMetric = false})
  • inputLenght - Lenght of the input data List
  • layers - List of Layer with lenght >= 1
  • loss - Loss function to minimize
  • optimizer - optional parameter, Optimizer for the NeuralNetwork
  • name - optional parameter, name of the NeuralNetwork
  • useAccuracyMetric - optional parameter, add accuracy metric computation while fitting (learning) or evaluating (testing). Can be used only for classsification tasks, with both One-Hot encoded and labeled target class representation.
  • Properties

    hashCode int
    The hash code for this object.
    no setterinherited
    layers List<Layer>
    getter/setter pair
    loss Loss
    getter/setter pair
    name String
    getter/setter pair
    optimizer ↔ Optimizer
    getter/setter pair
    runtimeType Type
    A representation of the runtime type of the object.
    no setterinherited

    Methods

    evaluate(List<List<double>> x, List<List<double>> y, {int batchSize = 1, bool verbose = true}) Map<String, double>
    Call evaluating or testing process of this NeuralNetwork on the given batches
    fit(List<List<double>> x, List<List<double>> y, {int epochs = 1, int batchSize = 1, bool verbose = false}) Map<String, List<double>>?
    Call trainig (or fitting) process of this NeuralNetwork over given x and y
    loadWeights(String path, [SaveType type = SaveType.bin]) → void
    Load weights and biases of trainable layers of this NeuralNetwork from the $path/model_weights.bin file
    loadWeightsFromBytes(ByteBuffer buffer) → void
    Load weights and biases of trainable layers of this NeuralNetwork from buffer
    noSuchMethod(Invocation invocation) → dynamic
    Invoked when a nonexistent method or property is accessed.
    inherited
    predict(List<List<double>> inputs) List<List<double>>
    Call prediction process for this NeuralNetwork on the given input data
    saveWeights(String path, [SaveType type = SaveType.bin]) → void
    Save weights and biases of trainable layers of this NeuralNetwork to the $path/model_weights.bin file
    toString() String
    A string representation of this object.
    override

    Operators

    operator ==(Object other) bool
    The equality operator.
    inherited