简体   繁体   English

在Java中逐步询问levenberg-marquardt

[英]ask step by step levenberg-marquardt in java

I'm trying to write levenberg marquardt in Java, here's my code: 我正在尝试用Java编写levenberg marquardt ,这是我的代码:

    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. 函数calc_jacobian是我用来计算前馈和反向传播运算以计算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. 函数koreksi_w用于使用Jacobian,误差,miu和实际权重来更新新权重,它将给出新的权重,并且test_ff计算前馈以获取mse值。

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. 我的问题是,当我尝试运行这些代码时,mse的值不会减少,因此我在matlab使用trainlm函数以相同的输入和权重运行,以证明输入和权重不是问题,并且matlabmse下降。

I don't understand your piece of code, but are you sure it is Integer division that you want when you do : 我不理解您的代码,但是确定执行此操作时要确定它是Integer division

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; 还要检查miu = miu / beta; (is beta a double ?) beta是两倍吗?)

I suspect MathLab does floating point division where java doesn't... 我怀疑MathLab在Java不执行的情况下进行浮点除法...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM