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 665047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:40:02+00:00 2026-05-13T23:40:02+00:00

I have trained xor neural network in MATLAB and got these weights: iw: [-2.162

  • 0

I have trained xor neural network in MATLAB and got these weights:

iw: [-2.162 2.1706; 2.1565 -2.1688]

lw: [-3.9174 -3.9183]

b{1} [2.001; 2.0033]

b{2} [3.8093]

Just from curiosity I have tried to write MATLAB code which computes the output of this network (two neurons in the hidden layer, and one in the output, TANSIG activation function).

Code that I got:

l1w = [-2.162 2.1706; 2.1565 -2.1688];
l2w = [-3.9174 -3.9183];
b1w = [2.001 2.0033];
b2w = [3.8093];

input = [1, 0];

out1 = tansig (input(1)*l1w(1,1) + input(2)*l1w(1,2) + b1w(1));
out2 = tansig (input(1)*l1w(2,1) + input(2)*l1w(2,2) + b1w(2));
out3 = tansig (out1*l2w(1) + out2*l2w(2) + b2w(1))

The problem is when input is lets say [1,1], it outputs -0.9989, when [0,1] 0.4902. While simulating network generated with MATLAB outputs adequately are 0.00055875 and 0.99943.

What am I doing wrong?

  • 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-13T23:40:02+00:00Added an answer on May 13, 2026 at 11:40 pm

    I wrote a simple example of an XOR network. I used newpr, which defaults to tansig transfer function for both hidden and output layers.

    input = [0 0 1 1; 0 1 0 1];               %# each column is an input vector
    ouputActual = [0 1 1 0];
    
    net = newpr(input, ouputActual, 2);       %# 1 hidden layer with 2 neurons
    net.divideFcn = '';                       %# use the entire input for training
    
    net = init(net);                          %# initialize net
    net = train(net, input, ouputActual);     %# train
    outputPredicted = sim(net, input);        %# predict
    

    then we check the result by computing the output ourselves. The important thing to remember is that by default, inputs/outputs are scaled to the [-1,1] range:

    scaledIn = (2*input - 1);           %# from [0,1] to [-1,1]
    for i=1:size(input,2)
        in = scaledIn(:,i);             %# i-th input vector
        hidden(1) = tansig( net.IW{1}(1,1)*in(1) + net.IW{1}(1,2)*in(2) + net.b{1}(1) );
        hidden(2) = tansig( net.IW{1}(2,1)*in(1) + net.IW{1}(2,2)*in(2) + net.b{1}(2) );
        out(i) = tansig( hidden(1)*net.LW{2,1}(1) + hidden(2)*net.LW{2,1}(2) + net.b{2} );
    end
    scaledOut = (out+1)/2;              %# from [-1,1] to [0,1]
    

    or more efficiently expressed as matrix product in one line:

    scaledIn = (2*input - 1);           %# from [0,1] to [-1,1]
    out = tansig( net.LW{2,1} * tansig( net.IW{1}*scaledIn + repmat(net.b{1},1,size(input,2)) ) + repmat(net.b{2},1,size(input,2)) );
    scaledOut = (1 + out)/2;            %# from [-1,1] to [0,1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a well trained neural network consisting of about 40 input neurons and
I have created a neural network and the performance is good. By using nprtool,
I have an AI project, which uses a Backpropagation neural network. It is training
I have an artificial intelligence project, it has trained neural networks (The neural networks
I am currently building a Neural Network library. I have constructed it as an
I have a restfull webservice that requires loading trained model files and to create
I have a classifier that I trained using Python's scikit-learn. How can I use
i have a trained j48 classifier and i want to classify one record by
I have trained a NN with Back Propagation algorithm and calculated the MSE. Now
I have successfully trained a classifier (bayesnet) and constructed a test set (ARFF-format), which

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.