8个版本

使用旧的Rust 2015

0.1.6 2015年5月8日
0.1.5 2015年4月3日
0.1.2 2015年3月30日
0.0.1 2015年3月17日

#709 in 机器学习

Download history 7/week @ 2024-01-08 24/week @ 2024-02-19 16/week @ 2024-02-26 16/week @ 2024-03-04 20/week @ 2024-03-11 16/week @ 2024-03-18 17/week @ 2024-03-25 36/week @ 2024-04-01 8/week @ 2024-04-08 19/week @ 2024-04-15

81 每月下载量
用于 mlcr

Apache-2.0

22KB
310 代码行

RustNN

Build Status

一个用Rust编写的易于使用的神经网络库。

文档

描述

RustNN是一个 前馈神经网络 库。该库生成完全连接的多层人工神经网络,通过 反向传播 进行训练。网络使用增量训练模式进行训练。

XOR示例

此示例创建了一个输入层有 2 个节点、一个包含 3 个节点的单个隐藏层以及输出层有 1 个节点的神经网络。然后,该网络使用 XOR 函数的示例进行训练。在调用 train(&examples) 之后调用的所有方法都是可选的,仅用于指定各种选项,以指定网络应该如何进行训练。当调用 go() 方法时,网络将开始根据给定的示例进行训练。有关 NNTrainer 结构体的详细信息,请参阅文档。

use nn::{NN, HaltCondition};

// create examples of the XOR function
// the network is trained on tuples of vectors where the first vector
// is the inputs and the second vector is the expected outputs
let examples = [
    (vec![0f64, 0f64], vec![0f64]),
    (vec![0f64, 1f64], vec![1f64]),
    (vec![1f64, 0f64], vec![1f64]),
    (vec![1f64, 1f64], vec![0f64]),
];

// create a new neural network by passing a pointer to an array
// that specifies the number of layers and the number of nodes in each layer
// in this case we have an input layer with 2 nodes, one hidden layer
// with 3 nodes and the output layer has 1 node
let mut net = NN::new(&[2, 3, 1]);
    
// train the network on the examples of the XOR function
// all methods seen here are optional except go() which must be called to begin training
// see the documentation for the Trainer struct for more info on what each method does
net.train(&examples)
    .halt_condition( HaltCondition::Epochs(10000) )
    .log_interval( Some(100) )
    .momentum( 0.1 )
    .rate( 0.3 )
    .go();
    
// evaluate the network to see if it learned the XOR function
for &(ref inputs, ref outputs) in examples.iter() {
    let results = net.run(inputs);
    let (result, key) = (results[0].round(), outputs[0]);
    assert!(result == key);
}

依赖项

~1.1–1.5MB
~25K SLoC