Crates.io | mynn |
lib.rs | mynn |
version | 0.1.1 |
source | src |
created_at | 2024-06-09 21:03:51.87543 |
updated_at | 2024-06-11 03:11:39.275672 |
description | Experimental no_std type-safe neural network library. |
homepage | |
repository | https://github.com/jasonalexander-ja/mynn |
max_upload_size | |
id | 1266623 |
size | 25,131 |
A hobbyist no-std neural network library.
This is a small library (currently ~200 lines minus doc comments and helper macros) I initially created during my lunch break when I had attempted to represent the shape of a neural network in Rust's type system, the result was I was able to make all the vectors into fixed sized arrays and allow the neural network to be no-std and in theory usable on microcontroller and embedded platforms.
See this example of a pre-trained model approximating an XOR running on an ATtiny85.
Command line:
cargo add mynn
Cargo.toml:
mynn = "0.1.1"
To use f32
in all operations, supply the f32
flag:
mynn = { version = "0.1.1", features = ["f32"] }
Short example approximates the output of a XOR gate.
use mynn::make_network;
use mynn::activations::SIGMOID;
fn main() {
let inputs = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]];
let targets = [[0.0], [1.0], [1.0], [0.0]];
let mut network = make_network!(2, 3, 1);
network.train(0.5, inputs, targets, 10_000, &SIGMOID);
println!("0 and 0: {:?}", network.predict([0.0, 0.0], &SIGMOID));
println!("1 and 0: {:?}", network.predict([1.0, 0.0], &SIGMOID));
println!("0 and 1: {:?}", network.predict([0.0, 1.0], &SIGMOID));
println!("1 and 1: {:?}", network.predict([1.0, 1.0], &SIGMOID));
}