In the last episode we walked through the code that initializes a neural network in Karmen Blake's neural_network_elixir library. Today we're going to see how the network is trained. Let's get to it.

Again, we're starting with a function call in our or mix task:

vim lib/mix/tasks/or.ex

After initializing the network with our desired topology, we pass it some training data and tell it to train for a certain number of iterations, and we tell it how frequently to log its progress.

 Trainer.train(network_pid, training_data(), %{epochs: epoch_count, log_freqs: 1000})

What does Trainer.train do?

defmodule NeuralNetwork.Trainer do @moduledoc """ Runs a network as classified by data its given. """ alias NeuralNetwork.{Network} def train(network_pid, data, options \\ %{}) do epochs = options.epochs log_freqs = options.log_freqs data_length = length(data) for epoch <- 0..epochs do average_error = Enum.reduce(data, 0, fn sample, sum -> # sum...