public static OptimisationReport runNewton(MatrixChains chains, double[] angles) { System.out.println("f: " + Newton.f(chains, angles)); System.out.println(); DenseMatrix64F dby1 = Newton.get1d(chains, angles); System.out.println("dby1: " + dby1); System.out.println("numDiff: " + Newton.numDiff1d(chains, angles, 1e-6)); System.out.println(); DenseMatrix64F dby11 = Newton.get2d(chains, angles); System.out.println("dby11: " + dby11); System.out.println("numDiff: " + Newton.numDiff2d(chains, angles, 1e-5)); OptimisationReport report = runNewtonRun(chains, angles, 25); if (report.gradn >= chains.tolerance) { report.status = "FAILED"; } else { int minIndex = diagnoseEigenvalues(report.eigenvalues); if (minIndex == -1) { report.status = "RIGID"; } else { report.status = "LOOSE"; chains.regularise = 1e-1; chains.initialPoint = angles; System.out.println("Beginning 2nd run with regularisation " + chains.regularise); report = runNewtonRun(chains, angles, 30); report.status = (report.gradn >= chains.tolerance) ? "LOOSE-FAILED" : "LOOSE"; System.out.println("Original vector was " + printVec(angles)); chains.regularise = 1e-4; chains.initialPoint = report.angles; System.out.println("Beginning 3nd run with regularisation " + chains.regularise); report = runNewtonRun(chains, report.angles, 30); report.status = (report.gradn >= chains.tolerance) ? "LOOSE-FAILED" : "LOOSE"; System.out.println("Original vector was " + printVec(angles)); } } System.out.println("Optimisation concluded - the configuration is " + report.status); return report; }
public static OptimisationReport runNewtonRun(MatrixChains chains, double[] angles, int maxit) { OptimisationReport togo = null; for (int i = 0; i < maxit; ++i) { boolean printStep = true; // ((i + 1) % 24) == 0; if (printStep) { System.out.println("Step " + i); } togo = Newton.nstep(chains, angles, printStep); angles = togo.angles; double nval = togo.gradn; if (printStep) { System.out.println("gradn: " + nval); System.out.println(); } if (nval < chains.tolerance) { break; } } System.out.println(Newton.get2d(chains, angles)); return togo; }