{"id":28764091,"url":"https://github.com/irfansharif/cerebrum","last_synced_at":"2025-06-17T09:11:04.339Z","repository":{"id":56843372,"uuid":"55458165","full_name":"irfansharif/cerebrum","owner":"irfansharif","description":"Artificial Neural Networks (ANN's) in Ruby (unmaintained, unfortunately)","archived":false,"fork":false,"pushed_at":"2019-03-03T03:54:26.000Z","size":62,"stargazers_count":36,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-08T21:15:02.684Z","etag":null,"topics":["ann","neural-network","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/irfansharif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-05T01:32:09.000Z","updated_at":"2024-06-22T05:17:13.000Z","dependencies_parsed_at":"2022-09-09T04:12:53.039Z","dependency_job_id":null,"html_url":"https://github.com/irfansharif/cerebrum","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/irfansharif/cerebrum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irfansharif%2Fcerebrum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irfansharif%2Fcerebrum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irfansharif%2Fcerebrum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irfansharif%2Fcerebrum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/irfansharif","download_url":"https://codeload.github.com/irfansharif/cerebrum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irfansharif%2Fcerebrum/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260326793,"owners_count":22992388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ann","neural-network","ruby"],"created_at":"2025-06-17T09:11:03.391Z","updated_at":"2025-06-17T09:11:04.318Z","avatar_url":"https://github.com/irfansharif.png","language":"Ruby","funding_links":[],"categories":["Machine Learning Libraries"],"sub_categories":["Neural networks"],"readme":"# GEM: cerebrum ![](https://travis-ci.org/irfansharif/cerebrum.svg?branch=master) [![Gem Version](https://badge.fury.io/rb/cerebrum.svg)](https://badge.fury.io/rb/cerebrum)\n\n`cerebrum` is an implementation of\n[ANNs](https://en.wikipedia.org/wiki/Artificial_neural_network)\nin Ruby.  There's no reason to train a neural network in Ruby, I'm using it to\nexperiment and play around with the bare fundamentals of ANNs, original idea\nfor this project [here](https://github.com/harthur/brain) is currently\nunmaintained. Extensions on top of that are personal experimentation.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cerebrum'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install cerebrum\n\n## Usage\n\n```ruby\nrequire 'cerebrum'\n\nnetwork = Cerebrum.new\n\nnetwork.train([\n  {input: [0, 0], output: [0]},\n  {input: [0, 1], output: [1]},\n  {input: [1, 0], output: [1]},\n  {input: [1, 1], output: [0]}\n])\n\nresult = network.run([1, 0])\n# =\u003e [0.9333206724219677]\n\n```\n\n### Training\n\nUse `Cerebrum#train` to train the network with an array of training data.\n\n#### Data format\n\nEach training pattern should have an `input:` and an `output:`, both of which\ncan either be an array of numbers from `0` to `1` or a hash of numbers from `0`\nto `1`. An example of the latter is demonstrated below:\n\n```ruby\nnetwork = Cerebrum.new\n\nnetwork.train([\n    {input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }},\n    {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }},\n    {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}\n]);\n\nresult = network.run({ r: 1, g: 0.4, b: 0 })\n# =\u003e { black: 0.011967728530458011, white: 0.9871010273923573 }\n```\n\n#### Cerebrum Options\n\n`Cerebrum#new` takes a hash of options that would set defaults if not specified in the `Cerebrum#train` procedure call:\n\n```ruby\nnetwork = Cerebrum.new({\n  learning_rate:  0.3,\n  momentum:       0.1,\n  binary_thresh:  0.5,\n  hidden_layers:  [3, 4]\n})\n```\n\n#### Training Options\n\n`Cerebrum#train` optionally takes in a configuration hash as the second argument:\n\n```ruby\nnetwork.train(data, {\n  error_threshold: 0.005,\n  iterations:      20000,\n  log:             true,\n  log_period:      100,\n  learning_rate:   0.3\n})\n```\n\nThe network will train until the training error has gone below the threshold or\nthe max number of iterations has been reached, whichever comes first.\n\nBy default training won't let you know how its doing until the end, but set `log`\nto `true` to get periodic updates on the current training error of the network.\nThe training error should decrease every time. The updates will be printed to\nconsole. If you set `log` to a function, this function will be called with the\nupdates instead of printing to the console.\n\nThe `learning_rate` is a parameter that influences how quickly the network\ntrains, a number from `0` to `1`. If the learning rate is close to `0` it will\ntake longer to train. If the learning rate is closer to `1` it will train faster\nbut it's in danger of training to a local minimum and performing badly on new\ndata.\n\n#### Output\n\nThe output of `Cerebrum#train` is a hash of information about how the training went:\n\n```ruby\nnetwork.train(data, options)\n# =\u003e { error: 0.005324233132423, iterations: 9001 }\n```\n\n#### JSON\n\nSerialize or load in the state of a trained network with JSON:\n\n``` ruby\nsaved_state = network.save_state\nnn = Cerebrum.new\nnn.load_state(saved_state)\n\nnn.run({ r: 1, g: 0.4, b: 0 })\n# =\u003e { black: 0.011967728530458011, white: 0.9871010273923573 }\n```\n\nAdditionally the new network can be separately trained whilst retaining all\nprevious training from the other network.\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.  To install this gem onto your local\nmachine, run `bundle exec rake install`. To release a new version, update the\nversion number in `version.rb`, and then run `bundle exec rake release`, which\nwill create a git tag for the version, push git commits and tags, and push the\n`.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [irfansharif](https://github.com/irfansharif/cerebrum).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firfansharif%2Fcerebrum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firfansharif%2Fcerebrum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firfansharif%2Fcerebrum/lists"}