Perceptron

A perceptron implementation in Crystal.

perceptron

Single layer perceptron implementation in Crystal.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      perceptron:
        github: unullable/perceptron
    
  2. 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

  1. Fork it (https://github.com/unullable/perceptron/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

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