[][src]Struct scholar::NeuralNet

pub struct NeuralNet<A: Activation> { /* fields omitted */ }

A fully-connected neural network.

Methods

impl<A: Activation + Serialize + DeserializeOwned> NeuralNet<A>[src]

pub fn new(node_counts: &[usize]) -> Self[src]

Creates a new network with the given node configuration and activation.

Examples

use scholar::{NeuralNet, Sigmoid};

// Creates a neural network with two input nodes,
// a single hidden layer with two nodes, and one output node
let brain: NeuralNet<Sigmoid> = NeuralNet::new(&[2, 2, 1]);

Panics

This function panics if the number of layers (i.e. the length of the given node_counts slice) is less than 2.

pub fn from_file(path: impl AsRef<Path>) -> Result<Self, LoadErr>[src]

Creates a new network from a valid file.

Files are valid only if they were created using NeuralNet::save().

Examples

use scholar::{NeuralNet, Sigmoid};

let brain: NeuralNet<Sigmoid> = NeuralNet::from_file("brain.network")?;

pub fn train(
    &mut self,
    training_dataset: Dataset,
    iterations: u64,
    learning_rate: f64
)
[src]

Trains the network on the given dataset for the given number of iterations.

Examples

use scholar::{Dataset, NeuralNet, Sigmoid};

let dataset = Dataset::from_csv("iris.csv", false, 4)?;

let mut brain: NeuralNet<Sigmoid> = NeuralNet::new(&[4, 10, 10, 1]);
brain.train(dataset, 10_000, 0.01);

pub fn test(&mut self, testing_dataset: Dataset) -> f64[src]

Calculates the average cost of the network.

Examples

use scholar::{Dataset, NeuralNet, Sigmoid};

let dataset = Dataset::from_csv("iris.csv", false, 4)?;
let (training_data, testing_data) = dataset.split(0.75);

let mut brain: NeuralNet<Sigmoid> = NeuralNet::new(&[4, 10, 10, 1]);
brain.train(training_data, 10_000, 0.01);

let avg_cost = brain.test(testing_data);
println!("Accuracy: {:.2}%", (1.0 - avg_cost) * 100.0);

pub fn save(&self, path: impl AsRef<Path>) -> Result<(), SaveErr>[src]

Saves the network in a binary format to the specified path.

Examples

use scholar::{NeuralNet, Sigmoid};

let brain: NeuralNet<Sigmoid> = NeuralNet::new(&[2, 2, 1]);

brain.save("brain")?;

pub fn guess(&mut self, inputs: &[f64]) -> Vec<f64>[src]

Performs the feedforward algorithm on the given input slice, and returns the value of the output layer as a vector.

Examples

use scholar::{NeuralNet, Sigmoid};

let mut brain: NeuralNet<Sigmoid> = NeuralNet::new(&[3, 10, 2]);
let result = brain.guess(&[1.0, 0.0, -0.5]);

assert_eq!(result.len(), 2);

Panics

This method panics if the number of given input values is not equal to the number of nodes in the network's input layer.

Trait Implementations

impl<'de, A: Activation> Deserialize<'de> for NeuralNet<A>[src]

impl<A: Activation> Serialize for NeuralNet<A>[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for NeuralNet<A> where
    A: RefUnwindSafe

impl<A> Send for NeuralNet<A> where
    A: Send

impl<A> Sync for NeuralNet<A> where
    A: Sync

impl<A> Unpin for NeuralNet<A> where
    A: Unpin

impl<A> UnwindSafe for NeuralNet<A> where
    A: UnwindSafe

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: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

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>,