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
/*!
The library can make very basic feedforward neural networks.
Learning hasn't been implemented yet.
Library still needs a lot of work.
In brainy a layer struct represents a layer of the neural network (excluding the output layer) and a map to the next layer.
For now the activation function is treated as a seperate map from something like matrix multiplication.
That way, one can "mix and match" different maps.
A description of the underlying math and a deeper explanation of the code can be found here:
https://thefrogblog.xyz/neural-network-1/
https://thefrogblog.xyz/neural-network-2/
https://thefrogblog.xyz/neural-network-3/
Some example code:
```
extern crate brainy;
use brainy::matrix::Matrix;
use brainy::layer::Map;
use brainy::network::Network;
fn main()
{
let mut network = Network::new();
network.append_layer(Map::MatrixMultiply(4,3));
network.append_layer(Map::Sigmoid(3));
network.append_layer(Map::MatrixMultiply(3,2));
let input = vec![0.0, 1.0, 1.0, 0.5];
let x = Matrix { rows: input.len(), cols: 1, elements: input };
let y = network.feedforward(x);
y.print();
}
```
*/