I am new in neural network and I am trying to figure out how to build a feed-forward neural network to solve a classification problem defined in the following way (X1, X2 being the features and Y the target):

if X1>0 and X2>0 then Y=1

if X1<0 and X2>0 then Y=0

if X1>1 and X2<0 then Y=1

if X1<1 and X2<0 then Y=0

If someone could at least give me a clue



2 Answers 2


Try simplifying your set of rules to a simpler set of rules (one with fewer rules).

What nodes are you allowed to use? I assume you can use some sort of a threshold node to produce the zeros and ones.

Can you do these problems well with only one feature (positive goes to 1 and negative goes to zero)?


I misread the last rule before thinking it said X1 < 0. It's quite easy to do it in three layers (counting the output layer) as long as you can,

1) construct a node asking if the input is greater than a certain value.

2) construct a node performing "and" on two outputs from the previous layer.

Are these things you can handle? Am I correct in assuming you need to cut out one layer? It's possible but harder to lead you there.

(In the future I suggest adding more information by editing your original question)

  • $\begingroup$ Thanks for your answer. To have less rules I could say: if x1>1 or (x2>0 and x1>0) then y=1 else y=0 It has to be a two layers feed-forward neural network with threshold (I think by two layers they don't count the input layer). How would you move from 2 to 1 feature? $\endgroup$ Sep 10, 2015 at 8:13
  • $\begingroup$ Edited my answer $\endgroup$ Sep 10, 2015 at 20:46
  • $\begingroup$ You don't have to simplify your rules or use less features (by features I assume you mean inputs into the network?) Just feed it examples where x1 and x2 are randomly generated and calculate the target Y using a straightforward function that doesn't involve a neural network. $\endgroup$
    – Frobot
    Dec 16, 2015 at 5:12

Ah the old XOR problem. This has been written about at length. See here: https://web.stanford.edu/group/pdplab/pdphandbook/

Ultimately, this can be solved with a fully connected 1 hidden layer network. You need two input nodes to read in your input pattern, a two-node hidden layer, and a single output node. Then train with stochastic gradient descent.

Consider a network with input nodes $i_0$ and $i_1$, hidden nodes $h_0$ and $h_1$ and output node $o$ and a sigmoid activation function.

One solution would have strong positive weights from both input nodes to $h_0$ and weak positive weights from both input nodes to $h_1$. $h_0$ will have a weak negative bias weight and $h_1$ will have a strong negative bias weight. $h_0$ will have a strong positive weight to $o$ and $h_1$ will have a strong negative weight to $o$. Finally, $o$ will have a weak negative bias.

It might help to draw a diagram of this configuration and walk yourself through how the activation would flow for each of the possible 4 input patterns.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.