-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.rs
35 lines (30 loc) · 917 Bytes
/
simple.rs
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
//this is a simple example that uses a neural network with
// 2 input layer neurons,
// 3 hidden layer neurons
// and 1 output layer neuron
//to approximate a XOR function
use nn::dataset;
use nn::defaults::DefaultRng as Rng;
use nn::nn::NeuralNetwork;
fn main() {
let mut nn = NeuralNetwork::new(&[2, 3, 3, 1], &mut Rng::new());
nn.set_err_thres(1e-8);
nn.set_momentum(0.01);
nn.train(
100000,
&dataset!(
[0., 0.] => [0.],
[0., 1.] => [1.],
[1., 0.] => [1.],
[1., 1.] => [0.],
[0., 0.] => [0.],
[0., 1.] => [1.],
[1., 0.] => [1.],
[1., 1.] => [0.],
),
);
println!("{:?}", nn.predict(vec![0., 0.]));
println!("{:?}", nn.predict(vec![0., 1.]));
println!("{:?}", nn.predict(vec![1., 0.]));
println!("{:?}", nn.predict(vec![1., 1.]));
}