Skip to content

Commit 6bf3988

Browse files
feat(api): add show neurons function, refac(name): rename to "snake_case", refac(api): remove unwanted properties from structs
1 parent 29b59c0 commit 6bf3988

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

  • try1 (OOP Approach)/rust/src
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct Neuron {
1010
pub value: f32,
1111
pub bias: f32,
1212
pub weights: Vec<f32>,
13-
pub prev_layer_neurons_count: u8,
1413
}
1514
impl Neuron {
1615
fn new(prev_layer_neurons_count: u8) -> Neuron {
@@ -24,23 +23,32 @@ impl Neuron {
2423
value: 0.0,
2524
bias: random_float(rand_range),
2625
weights,
27-
prev_layer_neurons_count,
2826
}
2927
}
3028
}
31-
struct Layer {
32-
size: u8,
29+
pub struct Layer {
3330
neurons: Vec<Neuron>,
3431
}
3532
impl Layer {
36-
fn new(size: u8, prev_layer_neurons_count: u8) -> Layer {
33+
pub fn new(size: u16, prev_layer_neurons_count: u8) -> Layer {
3734
let mut neurons: Vec<Neuron> = Vec::new();
3835
for _ in 0..size {
3936
neurons.push(Neuron::new(prev_layer_neurons_count));
4037
}
4138

42-
Layer { size, neurons }
39+
Layer { neurons }
40+
}
41+
pub fn show_neurons(&self) {
42+
for (i, neuron) in self.neurons.iter().enumerate() {
43+
println!("Neuron :- {}", i);
44+
println!("value :- {}", neuron.value);
45+
println!("bias :- {}", neuron.bias);
46+
println!("weights :");
47+
for weight in neuron.weights.iter() {
48+
print!("{:.2}, ", weight);
49+
}
50+
println!("\n");
51+
}
4352
}
44-
// TODO: Add Other Function of Layer Struct
4553
}
4654
// TODO: Add remaining Structs like MLP,

0 commit comments

Comments
 (0)