rust_neural_network/
lib.rs1#![allow(unused_imports)]
2#![allow(dead_code)]
3
4use std::{
5 borrow::Borrow,
6 collections::HashMap,
7 time::{Duration, Instant},
8 vec,
9};
10
11use std::sync::mpsc::Sender;
12
13pub mod neural_network;
14pub mod utils;
15use ndarray::{array, Array2};
16
17use crate::neural_network::{NeuralNetwork, NEURAL_NETWORK_MANAGER};
18
19const TICK_SPEED: u32 = 1;
20
21pub fn main() {
22 println!("Begin");
23
24 let inputs: Vec<f32> = vec![1., 3.];
41 let output_count = 1;
42
43 let mut neural_network = init(inputs.len(), output_count);
44 run_ticks(&mut neural_network, inputs);
45
46 println!("End");
47}
48
49pub fn init(input_count: usize, output_count: usize) -> NeuralNetwork {
50 let neural_network = NeuralNetwork::new(1., 0.1, vec![input_count, 5, 3, output_count]);
51 neural_network
52}
53
54pub fn run_ticks(neural_network: &mut NeuralNetwork, inputs: Vec<f32>) {
55 let time_start = Instant::now();
56
57 for tick in 0..50000 {
58 if tick > 500 {
59 break;
60 }
61
62 print!("Processing tick: ");
63 println!("{}", tick);
64
65 let time_elapsed = time_start.elapsed();
66 println!("{:?}", time_elapsed);
67
68 let activations = neural_network.forward_propagate(inputs.clone());
69
70 println!("Ouputs {:?}", activations.last().unwrap());
71
72 if tick % 10 == 0 {
73 neural_network.mutate();
74 neural_network.write_to_file();
75 }
76 }
77}