/** * Creates a sparse trust region optimization using cauchy steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixSparseCSC> cauchy( @Nullable ConfigTrustRegion config ) { if( config == null ) config = new ConfigTrustRegion(); HessianLeastSquares_DSCC hessian = new HessianLeastSquares_DSCC(); MatrixMath_DSCC math = new MatrixMath_DSCC(); TrustRegionUpdateCauchy_F64<DMatrixSparseCSC> update = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
@Override public void initialize(double[] initial, double ftol, double gtol) { this.initialize(initial,functionResiduals.getNumOfInputsN(),0); config.ftol = ftol; config.gtol = gtol; }
protected UnconLeastSqTrustRegion_F64<DMatrixRMaj> createAlg() { TrustRegionUpdateCauchy_F64<DMatrixRMaj> update = new TrustRegionUpdateCauchy_F64<>(); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(); MatrixMath_DDRM math = new MatrixMath_DDRM(); return new UnconLeastSqTrustRegion_F64<>(update,hessian,math); }
@Override protected UnconstrainedLeastSquares<DMatrixRMaj> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); config.regionInitial = 100; config.hessianScaling = true; UnconLeastSqTrustRegion_F64<DMatrixRMaj> tr = createSolver(); tr.configure(config); return tr; } }
@Test public void costFunction() { UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = createAlg(); alg.functionResiduals = new MockFunctionNtoM(new double[]{-1,2,-3},1); alg.residuals.reshape(3,1); double expected = 0.5*(1+4+9); double found = alg.cost(new DMatrixRMaj(1,1)); assertEquals(expected,found, UtilEjml.TEST_F64); }
private static UnconLeastSqTrustRegion_F64<DMatrixRMaj> createSolver() { LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.chol(2); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(solver); TrustRegionUpdateDogleg_F64<DMatrixRMaj> alg = new TrustRegionUpdateDogleg_F64<>(); return new UnconLeastSqTrustRegion_F64<>(alg,hessian, new MatrixMath_DDRM()); }
@Override protected UnconstrainedLeastSquares<DMatrixRMaj> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); config.regionInitial = -1; UnconLeastSqTrustRegion_F64<DMatrixRMaj> tr = createSolver(); tr.configure(config); return tr; } }
/** * Creates a dense trust region least-squares optimization using cauchy steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixRMaj> cauchy( @Nullable ConfigTrustRegion config ) { if( config == null ) config = new ConfigTrustRegion(); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(); MatrixMath_DDRM math = new MatrixMath_DDRM(); TrustRegionUpdateCauchy_F64<DMatrixRMaj> update = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
@Override public void initialize(double[] initial, double ftol, double gtol) { this.initialize(initial,functionResiduals.getNumOfInputsN(),0); config.ftol = ftol; config.gtol = gtol; }
/** * Creates a sparse trust region optimization using cauchy steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixSparseCSC> cauchy( @Nullable ConfigTrustRegion config ) { if( config == null ) config = new ConfigTrustRegion(); HessianLeastSquares_DSCC hessian = new HessianLeastSquares_DSCC(); MatrixMath_DSCC math = new MatrixMath_DSCC(); TrustRegionUpdateCauchy_F64<DMatrixSparseCSC> update = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
/** * Makes sure the specified tolerances are copied into the configuration */ @Test public void initialize() { UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = createAlg(); alg.functionResiduals = new MockFunctionNtoM(new double[]{1,2,3},3); alg.initialize(new double[]{1,2,3},2e-3,6e-12); assertEquals(2e-3,alg.config.ftol, UtilEjml.TEST_F64); assertEquals(6e-12,alg.config.gtol, UtilEjml.TEST_F64); }
/** * Creates a dense trust region least-squares optimization using cauchy steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixRMaj> cauchy( @Nullable ConfigTrustRegion config ) { if( config == null ) config = new ConfigTrustRegion(); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(); MatrixMath_DDRM math = new MatrixMath_DDRM(); TrustRegionUpdateCauchy_F64<DMatrixRMaj> update = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
/** * Creates a sparse trust region optimization using dogleg steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixSparseCSC> dogleg( @Nullable ConfigTrustRegion config) { if( config == null ) config = new ConfigTrustRegion(); LinearSolverSparse<DMatrixSparseCSC,DMatrixRMaj> solver = LinearSolverFactory_DSCC.cholesky(FillReducing.NONE); HessianLeastSquares_DSCC hessian = new HessianLeastSquares_DSCC(solver); MatrixMath_DSCC math = new MatrixMath_DSCC(); TrustRegionUpdateDogleg_F64<DMatrixSparseCSC> update = new TrustRegionUpdateDogleg_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
/** * Creates a sparse trust region optimization using dogleg steps. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixSparseCSC> dogleg( @Nullable ConfigTrustRegion config) { if( config == null ) config = new ConfigTrustRegion(); LinearSolverSparse<DMatrixSparseCSC,DMatrixRMaj> solver = LinearSolverFactory_DSCC.cholesky(FillReducing.NONE); HessianLeastSquares_DSCC hessian = new HessianLeastSquares_DSCC(solver); MatrixMath_DSCC math = new MatrixMath_DSCC(); TrustRegionUpdateDogleg_F64<DMatrixSparseCSC> update = new TrustRegionUpdateDogleg_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
/** * Creates a dense trust region least-squares optimization using dogleg steps. Solver works on the B=J<sup>T</sup>J matrix. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixRMaj> dogleg( @Nullable ConfigTrustRegion config, boolean robust ) { if( config == null ) config = new ConfigTrustRegion(); LinearSolverDense<DMatrixRMaj> solver; if( robust ) solver = LinearSolverFactory_DDRM.leastSquaresQrPivot(true,false); else solver = LinearSolverFactory_DDRM.chol(100); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(solver); MatrixMath_DDRM math = new MatrixMath_DDRM(); TrustRegionUpdateDogleg_F64<DMatrixRMaj> update = new TrustRegionUpdateDogleg_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
/** * Creates a dense trust region least-squares optimization using dogleg steps. Solver works on the B=J<sup>T</sup>J matrix. * * @see UnconLeastSqTrustRegion_F64 * * @param config Trust region configuration * @return The new optimization routine */ public static UnconstrainedLeastSquares<DMatrixRMaj> dogleg( @Nullable ConfigTrustRegion config, boolean robust ) { if( config == null ) config = new ConfigTrustRegion(); LinearSolverDense<DMatrixRMaj> solver; if( robust ) solver = LinearSolverFactory_DDRM.leastSquaresQrPivot(true,false); else solver = LinearSolverFactory_DDRM.chol(100); HessianLeastSquares_DDRM hessian = new HessianLeastSquares_DDRM(solver); MatrixMath_DDRM math = new MatrixMath_DDRM(); TrustRegionUpdateDogleg_F64<DMatrixRMaj> update = new TrustRegionUpdateDogleg_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> alg = new UnconLeastSqTrustRegion_F64<>(update,hessian,math); alg.configure(config); return alg; }
@Override protected UnconstrainedLeastSquares<DMatrixRMaj> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); config.hessianScaling = true; TrustRegionUpdateCauchy_F64<DMatrixRMaj> cauchy = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> tr = new UnconLeastSqTrustRegion_F64<>( cauchy, new HessianLeastSquares_DDRM(),new MatrixMath_DDRM()); tr.configure(config); return tr; }
@Override protected UnconstrainedLeastSquares<DMatrixRMaj> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); TrustRegionUpdateCauchy_F64<DMatrixRMaj> cauchy = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixRMaj> tr = new UnconLeastSqTrustRegion_F64<>( cauchy, new HessianLeastSquares_DDRM(),new MatrixMath_DDRM()); tr.configure(config); return tr; } }
@Override protected UnconstrainedLeastSquares<DMatrixSparseCSC> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); TrustRegionUpdateCauchy_F64<DMatrixSparseCSC> cauchy = new TrustRegionUpdateCauchy_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> tr = new UnconLeastSqTrustRegion_F64<>( cauchy, new HessianLeastSquares_DSCC(),new MatrixMath_DSCC()); tr.configure(config); return tr; } }
@Override protected UnconstrainedLeastSquares<DMatrixSparseCSC> createSearch(double minimumValue) { ConfigTrustRegion config = new ConfigTrustRegion(); config.regionInitial = 1; LinearSolverSparse<DMatrixSparseCSC,DMatrixRMaj> solver = LinearSolverFactory_DSCC.cholesky(FillReducing.NONE); HessianLeastSquares_DSCC hessian = new HessianLeastSquares_DSCC(solver); TrustRegionUpdateDogleg_F64<DMatrixSparseCSC> alg = new TrustRegionUpdateDogleg_F64<>(); UnconLeastSqTrustRegion_F64<DMatrixSparseCSC> tr = new UnconLeastSqTrustRegion_F64<>( alg,hessian, new MatrixMath_DSCC()); tr.configure(config); // tr.setVerbose(true); return tr; } }