1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! # nnrs
//! A simple, minimal neural network library written in Rust. No training included
//!
//! ## Example:
//! ```
//! use nnrs::{network::Network, node::Node, edge::Edge, layer::LayerID, activationfn::ActivationFn};
//!
//! let mut network = Network::create(1, 1, ActivationFn::Linear).unwrap();
//! let mut output: Vec<f64> = Vec::new();
//!
//! let layer_id = network.add_layer();
//!
//! let input_node_id = network.input_node_ids().pop().unwrap();
//! let hidden_node_id = Node::create(&mut network, layer_id, 0.2).unwrap();
//! let output_node_id = network.output_node_ids().pop().unwrap();
//!
//! let edge_input_to_hidden = Edge::create(&mut network, input_node_id, hidden_node_id, 1.3).unwrap();
//! let edge_hidden_to_output = Edge::create(&mut network, hidden_node_id, output_node_id, 1.5).unwrap();
//!
//! network.fire(vec![0.8], &mut output).unwrap();
//!
//! assert_eq!(output, vec![((0.8 * 1.3) + 0.2) * 1.5]);
//! ```
/// Edges represent connections between nodes.
/// Contains the `LayerID` enum. Layer IDs are used to group `Nodes`.
/// Contains the `Network` struct. Use this to interact with your Network.
/// Nodes are the basic building blocks of a neural network.
/// Activation functions
// /// NEAT training for the Neural Network
// #[cfg(feature = "neat")]
// pub mod neat;
// #[test]
// fn test_neat() -> anyhow::Result<()> {
// use crate::{
// neat::{
// environment::Environment,
// settings::{Settings, TrainingMode},
// },
// network::Network,
// };
// let network = Network::create(2, 1)?;
// let settings = Settings {
// population_size: 100,
// training_mode: TrainingMode::FitnessTarget(100f64),
// ..Settings::default()
// };
// let mut environment = Environment::new(settings, network, |network| {
// let mut distance = 0.0;
// let mut output = vec![];
// network.fire(vec![0.0, 0.0], &mut output).unwrap();
// distance += (0f64 - output[0]).abs();
// output.clear();
// network.fire(vec![0.0, 1.0], &mut output).unwrap();
// distance += (1f64 - output[0]).abs();
// output.clear();
// network.fire(vec![1.0, 0.0], &mut output).unwrap();
// distance += (1f64 - output[0]).abs();
// output.clear();
// network.fire(vec![1.0, 1.0], &mut output).unwrap();
// distance += (0f64 - output[0]).abs();
// output.clear();
// (4f64 - distance).powi(2)
// });
// let mut champ = environment.run().unwrap();
// let mut output = vec![];
// champ.fire(vec![0.0, 0.0], &mut output).unwrap();
// println!("Campion says xor of 1 and 0 is: {:?}", output);
// Ok(())
// }