Building my own Neural networks in Rust. Inspired by Andrej Karpathy's micrograd and related video. The code was built piece by piece from the ground up by me. I also took inspiration from rustygrad when initially figuring out how to make the Rust borrow checker happy with a DAG.
- You must have graphviz installed for the graph pngs to be generated.
let a = Value::from(3.0);
let b = Value::from(4.0);
let c = Value::from(5.0);
let d = (a - b) * c;
d.backward();
graph::render_graph(&d).unwrap()
let inputs = vec![Value::from(1.0), Value::from(2.0), Value::from(3.0)];
let neuron = neural::Neuron::new(inputs.len().try_into().unwrap());
let out = neuron.forward(inputs);
out.backward();
graph::render_graph(&out, neuron.get_subgraph_tree().unwrap()).unwrap();
let x_inputs = vec![Value::from(1.0), Value::from(2.0), Value::from(3.0)];
let y_target = Value::from(1.0);
let mlp = neural::MLP::new(x_inputs.len().try_into().unwrap(), vec![4, 4, 1]);
let preds = mlp.forward(x_inputs);
let pred = preds[0].clone();
let loss = (pred.clone() - y_target.clone()).pow(Value::from(2.0));
loss.backward();
graph::render_graph(&loss, mlp.get_subgraph_tree().unwrap()).unwrap();