[−][src]Struct cogent::core::NeuralNetwork
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]
&mut self,
training_data: &Vec<(Vec<f32>, usize)>,
k: usize
) -> Trainer
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]
&self,
test_data: &[(Vec<f32>, usize)],
k: usize
) -> (Array1<f32>, Array2<f32>)
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]
fn clone(&self) -> NeuralNetwork
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'de> Deserialize<'de> for NeuralNetwork
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Serialize for NeuralNetwork
[src]
Auto Trait Implementations
impl RefUnwindSafe for NeuralNetwork
impl Send for NeuralNetwork
impl Sync for NeuralNetwork
impl Unpin for NeuralNetwork
impl UnwindSafe for NeuralNetwork
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,