[][src]Struct cogent::core::NeuralNetwork

pub struct NeuralNetwork { /* fields omitted */ }

Neural network.

Methods

impl NeuralNetwork[src]

pub fn new(inputs: usize, layers: &[Layer], cost: Option<Cost>) -> NeuralNetwork[src]

Constructs network of given layers.

Returns constructed network.

use cogent::core::{NeuralNetwork,Layer,Activation};
 
let mut net = NeuralNetwork::new(2,&[
    Layer::new(3,Activation::Sigmoid),
    Layer::new(2,Activation::Softmax)
],None);

pub fn activation(&mut self, index: usize, activation: Activation)[src]

Sets activation of layer specified by index (excluding input layer).

use cogent::core::{NeuralNetwork,Layer,Activation};
 
let mut net = NeuralNetwork::new(2,&[
    Layer::new(3,Activation::Sigmoid),
    Layer::new(2,Activation::Sigmoid)
],None);
net.activation(1,Activation::Softmax); // Changes activation of output layer.

pub fn run(&self, inputs: &Array2<f32>) -> Array2<f32>[src]

Runs batch of examples through network.

Returns outputs from batch of examples.

use cogent::core::{NeuralNetwork,Layer,Activation};
use ndarray::{Array2,array};
 
let mut net = NeuralNetwork::new(2,&[
    Layer::new(3,Activation::Sigmoid),
    Layer::new(2,Activation::Softmax)
],None);
let input:Array2<f32> = array![
    [0f32,0f32],
    [1f32,0f32],
    [0f32,1f32],
    [1f32,1f32]
];
let output:Array2<f32> = net.run(&input);

pub fn train(
    &mut self,
    training_data: &Vec<(Vec<f32>, usize)>,
    k: usize
) -> Trainer
[src]

Begins setting hyperparameters for training.

Returns Trainer struct used to specify hyperparameters

Training a network to learn an XOR gate:

use cogent::core::{NeuralNetwork,Layer,Activation,EvaluationData};
 
// Sets network
let mut neural_network = NeuralNetwork::new(2,&[
    Layer::new(3,Activation::Sigmoid),
    Layer::new(2,Activation::Softmax)
],None);
// Sets data
// For output 0=false and 1=true.
let data = vec![
    (vec![0f32,0f32],0),
    (vec![1f32,0f32],1),
    (vec![0f32,1f32],1),
    (vec![1f32,1f32],0)
];
// Trains network
neural_network.train(&data,2)
    .learning_rate(2f32)
    .evaluation_data(EvaluationData::Actual(&data)) // Use testing data as evaluation data.
    .lambda(0f32)
.go();

pub fn evaluate(&self, test_data: &[(Vec<f32>, usize)], k: usize) -> (f32, u32)[src]

Returns tuple: (Average cost across batch, Number of examples correctly classified).

pub fn evaluate_outputs(
    &self,
    test_data: &[(Vec<f32>, usize)],
    k: usize
) -> (Array1<f32>, Array2<f32>)
[src]

Requires ordered test_data.

Returns tuple of: (List of correctly classified percentage for each class. Confusion matrix of percentages).

pub fn print(&self) -> String[src]

Returns pretty string of wieghts (self.connections) and biases (self.biases).

pub fn export(&self, path: &str)[src]

Exports neural network to path.

pub fn import(path: &str) -> NeuralNetwork[src]

Imports neural network from path.

Trait Implementations

impl Clone for NeuralNetwork[src]

impl<'de> Deserialize<'de> for NeuralNetwork[src]

impl Serialize for NeuralNetwork[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,