Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d12/simpleneuralnetwork
A simple neural network implementation in Ruby.
https://github.com/d12/simpleneuralnetwork
machine-learning neural-network ruby
Last synced: 9 days ago
JSON representation
A simple neural network implementation in Ruby.
- Host: GitHub
- URL: https://github.com/d12/simpleneuralnetwork
- Owner: d12
- Created: 2018-02-20T20:56:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-02T18:45:05.000Z (over 3 years ago)
- Last Synced: 2024-04-25T14:02:40.755Z (8 months ago)
- Topics: machine-learning, neural-network, ruby
- Language: Ruby
- Size: 34.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SimpleNeuralNetwork
This is a simple neural network implementation in Ruby.
This gem does not include any learning implementations (back-prop, etc).
## Installation
```
gem install simple_neural_network
```## Sample usage:
![Sample Neural Network](https://cdn-images-1.medium.com/max/1600/0*IUWJ5oJ_z6AiG7Ja.jpg)
The following code implements the above neural network.
```ruby
require 'simple_neural_network'network = SimpleNeuralNetwork::Network.new
network.create_layer(neurons: 5)
network.create_layer(neurons: 7)
network.create_layer(neurons: 7)
network.create_layer(neurons: 4)
```Neural networks are initialized with random edge weights and zero-valued neuron biases. Edge/bias initialization is configurable by setting the initialization lambdas.
The following code runs an input set against the network.
```ruby
network.run([0.5, 0.4, 0.8, 0, 0.9])
=> [0.2257, 0.7488, 0.1016, 0.9935]
```## Manipulating the network
### Setting a neuron bias
```ruby
network.layers[layer_index].neurons[neuron_index].bias = new_neuron_bias
```### Setting an edge weight
In `SimpleNeuralNetwork`, edges point forward and edge weights stored as an array of integers on a `Neuron` object. To access the edge pointing from a neuron to the `n'th` neuron in the next layer:
```ruby
network.layers[layer_index].neurons[neuron_index].edges[n] = new_edge_weight
```## Improvements / Bugs
Improvements and bugs are listed as issues in the gem repository.