protected void combinedStep(double regionRadius, DMatrixRMaj step) { // find the Cauchy point CommonOps_DDRM.scale(-distanceCauchy, direction, stepCauchy); stepLength = regionRadius; // touches the trust region double distancePtoGN = SpecializedOps_DDRM.diffNormF(stepCauchy,stepGN); double f = fractionCauchyToGN(distanceCauchy,distanceGN,distancePtoGN,regionRadius); CommonOps_DDRM.add(1-f,stepCauchy,f,stepGN,step); predictedReduction = owner.computePredictedReduction(step); }
protected void combinedStep(double regionRadius, DMatrixRMaj step) { // find the Cauchy point CommonOps_DDRM.scale(-distanceCauchy, direction, stepCauchy); stepLength = regionRadius; // touches the trust region double distancePtoGN = SpecializedOps_DDRM.diffNormF(stepCauchy,stepGN); double f = fractionCauchyToGN(distanceCauchy,distanceGN,distancePtoGN,regionRadius); CommonOps_DDRM.add(1-f,stepCauchy,f,stepGN,step); predictedReduction = owner.computePredictedReduction(step); }
/** * Randomly generate points in 2D and circles. Then see if a valid length can be found */ @Test public void fractionCauchyToGN_random() { for (int i = 0; i < 200; i++) { double r = rand.nextDouble()+1; double lengthP = 0.01+rand.nextDouble()*0.99*r; double lengthGN = r + rand.nextDouble(); double angleP = rand.nextDouble()*Math.PI*2.0; double angleGN = rand.nextDouble()*Math.PI*2.0; double x_p = Math.cos(angleP)*lengthP; double y_p = Math.sin(angleP)*lengthP; double x_gn = Math.cos(angleGN)*lengthGN; double y_gn = Math.sin(angleGN)*lengthGN; double dx = x_gn-x_p; double dy = y_gn-y_p; double lengthPtoGN = Math.sqrt(dx*dx + dy*dy); double fraction = TrustRegionUpdateDogleg_F64.fractionCauchyToGN(lengthP,lengthGN,lengthPtoGN,r); double x = x_p + fraction*dx; double y = y_p + fraction*dy; double found = Math.sqrt(x*x + y*y); assertEquals(r,found, UtilEjml.TEST_F64); } }
/** * Easy to derive solutions */ @Test public void fractionCauchyToGN_easy() { // Everything lies along a line double lengthPtoGN = 2; double found = TrustRegionUpdateDogleg_F64.fractionCauchyToGN(2,4,lengthPtoGN,2.5); assertEquals(0.5/lengthPtoGN,found,UtilEjml.TEST_F64); }