Struct prophet::neural_net::NeuralNet [] [src]

pub struct NeuralNet {
    pub config: LearnConfig,
    // some fields omitted
}

A neural net.

Can be trained with testing data and afterwards be used to predict results.

Neural nets in this implementation constists of several stacked neural layers and organized the data flow between them.

For example when the user uses predict from NeuralNet this object organizes the input data throughout all of its owned layers and pipes the result in the last layer back to the user.

Fields

the config that handles all the parameters to tune the learning process

Methods

impl NeuralNet
[src]

Creates a new instance of a NeuralNet.

  • layer_sizes define the count of neurons (without bias) per neural layer.
  • learning_rate and learning_momentum describe the acceleration and momentum with which the created neural net will be learning. These values can be changed later during the lifetime of the object if needed.
  • act_fn represents the pair of activation function and derivate used throughout the neural net layers.

Weights between the neural layers are initialized to (0,1).

Examples

use prophet::prelude::*;

let config  = LearnConfig::new(
    0.15,                // learning_rate
    0.4,                 // learning_momentum
    ActivationFn::tanh() // activation function + derivate
);
let mut net = NeuralNet::new(config, &[2, 4, 3, 1]);
// layer_sizes: - input layer which expects two values
//              - two hidden layers with 4 and 3 neurons
//              - output layer with one neuron
 
// now train the neural net how to be an XOR-operator
let f = -1.0; // represents false
let t =  1.0; // represents true
for _ in 0..1000 {
    net.train(&[f, f], &[f]);
    net.train(&[f, t], &[t]);
    net.train(&[t, f], &[t]);
    net.train(&[t, t], &[f]);
}
// now check if the neural net has successfully learned it by checking how close
// the latest ```avg_error``` is to ```0.0```:
assert!(net.latest_error_stats().avg_error() < 0.05);

Returns the ErrorStats that were generated by the latest call to train.

Returns a default constructed ErrorStats object when this neural net was never trained before.

Trait Implementations

impl Prophet for NeuralNet
[src]

The type used internally to store weights, intermediate results etc. Read more

Predicts resulting data based on the given input data and on the data that was used to train this neural network, eventually. Read more

impl Disciple for NeuralNet
[src]

The type used internally to store weights, intermediate results etc. Read more

Trains the neural network with the given input data based on the target expected values. Read more