private void quadraticBacktrack(DoubleArray p, System.Func <DoubleArray, DoubleArray> function, DataBundle data) { double lambda0 = data.Lambda0; double g0 = data.G0; double lambda = Math.Max(0.01 * lambda0, g0 * lambda0 * lambda0 / (data.G1 + g0 * (2 * lambda0 - 1))); data.swapLambdaAndReplace(lambda); updatePosition(p, function, data); }
private void cubicBacktrack(DoubleArray p, System.Func <DoubleArray, DoubleArray> function, DataBundle data) { double temp1, temp2, temp3, temp4, temp5; double lambda0 = data.Lambda0; double lambda1 = data.Lambda1; double g0 = data.G0; temp1 = 1.0 / lambda0 / lambda0; temp2 = 1.0 / lambda1 / lambda1; temp3 = data.G1 + g0 * (2 * lambda0 - 1.0); temp4 = data.G2 + g0 * (2 * lambda1 - 1.0); temp5 = 1.0 / (lambda0 - lambda1); double a = temp5 * (temp1 * temp3 - temp2 * temp4); double b = temp5 * (-lambda1 * temp1 * temp3 + lambda0 * temp2 * temp4); double lambda = (-b + Math.Sqrt(b * b + 6 * a * g0)) / 3 / a; lambda = Math.Min(Math.Max(lambda, 0.01 * lambda0), 0.75 * lambda1); // make sure new lambda is between 1% & 75% of old value data.swapLambdaAndReplace(lambda); updatePosition(p, function, data); }