Crate nnrs

source ·
Expand description


A simple, minimal neural network library written in Rust. No training included


use nnrs::{network::Network, node::Node, edge::Edge, layer::LayerID, activationfn::ActivationFn};

let mut network = Network::create(1, 1, ActivationFn::Linear).unwrap();
let mut output: Vec<f64> = Vec::new();

let layer_id = network.add_layer();

let input_node_id = network.input_node_ids().pop().unwrap();
let hidden_node_id = Node::create(&mut network, layer_id, 0.2).unwrap();
let output_node_id = network.output_node_ids().pop().unwrap();

let edge_input_to_hidden = Edge::create(&mut network, input_node_id, hidden_node_id, 1.3).unwrap();
let edge_hidden_to_output = Edge::create(&mut network, hidden_node_id, output_node_id, 1.5).unwrap();![0.8], &mut output).unwrap();

assert_eq!(output, vec![((0.8 * 1.3) + 0.2) * 1.5]);


  • Activation functions
  • Edges represent connections between nodes.
  • Contains the LayerID enum. Layer IDs are used to group Nodes.
  • Contains the Network struct. Use this to interact with your Network.
  • Nodes are the basic building blocks of a neural network.