I have a neural network that contains 2 input neurons, 1 hidden layer containing 2 neurons, and one output neuron. I am using this neural network for the XOR problem, but it does not work.
Test Results:
If you test 1, 1 you get the output of -1 (equivalent to 0).
If you test -1, 1 you get the output of 1.
If you test 1, -1 you get the output of 1.
If you test -1, -1 you get the output of 1.
This last test is obviously incorrect, therefore my neural network is clearly wrong somewhere.
The exact output are here
So as you can see, changing 1, 1 to -1, -1 just flips the output value
And changing -1, 1 to 1, -1 does the same. This is obviously incorrect.
These are the steps my neural network goes through:
Randomly assign the weights between -1, 1
Forward propagate through the network (applying the tanh activation function to the hidden neurons and the output neuron)
Back propagate using the algorithm explained at this website: https://stevenmiller888.github.io/mind-how-to-build-a-neural-network/ (is this algorithm correct?)
I need to know if I am missing something in my neural network, and I was also wondering if anyone knew of a tutorial for back propagation that is less mathematical and more pseudo-code style.
Also, I am not using biases or momentum within my neural network, so I was wondering if adding either of them would fix the issue?
I have tried a few different back propagation algorithms and none of them seem to work, so it is most likely not that.
Thanks for any help you can provide,
Finley Dabinett.
UPDATE:
I have added biases to the hidden and output layer and I get these results:
1, 1 = -1 - Correct
-1, -1 = 1 - Incorrect
-1, 1 = 1 - Correct
1, -1 = 1 - Correct
Related
I'm reviewing for my midterm and this specific question is causing me some issues.
This is the following array to perform the binary search:
the value I want to search for is 150.
To start off, I take the first element which is 0, and the last element which is 15.
(start + end) / 2,
(0 + 15) / 2 = 7
The value at the array of 7 is 90.
90 < 150, so the value is contained in the right side of the array.
The array now looks like this:
Continuing with the same logic
(start + end) / 2
(8 + 15) / 2 = 11.
However, according to the professor I should be at the value 12 here. I'm not sure what i am doing wrong. Any help would be appreciated.
The algorithms were written even before the computers were invented.
Computers are simply a tool or a device which implements the algorithm in an efficient manner which is why it is fast.
The binary search which you are performing here is relevant to computers as the array are indexed from 0 (counting usually starts from 0 in computers), that is why you are getting 11 which is correct in point of computers.
But for the humans counting starts from 1 and the so the result according to professor is 12.
While writing algorithms we write in according to the perception of the human and we twist it a little to implement in our machine.
I try to solve SAT Problem in particular 3-SAT. My dataset is from SATLIB and I use Neuroph to create Neural Network. In my data set a phrase's clauses are represented like:
1 -2 0
2 3 0
-3 2 0
where 0 - end of clause, {1,2,3} - variables, "-"(minus sign) - negation. A.k.a. this is equal to:
(a^(not)b)v(b^b)v((not)c^b)
My problem is that don't know how to represent this like input for Neural Network. On base of this answer I will choose properly input nodes that I need.
P.S: I don't know is it important but NN output must be answer of "Can the phrase be satisfied?".
Is it possible to solve this problem with a solution which has time complexity better than linear?
N light bulbs are connected by a wire. Each bulb has a switch associated with it, however due to faulty wiring, a switch also changes the state of all the bulbs to the right of current bulb. Given an initial state of all bulbs, find the minimum number of switches you have to press to turn on all the bulbs. You can press the same switch multiple times.
Note : 0 represents the bulb is off and 1 represents the bulb is on.
Input : [0 1 0 1]
Steps:
press switch 0 : [1 0 1 0]
press switch 1 : [1 1 0 1]
press switch 2 : [1 1 1 0]
press switch 3 : [1 1 1 1]
Return : 4
This is called a "Lights Out" riddle:
http://mathworld.wolfram.com/LightsOutPuzzle.html
One speed improvement I could think off would be to paralellise the setting of all the bulbs to the right. In particular a GPU might be able to do that effectively (I am not sure as you need to change wich elements are effected with each loop).
Maybe making it a proper boolean Array and bitwise XOR-ing a pattern onto the array?
Unless the real process is a lot more complex then XOR-ing boolean values, memory speed will be the bottleneck here - not CPU time.
Unless this is for purely academic purposes, the performance rant propably applies:
http://ericlippert.com/2012/12/17/performance-rant/
I have a function f(n) which returns sum from 1 to n ie
f(1)=1
f(2)=3
f(3)=6
Suppose this function have some issue and n can range from 1 to 100000.
How can i test it by providing minimum number of test cases. like n=1 can be 1 test case. n=50 can be another test case.
I mean is there any algorithm which can generate what all inputs can i test to ensure that all input from 1 to 100000 are working fine.
A common cliche in software testing is that you can never test every possible case. In a bounded and simple case such as your example, testing the entire range of input is possible, but it's not worth it. So, we take a more pragmatic approach -- this means working fine in happy paths and gracefully failing (in the case of computer programs) in invalid scenarios.
Let us look at your example :
f(n) = 1+2+...+n
What's the least possible input: 1 -- this input has only one item in the series. So, test for that value of n.
f(1) = 1?
Next, for n=2...100000, does it make a difference if you pick 2 or 100 or 10000 or 987? No. So, test for any one or two of them, picked at random.
Say, f(10)=55?
Next, the negative cases: does your function operate only within the range? Here comes the tricky part, there are endless possibilities.
For the lower bounds, one can test for n=0 and some negative number?
f(0) and f(-1) throws exception?
For the higher bounds,
The hope is people would stop at 100000 and not over it.
Test for 100000 - make sure, it still works. And test another large number to make it fail.
f(100000) = 4999950000?
f(100001) throws exception?
However, even this is too much. f(10) is redundant, because f(100000) and f(1) already test if the addition is right. (We expect the programmer did not write code saying fail for everything except 1 and 100000!).
That leaves the n values: -1, 0, 1, 100000, 100001
Recently I had an exam where we were tested on logic circuits. I encountered something on that exam that I had never encountered before. Forgive me for I do not remember the exact problem given and we have not received our grade for it; however I will describe the problem.
The problem had a 3 or 4 inputs. We were told to simplify then draw a logic circuit design for that simplification. However, when I simplified, I ended up eliminating the other inputs and ended up literally with just
A
I had another problem like this as well where there was 4 inputs and when I simplified, I ended up with three. My question is:
What do I do with the eliminated inputs? Do I just not have it on the circuit? How would I draw it?
Typically an output is a requirement which would not be eliminated, even if it ends up being dependent on a single input. If input A flows through to output Y, just connect A to Y in the diagram. If output Y is always 0 or 1, connect an incoming 0 or 1 to output Y.
On the other hand, inputs are possible, not required, factors in the definition of the problem. Inputs that have no bearing on the output need not be shown in the circuit diagram at all.
Apparently it not eliminating inputs but the resulted expression is the simplified outcome which you need to think of implementing with logic circuit.
As an example if you have a expression given with 3 inputs namely with the combination of A, B & c, possible literals can be 2^9 = 9 between 000 through 111. Now when you said your simplification lead to just A that mean, when any of those 9 input combinations will result in to value which contain by A.
An example boolean expression simplified to output A truth table is as follows,
A B | Output = A
------------------
0 0 | 0
0 1 | 0
1 0 | 1
1 1 | 1