Project

neuronet

0.0
No release in over a year
Library to create neural networks. This is primarily a math project meant to be used to investigate the behavior of different small neural networks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8, >= 0.8.1
~> 3.2, >= 3.2.1
~> 1.45, >= 1.45.1
~> 3.5, >= 3.5.7
 Project Readme

Neuronet

DESCRIPTION:

Library to create neural networks.

This is primarily a math project meant to be used to investigate the behavior of different small neural networks.

INSTALL:

gem install neuronet

SYNOPSIS:

The library is meant to be read, but here is a motivating example:

require 'neuronet'
include Neuronet

ff = FeedForward.new([3,3])
# It can mirror, equivalent to "copy":
ff.last.mirror
values = ff * [-1, 0, 1]
values.map { '%.13g' % _1 } #=> ["-1", "0", "1"]
# It can anti-mirror, equivalent to "not":
ff.last.mirror(-1)
values = ff * [-1, 0, 1]
values.map { '%.13g' % _1 } #=> ["1", "0", "-1"]

# It can "and";
ff = FeedForward.new([2,2,1])
ff[1].mirror(-1)
ff.last.connect(ff.first)
ff.last.average
# Training "and" pairs:
pairs = [
  [[1, 1], [1]],
  [[-1, 1], [-1]],
  [[1, -1], [-1]],
  [[-1, -1], [-1]],
]
# Train until values match:
ff.pairs(pairs) do
  pairs.any? { |input, target| (ff * input).map { _1.round(1) } != target }
end
(ff * [-1, -1]).map{ _1.round } #=> [-1]
(ff * [-1,  1]).map{ _1.round } #=> [-1]
(ff * [ 1, -1]).map{ _1.round } #=> [-1]
(ff * [ 1,  1]).map{ _1.round } #=> [1]

# It can "or";
ff = FeedForward.new([2,2,1])
ff[1].mirror(-1)
ff.last.connect(ff.first)
ff.last.average
# Training "or" pairs:
pairs = [
  [[1, 1], [1]],
  [[-1, 1], [1]],
  [[1, -1], [1]],
  [[-1, -1], [-1]],
]
# Train until values match:
ff.pairs(pairs) do
  pairs.any? { |input, target| (ff * input).map { _1.round(1) } != target }
end
(ff * [-1, -1]).map{ _1.round } #=> [-1]
(ff * [-1,  1]).map{ _1.round } #=> [1]
(ff * [ 1, -1]).map{ _1.round } #=> [1]
(ff * [ 1,  1]).map{ _1.round } #=> [1]

CONTENTS:

Mju

Mju is a Marklar which value depends on which Marklar is asked. Other known Marklars are Mu and Kappa. Hope it's not confusing... I tried to give related Marklars the same name. Marklar

Marshal

Marshal works with Neuronet to save your networks:

dump = Marshal.dump ff
ff2 = Marshal.load dump
ff2.inspect == ff.inspect #=> true

Base

Scaled

LICENSE:

Copyright (c) 2023 CarlosJHR64

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.