A question about neural networks and backpropogation

blackllotus

Golden Member
May 30, 2005
1,875
0
0
I know the backpropogation algorithm has been replaced by newer algorithms, however I have never formally studied neural networks and have only recently started looking into them as a hobby. Anyways, my question is whether a network trained using backpropogation is guarenteed to converge on learnable functions. For example, I wrote some code for a network (3 layer) and tried to train it (with 3 hidden nodes) to do the XOR function. It succeeds around 75% of the time however 25% of the time it fails and doesn't converge within 100,000 training trials. Is this a bug with my code or a property of the network?
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Just some thoughts:

* Could you provide your code?

* What function are you applying to the sum of (inputs * weights) for the nonlinearity?

* What are you initializing the weights to? If you set them to be very far from zero, it can take an extremely long time to converge - especially if there's a gradient-descent type of thing going on and your function looks like this one (since the gradient is extremely shallow as you get far from the center).

* Are you using 0/+1 or -1/+1? I remember having issues when using 0/+1. I actually ended up using -.9 / +.9
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
I'm using tanh as the nonlinear function

Weights are initialized to random values between zero and one

I can post the code but its written in D
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Any reason you don't initialize between -1 and 1? Are you adding a negative bias? It's not clear to me how you would compute out = !in with one neuron.

edit: Or maybe out = in1 & !in2...
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
Originally posted by: CTho9305
Any reason you don't initialize between -1 and 1? Are you adding a negative bias? It's not clear to me how you would compute out = !in with one neuron.

edit: Or maybe out = in1 & !in2...

I changed it so it initializes between -1 and 1. The bias is positive 1. I'm trying to get the network to compute exclusive or with 2 input neurons, 3 hidden neurons, and 1 output neuron.

Btw, I don't know if this helps but when the network fails to converge the deltas are off the wall (like -2) for the output neuron.

EDIT: I also assume that this means that my code is bugged in which case this thread no longer belongs in HT. Thanks for the help.
 
Dec 29, 2005
89
0
0
i'll have to doublecheck my textbook, but i'm pretty sure a nn is not guaranteed to converge. that being said, i have used nn's on several problems and at first they didn't converge, but after changing some of the settings (acceptance criteria, learning rate) i was able to get them to converge.
also i don't know if you already have this implemented, but adding a momentum parameter to the weight calculation speeds up learning drastically. if you do not know what momentum is, basically you take a percentage of the last adjustment and add that to the newest adjustment. example:
(probably not realistic numbers here)
last adjustment delta_old = 1
new adjustment delta_new = 1
new weight = 1 (delta_new) + (1 * MOMENTUM)
where MOMENTUM is from 0 - 1.
usually momentum is set very high, .7 -.9

also my teacher mentioned to my class that some reasearchers say using a separate learning rate for the hidden layers helps out. for instance i implemented this with a learning rate of .3 on the outer layers, and .5 on the hidden layers, and seemed to work very well.
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
Alright I think I found my problem but I'm not entirely sure as to how to fix it

Activation function: tanh
Delta calculation (for output layer): (expected - actual) * actual * (1 - actual)

The delta will always be negative no more what combination of expected output value and actual output value is used. What is the correct equation?
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
What is the correct equation?

Dunno. Hope this helps:

Activation function:
float Perceptron::getValue() {
float x = LinearUnit::getValue();
float s = 1/(1+pow(E, (double)-x));
float rv = s * 2.0f - 1.0f;
return rv;
}

Training:
// Update our weights, and train our inputs
void LinearUnit::train(int aIteration) {
if (mTrainIteration == aIteration) {
cout << "already trained!" << endl;
return; // already trained
}

// Update our weights
// Compute error term d = o(1-o)(blame), use prevErr for d
float prevOutput = getValue();
float err = getError(aIteration);
float prevErr = prevOutput*(1-prevOutput)*err;

int inpSize = inputNodes.size();
for (int i=0; i<inpSize; i++) {
WeightedNode *wn = inputNodes BRACKET i BRACKET ;
float v = wn->n->getValue();
float eta = 0.3f;
float delta = -eta*prevErr*v;
wn->weight += delta;
}

mTrainIteration = aIteration;

// train our inputs
for (i=0; i<inpSize; i++) {
inputNodes BRACKET i BRACKET ->n->train(aIteration);
}
}
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
Thanks for the code CTho! Fixing my problem was as simple as fixing the activation function.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |