ruby - Train neural network with sine function -


i want train neural network sine() function.

currently use code , (cerebrum gem):

require 'cerebrum'  input = array.new 300.times |i|   inputh = hash.new   inputh[:input]=[i]   sinus = math::sin(i)   inputh[:output] = [sinus]   input.push(inputh)  end  network = cerebrum.new  network.train(input, {   error_threshold: 0.00005,   iterations:      40000,   log:             true,   log_period:      1000,   learning_rate:   0.3 })   res = array.new 300.times |i|   result = network.run([i])   res.push(result[0]) end  puts "#{res}" 

but not work, if run trained network weird output values (instead of getting part of sine curve).

so, doing wrong?

cerebrum basic , slow nn implementation. there better options in ruby, such ruby-fann gem.

most problem network simple. have not specified hidden layers - looks code assigns default hidden layer 3 neurons in case.

try like:

network = cerebrum.new({   learning_rate:  0.01,   momentum:       0.9,   hidden_layers:  [100] }) 

and expect take forever train, plus still not good.

also, choice of 300 outputs broad - network noise , won't interpolate between points. neural network not somehow figure out "oh, must sine wave" , match it. instead interpolates between points - clever bit happens when in multiple dimensions @ once, perhaps finding structure not spot manual inspection. give reasonable chance of learning something, suggest give denser points e.g. have sinus = math::sin(i) instead use:

sinus = math::sin(i.to_f/10) 

that's still 5 iterations through sine wave. should enough prove network can learn arbitrary function.


Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

html - Fade out of a Mp3 song using javascript -