tangledpath / ruby-fann

Ruby library for interfacing with FANN (Fast Artificial Neural Network)
https://github.com/tangledpath/ruby-fann
MIT License
496 stars 42 forks source link

Segmentation fault problem #12

Closed ASnow closed 7 months ago

ASnow commented 9 years ago

This code cause [BUG] Segmentation fault

raw_input = "
1           1
    1     1 
    1   1   

  1         1

  1         1

    1     1 
    1     1 
1         1 

1           1
1           1
  1         1

1       1   
1       1   
1       1   
1       1   
1       1   
    1   1   

  1       1 
    1   1   

  1       1 
1           1
  1         1

    1     1 
1       1   
  1     1   
    1   1   

  1     1   
    1   1   

    1     1 
1           1
    1     1 
  1     1   
  1         1

    1       1
1           1
  1       1 
  1     1   
    1     1 
1       1   
  1     1   
  1         1
"

raw_input = raw_input.split(/\n/)
raw_input = raw_input.reject{ |a| !(a =~ /1/) }
raw_input = raw_input.map{ |s| [s.index('1'), s.rindex('1')] }
winloose = {
  0 => {8 => 1, 10 => 0, 12 => 2},
  2 => {8 => 2, 10 => 1, 12 => 0},
  4 => {8 => 0, 10 => 2, 12 => 1}
}
raw_input.each{ |r| r[2] = winloose[r[0]][r[1]] }
results = raw_input[1..-1].map{ |r| r[1] }
train = RubyFann::TrainData.new(:inputs=>raw_input[0..-2], :desired_outputs=>results)

ruby-2.0.0-p481

inspire22 commented 9 years ago

I get this segmentation fault too - but when I run the example in this one I don't, so not sure what could be causing it. https://github.com/bigohstudios/tictactoe

Did you ever get it working? Or with another project?

inspire22 commented 9 years ago

Aah, all your inputs and outputs need to be normalized to 0..1 FYI, which may be part of your problem. I'm doing that though and still getting a segfault...

ASnow commented 9 years ago

I think solutions for this kind of bugs is put results in array

results = raw_input[1..-1].map{ |r| r[1] } # error
results = raw_input[1..-1].map{ |r| [r[1]] } # no error

I dont test this for logic proof but segfault dont apeared.

inspire22 commented 9 years ago

Right, thanks. However I still don't get any meaningful results, have you had any luck with that? It always returns the same result to fann.run([1,2,3,4]) no matter the input.