crystal-fann v1.2.0
crystal-fann
Crystal bindings for the FANN C lib
Installation
Add this to your application's shard.yml
:
dependencies:
crystal-fann:
github: NeuraLegion/crystal-fann
Usage
Look at the spec for most functions
ann = Fann::Network::Standard.new(2, [2], 1)
ann.randomize_weights(0.0, 1.0)
3000.times do
ann.train_single([1.0, 0.0], [0.5])
end
result = ann.run([1.0, 0.0])
# Remember to close the network when done to free allocated C memory
ann.close
(result < [0.55] && result > [0.45]).should be_true
# Work on array of test data (batch)
ann = Fann::Network::Standard.new(2, [3], 1)
input = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
output = [[0.0], [1.0], [1.0], [0.0]]
train_data = Fann::TrainData.new(input, output)
data = train_data.train_data
ann.randomize_weights(0.0, 1.0)
if data
ann.train_batch(data, {:max_runs => 8000, :desired_mse => 0.001, :log_each => 1000})
end
result = ann.run([1.0, 1.0])
ann.close
(result < [0.15]).should be_true
# Work on array of test data using the Cascade2 algorithm (no hidden layers, net will build it alone)
ann = Fann::Network::Cascade.new(2, 1)
input = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
output = [[0.0], [1.0], [1.0], [0.0]]
train_data = Fann::TrainData.new(input, output)
data = train_data.train_data
ann.train_algorithm(LibFANN::TrainEnum::TrainRprop)
ann.randomize_weights(0.0, 1.0)
if data
ann.train_batch(data, {:max_neurons => 500, :desired_mse => 0.001, :log_each => 10})
end
result = ann.run([1.0, 1.0])
ann.close
(result < [0.1]).should be_true
Development
All C lib docs can be found here -> http://libfann.github.io/fann/docs/files/fann-h.html
- Add TrainData class
- Add network call method to train on train data
- Add binding to the 'Parallel' binding to work on multi CPU at same time
- Clean unneeded bindings in the LibFANN binding
- Add specific Exceptions
- Add binding and checks for lib errors
I guess more stuff will be added once more people will use it.
Contributing
- Fork it ( https://github.com/NeuraLegion/crystal-fann/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
Contributors
Repository
crystal-fann
Owner
Statistic
- 85
- 6
- 1
- 0
- 0
- about 3 years ago
- June 30, 2017
License
MIT License
Links
Synced at
Sat, 21 Dec 2024 05:25:54 GMT
Languages