1个不稳定版本
0.1.0 | 2023年8月28日 |
---|
#1265 in 数学
18KB
300 行
rusty_neat
简单的用于处理增强拓扑神经演化的库。它可能不是该算法的精确实现,但它简单、快速且易于使用。此外,它适用于我的用例,所以就这样。文档和库仍在进行中
它做什么?
简而言之,您首先创建输入和输出节点,没有任何连接等。然后,通过随机演化,添加中间节点和连接,其特征被随机更改。
如何使用它?
创建大量具有各自神经网络的代理。让模拟运行(或您使用它的任何用途),然后在设定的时间内选择最好的作为下一代父母的代理。或者,您可以让代理在例如存活并获得设定数量的分数(这取决于用例)之后繁殖后代。下一代应由复制其前辈的神经网络并对其进行变异来创建。
示例用法
use rusty_neat::NN;
fn init() {
// init new network with amount of (input, output) nodes
let mut net = NN::new(3, 2);
// set diffrent ( than default ) chances of mutations, sum (eg. 100%) doesn't matter
net.set_chances(&[20, 20, 20, 0, 0, 0, 0])
// evolve network, mutations are chosen randomly,
// in future there will be an interface for choosing types and chances
for _ in 0..32 {
net.mutate();
}
// forward inputs through net and return outputs
let outputs = net.forward(&[0.5, 0.2, 0.8]);
// access internal structure
// calculation order, may be used for creating graph
println!("\nOrder: \n{:?}", net.layer_order);
// list of connections
println!("\nConnections: \n{:?}", net.connections);
// list of nodes
println!("\nNodes: \n{:?}", net.nodes);
// save network to file
net.save("path");
// load network from file
net.load("path");
}
可能的变异及其默认概率
35% => modify one of connections weight,
35% => modify one of nodes bias,
10% => change one of nodes activation function,
10% => add new random connection,
10% => add new random node,
0% => connection_enable,
0% => connection_disable,
Struct NN支持通过serde进行序列化和反序列化。
依赖关系
~0.7–1.3MB
~30K SLoC