train method

void train({
  1. required List<List<double>> inputs,
  2. required List<List<double>> expected,
  3. required int iterations,
  4. @Deprecated('The package no longer logs messages, thus the quiet mode no longer ' 'serves a purpose.') bool quiet = false,
})
inherited

Trains the network using the passed inputs, their respective expected results, as well as the number of iterations to make during training.

inputs - The values we pass into the Network.

expected - What we expect the Network to output.

iterations - How many times the Network should perform backpropagation using the provided inputs and expected values.

⚠️ Throws a FormatException if the:

  • The inputs and expected vectors are empty.
  • The inputs and expected vectors are of different sizes.
  • The number of iterations is less than 1.

Implementation

void train({
  required List<List<double>> inputs,
  required List<List<double>> expected,
  required int iterations,
  @Deprecated(
    'The package no longer logs messages, thus the quiet mode no longer '
    'serves a purpose.',
  )
  bool quiet = false,
}) {
  if (inputs.isEmpty || expected.isEmpty) {
    throw const FormatException(
      'Both inputs and expected results must not be empty.',
    );
  }

  if (inputs.length != expected.length) {
    throw const FormatException(
      'Inputs and expected result lists must be of the same length.',
    );
  }

  if (iterations < 1) {
    throw const FormatException(
      'You cannot train a network without granting it at least one '
      'iteration.',
    );
  }

  for (var iteration = 0; iteration < iterations; iteration++) {
    for (var index = 0; index < inputs.length; index++) {
      propagateBackwards(inputs[index], expected[index]);
    }
  }
}