ruby-fann
ruby-fann copied to clipboard
Segmentation fault problem
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
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?
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...
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.
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.