This project is a testbed to attempt using an evolutionary strategy for machine learning. The examples are fairly simple networks but the solution seems to work quite well and removes all the complexity around back propogation and gradient descent. This also leverages the CPU cores by spawning and distributing the network evaluation. In theory, this could be distributed horizontally on a cluster of servers and use a federated approach.
The network uses a simple evolutionary process:
- create a sample network
- generate a population and randomize the weights and biases
- for several generations:
- evaluate the error rate and sort
- destroy the bottom 25%
- clone the top 25%
- punctuate the top 20%
- keep the best model
- randomize the worst
- mutate the population
- return the top evolved network
add to your shards.yml
dependencies:
evolvenet:
github: drujensen/evolvenet
xor example
data = [
[[0, 0], [0]],
[[0, 1], [1]],
[[1, 0], [1]],
[[1, 1], [0]],
]
network = EvolveNet::Network.new
network.add_layer(:input, 2)
network.add_layer(:hidden, 2)
network.add_layer(:output, 1)
network.fully_connect
organism = EvolveNet::Organism.new(network)
network = organism.evolve(data)
puts network.run([0, 0])
See the specs for other examples.
To run specs with threads:
LOG_LEVEL=DEBUG CRYSTAL_WORKERS=16 crystal spec --release -Dpreview_mt
- Fork it (https://github.com/drujensen/evolvenet/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Dru Jensen - creator and maintainer