Sha256: b4d8ff93821ea1bda4ab381f17e42bc3d7f988eeac1e046698eb4b0211d6d4fb

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true
# This test was taken from ai4r gem

require File.dirname(__FILE__) + '/../lib/mlp'
require 'benchmark'

times = Benchmark.measure do
  srand 1

  a = MLP::Network.new(hidden_layers: [2], output_nodes: 1, inputs: 2)

  3001.times do |i|
    a.train([0, 0], [0])
    a.train([0, 1], [1])
    a.train([1, 0], [1])
    error = a.train([1, 1], [0])
    puts "Error after iteration #{i}:\t#{error}" if i % 200 == 0
  end

  puts 'Test data'
  puts "[0,0] = > #{a.feed_forward([0, 0]).inspect}"
  puts "[0,1] = > #{a.feed_forward([0, 1]).inspect}"
  puts "[1,0] = > #{a.feed_forward([1, 0]).inspect}"
  puts "[1,1] = > #{a.feed_forward([1, 1]).inspect}"
end

puts "Elapsed time: #{times}"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mlpnn-0.0.1 examples/xor.rb