Repository navigation
Expand file tree
/
Copy pathbasic_usage.rs
More file actions
39 lines (31 loc) · 1.48 KB
/
Copy pathbasic_usage.rs
File metadata and controls
39 lines (31 loc) · 1.48 KB
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
use ruv_fann::{ActivationFunction, NetworkBuilder};
fn main() {
// Create a neural network with 2 inputs, 3 hidden neurons, and 1 output
let mut network = NetworkBuilder::<f32>::new()
.input_layer(2)
.hidden_layer_with_activation(3, ActivationFunction::Sigmoid, 1.0)
.output_layer_with_activation(1, ActivationFunction::Linear, 1.0)
.connection_rate(1.0) // Fully connected
.build();
println!("Created network with {} layers", network.num_layers());
println!("Input neurons: {}", network.num_inputs());
println!("Output neurons: {}", network.num_outputs());
println!("Total neurons: {}", network.total_neurons());
println!("Total connections: {}", network.total_connections());
// Run the network with some test inputs
let inputs = vec![0.5, 0.7];
let outputs = network.run(&inputs).unwrap();
println!("Inputs: {inputs:?}");
println!("Outputs: {outputs:?}");
// Get and display current weights
let weights = network.get_weights();
println!("Number of weights: {}", weights.len());
// Example of setting new weights (normally done by training algorithm)
let new_weights: Vec<f32> = (0..weights.len()).map(|i| (i as f32) * 0.1 - 0.5).collect();
if let Ok(()) = network.set_weights(&new_weights) {
println!("Successfully updated weights");
// Run again with new weights
let new_outputs = network.run(&inputs).unwrap();
println!("New outputs: {new_outputs:?}");
}
}