Perceptron
perceptron
Single layer perceptron implementation in Crystal.
Installation
-
Add the dependency to your
shard.yml:dependencies: perceptron: github: unullable/perceptron -
Run
shards install
Usage
require "perceptron"
OR_gate = [
[0_f64, 0_f64], [0_f64, 1_f64],
[1_f64, 0_f64], [1_f64, 1_f64]
]
Targets = [ 0_f64, 1_f64, 1_f64, 1_f64 ]
# Create a new perceptron neuron that takes 2 inputs
neuron = Perceptron::Neuron.new(n_inputs: 2)
# Start a training session given the neuron as input and learning rate a = 0.01
session = Perceptron::Session.new(neuron, lrate: 0.01)
# Train the neuron
spawn do
Perceptron::EPOCHS.times do |epoch|
finished = true
OR_gate.each_with_index do |_, i|
finished &&= session.fit(OR_gate[i], Targets[i])
end
break if finished
end
end
sleep
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/unullable/perceptron/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
- unullable - creator and maintainer
Repository
Perceptron
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- about 1 hour ago
- December 2, 2026
License
MIT License
Links
Synced at
Wed, 02 Dec 2026 15:25:43 GMT
Languages