[−][src]Struct neat_gru::neural_network::NeuralNetwork
FFI wrapper for the NeuralNetwork C++ class
/!\ It contains a c_void* pointer. Accessing it from different threads is unsafe
Example
use neat_gru::neural_network::NeuralNetwork; use std::fs; let serialized: String = fs::read_to_string("topology_test.json") .expect("Something went wrong reading the file"); let mut net = NeuralNetwork::from_string(&serialized); let input_1: Vec<f64> = vec![0.5, 0.5]; let input_2: Vec<f64> = vec![-0.5, -0.5]; let output_1 = net.compute(&input_1, 1); let output_2 = net.compute(&input_2, 1); let output_3 = net.compute(&input_1, 1); // 1 and 2 should by definition be different assert_ne!(output_1, output_2); assert_ne!(output_1, output_3); //Because of GRU gates, giving the same input twice won't yield the same output assert_ne!(output_2, output_3); // Reset net.reset_state(); let output_4 = net.compute(&input_1, 1); // After resetting, giving the same input sequence should yield the same results assert_eq!(output_1, output_4);
Implementations
impl NeuralNetwork
[src]
pub fn new(ptr: *mut c_void) -> NeuralNetwork
[src]
Creates a new NeuralNetwork wrapper from a c void pointer
Arguments
ptr
- The C pointer to the C++ NeuralNetwork
pub fn compute(&self, input: &[f64], output_length: usize) -> Vec<f64>
[src]
Computes the Neural Network and returns the result
Arguments
input
- The input values on the first layer
output_length
- The number of outputs expected
pub fn reset_state(&mut self)
[src]
Resets the hidden state of a neural network
Use it to make the network forget
previous dataset during a generation
pub fn from_string(serialized: &str) -> NeuralNetwork
[src]
Parses a neural network to string
Arguments
serialized
- A string represented a JSON serialisation of a neural network's topology
Returns
A neural network instance /!\ The pointer is allocated on the heap
Example
use std::fs; use neat_gru::neural_network::NeuralNetwork; let serialized: String = fs::read_to_string("topology_test.json").expect("Something went wrong reading the file"); let mut net = NeuralNetwork::from_string(&serialized); net.compute(&vec![0.5, 0.5], 1);
pub fn get_ptr(&self) -> *mut c_void
[src]
Trait Implementations
impl Clone for NeuralNetwork
[src]
fn clone(&self) -> NeuralNetwork
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'_> Into<NeuralNetwork> for &'_ Topology
[src]
fn into(self) -> NeuralNetwork
[src]
impl Send for NeuralNetwork
[src]
impl Sync for NeuralNetwork
[src]
Auto Trait Implementations
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,