Giter VIP home page Giter VIP logo

Comments (8)

tagliala avatar tagliala commented on May 28, 2024 4

It works for me, using @bnolan 's example above:

⚠️ Disclaimer ⚠️

I'm new to NN and I don't know enough of NN theory. In the following example, the input data set is very small and you should not run the NN against the training data. Also that training could fail, so you may need to repeat the process

require 'ruby-fann'

inputs          = [ [0, 0], [0, 1], [1, 0], [1, 1] ]
desired_outputs = [    [0],    [1],    [1],    [0] ] # proper XOR

hidden_neurons_number = ((inputs.first.size + desired_outputs.first.size) ** 0.5).round + 1

train = RubyFann::TrainData.new(inputs: inputs, desired_outputs: desired_outputs)

fann = RubyFann::Standard.new(num_inputs: 2, hidden_neurons: [hidden_neurons_number], num_outputs: 1)
fann.train_on_data(train, 1000, 10, 0.01) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)

inputs.each do |input|
  puts "#{input} => #{fann.run(input)}"
end
ruby nn_xor_test.rb
Max epochs     1000. Desired error: 0.0099999998.
Epochs            1. Current error: 0.2503120899. Bit fail 4.
Epochs           10. Current error: 0.2499401718. Bit fail 4.
Epochs           20. Current error: 0.2423011661. Bit fail 4.
Epochs           30. Current error: 0.1863817573. Bit fail 3.
Epochs           40. Current error: 0.1407767683. Bit fail 1.
Epochs           50. Current error: 0.0858674496. Bit fail 1.
Epochs           60. Current error: 0.0190158486. Bit fail 0.
Epochs           62. Current error: 0.0088274833. Bit fail 0.
[0, 0] => [0.03469912811834021]
[0, 1] => [0.9446454636507801]
[1, 0] => [0.8884668126782995]
[1, 1] => [0.09336504889216161]

$ ruby nn_xor_test.rb
Max epochs     1000. Desired error: 0.0099999998.
Epochs            1. Current error: 0.2500002086. Bit fail 4.
Epochs           10. Current error: 0.2500554621. Bit fail 4.
Epochs           20. Current error: 0.2129755616. Bit fail 3.
Epochs           30. Current error: 0.1599631906. Bit fail 3.
Epochs           40. Current error: 0.1051470712. Bit fail 1.
Epochs           50. Current error: 0.0148407854. Bit fail 0.
Epochs           52. Current error: 0.0080423718. Bit fail 0.
[0, 0] => [0.103887281802755]
[0, 1] => [0.9576252736384885]
[1, 0] => [0.9506385048123076]
[1, 1] => [0.11616178258391585]

from ruby-fann.

inspire22 avatar inspire22 commented on May 28, 2024

Just to reply to myself, debugged with the tic-tac-toe project (clever!) but it is broken as well - fitness always returns 0.0

  • this project is dead!

[{:move=>[0, 0, 0, 0, 0, 0, 0, 0, 1], :fitness=>0.0}, {:move=>[0, 0, 0, 0, 0, 0, 0, 1, 0], :fitness=>0.0}, {:move=>[0, 0, 0, 0, 0, 0, 1, 0, 0], :fitness=>0.0}, {:move=>[0, 0, 0, 0, 0, 1, 0, 0, 0], :fitness=>0.0}, {:move=>[0, 0, 0, 1, 0, 0, 0, 0, 0], :fitness=>0.0}, {:move=>[0, 0, 1, 0, 0, 0, 0, 0, 0], :fitness=>0.0}, {:move=>[0, 1, 0, 0, 0, 0, 0, 0, 0], :fitness=>0.0}, {:move=>[1, 0, 0, 0, 0, 0, 0, 0, 0], :fitness=>0.0}]
[0, 0, 0, 0, 0, 0, 0, 0, 1]

from ruby-fann.

groe avatar groe commented on May 28, 2024

I just ran into the same problem as well while experimenting with the library. Too bad it seems to be unmaintained at the moment :/

from ruby-fann.

bnolan avatar bnolan commented on May 28, 2024

Yeah this project is dead, I can't get it to run an xor example.

require 'ruby-fann'
train = RubyFann::TrainData.new(
  inputs: [
    [0, 0], [0, 1], [1, 1], [1, 0]
  ], 
  desired_outputs: [
    [0], [1], [1], [0]
  ]
);

fann = RubyFann::Standard.new(num_inputs: 2, hidden_neurons: [10, 10, 10], num_outputs: 1)
fann.train_on_data(train, 1000, 10, 0.01) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)

puts '0,0', fann.run([0, 0])
puts '0,1', fann.run([0, 1])
puts '1,0', fann.run([1, 0])
puts '1,1', fann.run([1, 1])

from ruby-fann.

heri avatar heri commented on May 28, 2024

@tagliala how did you come to the formula for hidden_neurons_number?

Also why only a number? in the given example, it is an array [2, 8, 4, 3, 4]. I'm not sure how it relates to your formula

from ruby-fann.

tagliala avatar tagliala commented on May 28, 2024

@heri Sorry but as I mentioned before, I don't know enough of NN theory.

I've found that formula here

Also why only a number?

As far as I understand, single number: 1 layer
image

Multiple numbers: something like this
image

from ruby-fann.

heri avatar heri commented on May 28, 2024

@tagliala Thanks. It looks like the + 1 can be changed up to + 10 and also one needs to experiment with the number of hidden layers.

I have errors (more than 1_000_000 !) so I will experiment with different values to see if ruby-fann can work with my dataset.

Also what's not mentioned by others is that we need to choose carefully select the data features.

from ruby-fann.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.