I'm trying to write levenberg marquardt
in Java, here's my code:
while (iter <= 10 || mse < 0.0001) {
call.calc_jacobian(ff, trainlm, input, akt1, akt2, w, x, t);
double[][] jacobian = trainlm.ret_jacob();
double[][] error = trainlm.ret_err();
mse = trainlm.ret_mse() / 4;
mse_all[iter] = mse;
test: for (int m = 0; m <= 5; m++) {
upb.koreksi_w(miu, hidden, jacobian, error, w);
double[][] w_new = upb.ret_upw();
call.test_ff(ff, trainlm, input, akt1, akt2, w_new, x, t);
double mse2 = trainlm.ret_mse() / 4;
if (mse2 < mse || m == 5) {
miu = miu / beta;
w_skrg = w_baru;
iter++;
break test;
} else {
miu = miu * beta;
}
}
}
The function calc_jacobian
is a function I use to compute feed-forward and back-propagate operation to calculate the value of Jacobian. The function koreksi_w
use to update new weight using Jacobian, error, miu, and actual weight, it will give a new weight and test_ff
calculate feedforward to get mse
value.
My problem is that when I try to run those code, the value of mse doesn't decrease, so I use trainlm
function in matlab
to run with the same input & weight, to prove that input & wight isn't the problem and in matlab
, the mse
decrease.
I don't understand your piece of code, but are you sure it is Integer division
that you want when you do :
mse = trainlm.ret_mse() / 4; //OR:
double mse2 = trainlm.ret_mse() / 4;
As you expect a double, I would suggest a cast or something like so :
double mse2 = trainlm.ret_mse() / (double)4; //OR:
double mse2 = trainlm.ret_mse() / 4.0;
Check also miu = miu / beta;
(is beta
a double ?)
I suspect MathLab
does floating point division where java doesn't...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.