Skip to content

Instantly share code, notes, and snippets.

@ymurase
Created October 30, 2014 07:26
Show Gist options
  • Save ymurase/d612bd9adb0044f6730e to your computer and use it in GitHub Desktop.
Save ymurase/d612bd9adb0044f6730e to your computer and use it in GitHub Desktop.
sample of Ruby-fann
require 'pp'
require 'ruby-fann'
def f(x,y)
Math.exp(- ((x-1.0)/2.0)**2 - (y/1.0)**2 )
end
n = 100
inputs = []
n.times do |i|
inputs << [ rand, rand]
end
desired_outputs = inputs.map {|x,y| [f(x,y)] }
train = RubyFann::TrainData.new(inputs: inputs, desired_outputs: desired_outputs)
fann = RubyFann::Standard.new(num_inputs: inputs.first.size, hidden_neurons: [2,8,4,3,4], num_outputs: desired_outputs.first.size)
fann.train_on_data(train, 10000, 10, 0.001)
10.times do |i|
a = [rand, rand]
pp fann.run(a), f(*a)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment