Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:34:10+00:00 2026-05-18T04:34:10+00:00

I am trying to train a feedforward network to work to perform an XOR

  • 0

I am trying to train a feedforward network to work to perform an XOR operations with the Ruby Library AI4R. However,
when I evaluate for the XOR after training it. I am not getting the correct output. Has anyone used this library before
and gotten it to learn the XOR operation.

I am using two input neurons, three neurons in a hidden layer, and one layer for the output, as I saw a precomputed
XOR feed forward neural network like this before.

require "rubygems"
require "ai4r"

# Create the network with:
 #   2 inputs
 #   1 hidden layer with 3 neurons
 #   1 outputs
 net = Ai4r::NeuralNetwork::Backpropagation.new([2, 3, 1])  

 example = [[0,0],[0,1],[1,0],[1,1]]
 result = [[0],[1],[1],[0]]

 # Train the network
 400.times do |i|
   j = i % result.length
   puts net.train(example[j], result[j])
 end

 # Use it: Evaluate data with the trained network
puts "evaluate 0,0: #{net.eval([0,0])}"  # =>  evaluate 0,0: 0.507531383375123
puts "evaluate 0,1: #{net.eval([0,1])}"  # =>  evaluate 0,1: 0.491957823618629
puts "evaluate 1,0: #{net.eval([1,0])}"  # =>  evaluate 1,0: 0.516413912471401
puts "evaluate 1,1: #{net.eval([1,1])}"  # =>  evaluate 1,1: 0.500197884691668

Ted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:34:11+00:00Added an answer on May 18, 2026 at 4:34 am

    You haven’t trained it for enough iterations. If you change 400.times to 8000.times you’ll come much closer (and closer still at 20000.times).

    At 20000.times, I get

    puts "evaluate 0,0: #{net.eval([0,0])}"  # =>  evaluate 0,0: 0.030879848321403
    puts "evaluate 0,1: #{net.eval([0,1])}"  # =>  evaluate 0,1: 0.97105714994505
    puts "evaluate 1,0: #{net.eval([1,0])}"  # =>  evaluate 1,0: 0.965055940880282
    puts "evaluate 1,1: #{net.eval([1,1])}"  # =>  evaluate 1,1: 0.0268317078331645
    

    You can also increase net.learning_rate (but not too much).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to train an ANN (I use this library: http://leenissen.dk/fann/ ) and the
I'm trying to understand how to train a multilayer; however, I'm having some trouble
The problem I've encountered after trying to train neural networks isn't a new one
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
A little left field, but I'm trying to train a speech recognition program and
I'm trying to learn Haskell and after an article in reddit about Markov text
I'm trying to list the latest destination (MAX departure time) for each train in
I trying to train haar cascade classificator for card suite detection (which no rotation
I'm trying to create a personalized smilies system to train my JavaScript. To accomplish
I'm trying to mixin the MultiMap trait with a HashMap like so: val children:MultiMap[Integer,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.