Search in sources :

Example 1 with Obj_Dbl

use of suite.primitive.DblPrimitives.Obj_Dbl in project suite by stupidsing.

the class GaussNewton method sym.

public float[] sym(Node[] vars, Node[] rs, float[] initials) {
    int nVars = vars.length;
    int nrs = rs.length;
    @SuppressWarnings("unchecked") Obj_Dbl<float[]>[] residualFuns = Array_.newArray(Obj_Dbl.class, nrs);
    Dbl_Dbl[][] gradientFuns = new Dbl_Dbl[nrs][nVars];
    for (int i = 0; i < nrs; i++) {
        Node r = rs[i];
        residualFuns[i] = sym.fun(r, vars);
        for (int j = 0; j < nVars; j++) {
            Node var = vars[j];
            gradientFuns[i][j] = sym.fun(sym.d(var, r), var);
        }
    }
    return gn(r -> {
        float[] residuals = new float[nrs];
        for (int i = 0; i < nrs; i++) residuals[i] = (float) residualFuns[i].apply(r);
        return residuals;
    }, betas -> {
        float[][] jacobian = new float[nrs][nVars];
        for (int i = 0; i < nrs; i++) for (int j = 0; j < nVars; j++) jacobian[i][j] = (float) gradientFuns[i][j].apply(betas[j]);
        return jacobian;
    }, initials);
}
Also used : Node(suite.node.Node) Dbl_Dbl(suite.primitive.Dbl_Dbl) Obj_Dbl(suite.primitive.DblPrimitives.Obj_Dbl)

Aggregations

Node (suite.node.Node)1 Obj_Dbl (suite.primitive.DblPrimitives.Obj_Dbl)1 Dbl_Dbl (suite.primitive.Dbl_Dbl)1