apply neural network to recognize digits

Viewed 579

I try to understand neural networks

I compose arrays of inputs as

..# ### ### #.#
.## ..# ..# #.#
..# ### ### ###
..# #.. ..# ..#
..# ### ### ..#, etc

desired ouptut I set as digit/10, i.e digit = 5 output = 0.5

the code

require 'ruby-fann'

train = RubyFann::TrainData.new(
  inputs: [
    [0,0,1,0,1,1,0,0,1,0,0,1,0,0,1],
    [1,1,1,0,0,1,1,1,1,1,0,0,1,1,1],
    [1,1,1,0,0,1,1,1,1,0,0,1,1,1,1],
    [1,0,1,1,0,1,1,1,1,0,0,1,0,0,1],
    [1,1,1,1,0,0,1,1,1,0,0,1,1,1,1],
    [1,1,1,1,0,0,1,1,1,1,0,1,1,1,1],
    [1,1,1,0,0,1,0,1,0,1,0,0,1,0,0],
    [1,1,1,1,0,1,1,1,1,1,0,1,1,1,1],
    [1,1,1,1,0,1,1,1,1,0,0,1,1,1,1]
  ],
  desired_outputs: [[0.1],[0.2],[0.3], [0.4], [0.5], [0.6], [0.7], [0.8], [0.9]]
)
fann = RubyFann::Standard.new(
  num_inputs: 15,
  hidden_neurons: [8,4,3,4,1],
  num_outputs: 1
)
fann.train_on_data(train, 100000, 10, 0.1) # 100000 max_epochs, 100 errors between reports and 0.1 desired MSE (mean-squared-error)
outputs = fann.run([0,0,1,0,1,1,0,0,1,0,0,1,0,0,1])
result = outputs.first
abort result.inspect

Outputs for each run script

0.5367386954219215
0.5141728468011051
0.5249739971144654
0.5373135467504666
0.5182686028674102
0.46710004502372293
0.4723526462690119
0.5306690734137796
0.5151398228322749
0.5359153267266001
0.469100790593523
0.4749347798092478
0.5094355973839471
0.5205985468860461
0.5277528652471375
0.4825827561254995

I don't understand why output don't equal 0.1, which totally identical with first input.

What means that values in 0.46 - 0.53 diapason?

UPDATE

I replace 0 with 0.1, and 1 with 0.9

Output

0.4794515462681635
0.5332274595769928
0.4601992972516728
0.427064909364266
0.43466252163025687
0.46931411920827737
0.4455544021835517
0.48051179013023565
0.4798245565677274
0.4479353078492235
0.4646710791032779
0.4887400910135108

Also I add +1 input for zero digit, nothing significantly happened

1 Answers
Related