Struct revonet::neuro::MultilayeredNetwork [] [src]

pub struct MultilayeredNetwork { /* fields omitted */ }

Representation of multilayered neural network with linear activation on output and arbitrary activations for hidden layers.

Methods

impl MultilayeredNetwork
[src]

Create a new multilayered network object with given number of inputs and outputs.

The resulting network is not initialized. To add hidden layeres use add_hidden_layer and then call build function to finalize structure and weights initialization.

Arguments:

  • inputs_num - number of input nodes.
  • outputs_num - number of output nodes.

Create and initialize a new neural network object given sizes of layers (including input and output ones) and activation types.

The resulting network will have a linear activation in the output layer.

Arguments:

  • layers - array containing sizes of input (layers[0]), output (layers[layers.len()-1]) and hidden layers (layers[1:layers.len()-1]).
  • acts - array of activations for hidden layers. Note that k-th hidden layers will have k-th activation!

Number of hidden+output layers in the neural network.

Add a hidden layer to an uninitialized network.

Panics if the network has already been initialized .

Arguments:

  • size - number of nodes in a layer.
  • actf - type of activation function.

Finalize building neural network and initialize its weights.

Arguments:

  • rng - mutable reference to the external RNG.

Returns tuple containing weights and biases layer by layer.

Return:

  • result.0 - matrix of weights. k-th row corresponds to the flattened vector of weights for k-th layer.
  • result.1 - matrix of biases. k-th row corresponds to the vector of biases for k-th layer.

Example: Multilayered network with sigmoid activations:

extern crate rand;
use rand::{Rng};

extern crate revonet;
use revonet::neuro::*;

fn main () {
    const INPUT_SIZE: usize = 20;
    const OUTPUT_SIZE: usize = 2;

    let mut rng = rand::thread_rng();   // needed for weights initialization when NN is built.
    let mut net: MultilayeredNetwork = MultilayeredNetwork::new(INPUT_SIZE, OUTPUT_SIZE);
    net.add_hidden_layer(30 as usize, ActivationFunctionType::Sigmoid)
       .add_hidden_layer(20 as usize, ActivationFunctionType::Sigmoid)
       .build(&mut rng, NeuralArchitecture::Multilayered);       // `build` finishes creation of neural network.

    let (ws, bs) = net.get_weights();   // `ws` and `bs` are `Vec` arrays containing weights and biases for each layer.
    assert!(ws.len() == 3);     // number of elements equals to number of hidden layers + 1 output layer
    assert!(bs.len() == 3);     // number of elements equals to number of hidden layers + 1 output layer

    let rnd_input = (0..INPUT_SIZE).map(|_| rng.gen::<f32>()).collect::<Vec<f32>>();
    println!("NN outputs: {:?}", net.compute(&rnd_input));
}

Sets weights and biases layer by layer.

See description for the get_weights for more details and example.

Arguments:

  • wss - matrix of weights. wss[k] flattened vector of weights for the k-th layer.
  • bss - matrix of biases. bss[k] flattened vector of biases for the k-th layer.

Returns iterator for layers.

Trait Implementations

impl Debug for MultilayeredNetwork
[src]

Formats the value using the given formatter.

impl NeuralNetwork for MultilayeredNetwork
[src]

Returns number of input nodes.

Returns number of output nodes.

Compute output of neural network for a given input vector. Read more

impl Clone for MultilayeredNetwork
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more