Note that there are some explanatory texts on larger screens.

plurals
  1. POMultilayer perceptron - backpropagation
    primarykey
    data
    text
    <p>I have a school project to program multilayer perceptron that classify data into three classes. I have implemented backpropagation algorithm from <a href="http://home.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html" rel="nofollow">http://home.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html</a>. I have checked my algorithm (by manually calculating each step of backpropagation) if it really meets this explained steps and it meets. </p> <p>For classifing I am using one-hot code and I have inputs consisting of vectors with 2 values and three output neurons (each for individual class). After each epoch I shuffle input data. For classification I am using sigmoid function. I tried to implement softmax too, but I haven't found how looks derivative softmax. Is derivative softmax needed in weights adjusting? For checking if network successfully classified input, I am comparing if position of an output neuron with maximal output from output neurons is corresponding to position from current input one-hot code vector that equals 1.</p> <p>But my implementation doesn't train this neural network. I am working on this and debugging several days and looking on internet to find what I am doing wrong but I haven't find answer. I really don't know where I am making mistake. My neural network will successfully train when I have 10 inputs, but when I have 100, 200, 400 and 800 inputs it start cycling when it have one-half good classified inputs. As I said my backpropagation algorithm is good. Whole C++ project in Visual Studio 2010 with input files is here: <a href="http://www.st.fmph.uniba.sk/~vajda10/mlp.zip" rel="nofollow">http://www.st.fmph.uniba.sk/~vajda10/mlp.zip</a></p> <p>Structures:</p> <pre><code> struct input { vector&lt;double&gt; x; vector&lt;double&gt; cls; }; struct neuron { double output; double error; neuron(double o, double e): output(o), error(e) { }; }; </code></pre> <p>Global variables:</p> <pre><code> double alpha = 0.5; vector&lt;vector&lt;input&gt;&gt; data; vector&lt;vector&lt;neuron&gt;&gt; hiddenNeurons; vector&lt;neuron&gt; outputNeurons; vector&lt;vector&lt;vector&lt;double&gt;&gt;&gt; weights; </code></pre> <p>Here is my code for backpropagation algorithm:</p> <pre><code> for (int b = 0; b &lt; data[0].size(); b++) { // calculate output of hidden neurons for (int i = 0; i &lt; hiddenNeurons.size(); i++) { for (int j = 0; j &lt; hiddenNeurons[i].size(); j++) { double activation = neuronActivation(0, b, i, j); hiddenNeurons[i][j].output = sigmoid(activation); } } double partError = 0; // calculate output and errors on output neurons for (int k = 0; k &lt; outputNeurons.size(); k++) { double activation = neuronActivation(0, b, hiddenNeurons.size(), k); outputNeurons[k].output = sigmoid(activation); outputNeurons[k].error = data[0][b].cls[k] - outputNeurons[k].output; partError += pow(outputNeurons[k].error, 2); } error += sqrt(partError)/outputNeurons.size(); // if classification is wrong if (data[0][b].cls[maxOutputIndex(outputNeurons)] != 1) { wrongClass++; // error backpropagation for (int i = hiddenNeurons.size()-1; i &gt;= 0; i--) { for (int j = 0; j &lt; hiddenNeurons[i].size(); j++) { hiddenNeurons[i][j].error = 0.0; if (i &lt; hiddenNeurons.size()-1) { for (int k = 0; k &lt; hiddenNeurons[i+1].size(); k++) { hiddenNeurons[i][j].error += hiddenNeurons[i+1][k].error * weights[i+1][j][k]; } } else { for (int k = 0; k &lt; outputNeurons.size(); k++) { hiddenNeurons[i][j].error += outputNeurons[k].error * weights[i+1][j][k]; } } } } // adjust weights for (int i = 0; i &lt; weights.size(); i++) { int n; if (i &lt; weights.size()-1) { n = hiddenNeurons[i].size(); } else { n = outputNeurons.size(); } for (int k = 0; k &lt; n; k++) { for (int j = 0; j &lt; weights[i].size(); j++) { double y; if (i == 0) { y = data[0][b].x[j]; } else { y = hiddenNeurons[i-1][j].output; } if (i &lt; weights.size()-1) { weights[i][j][k] += alpha * hiddenNeurons[i][k].error * derivedSigmoid(hiddenNeurons[i][k].output) * y; } else { weights[i][j][k] += alpha * outputNeurons[k].error * derivedSigmoid(outputNeurons[k].output) * y; } } } } } } </code></pre> <p>Please, can anyone tell me what I am doing wrong or give me an advice to where I must to look for a mistake? I hope that I have told everything important. Please, forgive me my bad english.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload