 |
 |
 |
 |
 |
 |
 |
 |  primo |
|  |  |  |  |  | posted 6/24/2012 09:15 |      |  |  |  |  |  |  |  |  | hello everyone. im currently doing final year project for my degree. but i have problem with my coding. my MSE while training the data keep on giving the same value.
i have no idea whats wrong with the codes.
input = 2500, hiddenlayer=40, output=2, data=10.
so here's the codes:
int epoch = 0;
double temp_dotproduct = 0.0;
double dot;
double mean_sumE = 1.0;
double sumE = 0.0;
while(mean_sumE > 0.001 && epoch < 100000)
{
sumE = 0.0;
mean_sumE = 0.0;
for(int data=0; data < 10; data++)//sample data
{
//actual output for hidden neuron
for (int row5 = 0; row5 < 40; row5++)//hidden
{
temp_dotproduct = 0.0;
for (int col5 = 0; col5 < 2500; col5++)
{
dot = weight_inputhidden[row5][col5] * input[data][col5];
temp_dotproduct = temp_dotproduct + dot;
}
actual_hidden[row5] = sigmoid(temp_dotproduct-threshold_hidden[row5]);
}
//actual output for output neuron
for(int row6=0; row6 < 2; row6++)
{
temp_dotproduct = 0.0;
for(int col6=0; col6 < 40; col6++)
{
dot = actual_hidden[col6]*weight_hiddenoutput[row6][col6];
temp_dotproduct = temp_dotproduct + dot;
}
actual_output[row6] = sigmoid(temp_dotproduct-threshold_output[row6]);
temp_dotproduct = 0.0;
}
//calculate error of output
double errortemp = 0;
for(int row7=0; row7 < 2; row7++)
{
error[data][row7] = target[data][row7] - actual_output[row7];
sumE = sumE + Math.pow(error[data][row7],2);
sumE = Math.round(sumE*10000.0)/10000.0;
}
//error gradient output
for(int row8 = 0; row8 < 2; row8++)
{
error_gradient_output[row8] = actual_output[row8] * (1-actual_output[row8])*(error[data][row8]);
deltathreshold_output[row8] = alpha*-1*error_gradient_output[row8];
}
//delta weight of hidden to output
for(int row9 = 0; row9 < 2; row9++)
{
for(int col9 = 0; col9 < 40; col9++)
{
deltaweight_hiddenoutput[row9][col9]=alpha*actual_hidden[col9]*error_gradient_output[row9];
}
}
//error gradient of hidden
for(int col10=0; col10<40; col10++)
{
for(int row10=0; row10<2; row10++)
{
error_gradient_hidden[col10] += actual_hidden[col10]*(1-actual_hidden[col10])*error_gradient_output[row10]*weight_hiddenoutput[row10][col10];
deltathreshold_hidden[col10]=alpha*-1*error_gradient_hidden[col10];
}
}
//delta weight input to hidden
for(int row11=0; row11<40; row11++)
{
for(int col11=0; col11<2500; col11++)
{
deltaweight_inputhidden[row11][col11]=alpha*input[data][col11]*error_gradient_hidden[row11];
}
}
//update weight
for(int row12=0; row12<2; row12++)
{
threshold_output[row12] = threshold_output[row12]+deltathreshold_output[row12];
for(int col12=0; col12<40; col12++)
{
weight_hiddenoutput[row12][col12]=weight_hiddenoutput[row12][col12]+deltaweight_hiddenoutput[row12][col12];
}
}
for(int row13=0; row13<40; row13++)
{
threshold_hidden[row13] = threshold_hidden[row13]+deltathreshold_hidden[row13];
for(int col13=0; col13<2500; col13++)
{
weight_inputhidden[row13][col13]=weight_inputhidden[row13][col13]+deltaweight_inputhidden[row13][col13];
}
}
}//End of data sample
mean_sumE = sumE/12;
System.out.println("Mean square error: "+mean_sumE);
epoch++;
}// end of while looping
System.out.println("Epoch: "+epoch);
System.out.println("MSE: "+mean_sumE);
System.out.println("Output 1: "+actual_output[0]);
System.out.println("Output 2: "+actual_output[1]);
}
}
// hope u guys can help me =)
|  |  |
|
 |
|
 |
 |