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
config: LearnConfig
the config that handles all the parameters to tune the learning process
Methods
impl NeuralNet
[src]
fn new(config: LearnConfig, layer_sizes: &[Ix]) -> Self
Creates a new instance of a NeuralNet
.
layer_sizes
define the count of neurons (without bias) per neural layer.learning_rate
andlearning_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);
fn latest_error_stats(&self) -> ErrorStats
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]
type Elem = f32
The type used internally to store weights, intermediate results etc. Read more
fn predict<'b, 'a: 'b>(&'a mut self,
input: &'b [Self::Elem])
-> &'b [Self::Elem]
input: &'b [Self::Elem])
-> &'b [Self::Elem]
Predicts resulting data based on the given input data and on the data that was used to train this neural network, eventually. Read more