public static Vector2 FindMin(Vector2 x0, double eps) { double alpha; double f; Vector2 grad; int i = 0; Vector2 x; do { //Устанавливаем максимальное значение alpha alpha = alphaMax; //Вычисляем градиент в x_k grad = Rosenbrock.Gradient(x0); //Проверяем условие Армихо do { i++; alpha *= 0.75; x = x0 - alpha * grad; f = -(Rosenbrock.F(x) - Rosenbrock.F(x0)) / (alpha * grad.Norm * grad.Norm); } while (!((delta1 <= f) && (f <= delta2))); x = x0.Copy(); x0 -= alpha * Rosenbrock.Gradient(x0); }while(grad.Norm > eps); Console.WriteLine("Iterations:\t{0}", i); return(x); }
public static Vector2 FindMin(Vector2 x, double EPS) { int i = 0; double alpha; Vector2 grad = Rosenbrock.Gradient(x); Vector2 d = -1 * Rosenbrock.Gradient(x); double prevGradSquare; do { i++; prevGradSquare = grad.Norm * grad.Norm; alpha = Rosenbrock.GoldenSearch(x, d); x += alpha * d; grad = Rosenbrock.Gradient(x); if (i % 2 == 0) { d = -1 * grad; } else { double beta = grad.Norm * grad.Norm / prevGradSquare; d = beta * d - grad; } } while(d.Norm > EPS); Console.WriteLine("Iterations:\t{0}", i); return(x); }
public static Vector2 FindMin(Vector2 p, double eps) { Vector2 p0; double[,] H; Vector2 grad; do { p0 = p.Copy(); H = Newton.InverseHessian(p0); grad = Rosenbrock.Gradient(p0); p -= (H * grad); } while ((p - p0).Norm > eps); return(p); }
public static Vector2 FindMin(Vector2 point, double EPS) { Vector2 delta = new Vector2(0.1, 0.1); Vector2 df; Vector2 dfPrev = new Vector2(0, 0); int k = 0; do { k++; df = Rosenbrock.Gradient(point); for (int i = 0; i < 2; i++) { double product = df[i] * dfPrev[i]; if (product > 0) { delta[i] = Math.Min(delta[i] * etaPlus_, deltaMax_); point[i] -= Math.Sign(df[i]) * delta[i]; dfPrev[i] = df[i]; } else if (product < 0) { delta[i] = Math.Max(delta[i] * etaMinus_, deltaMin_); dfPrev[i] = 0; } else { point[i] -= Math.Sign(df[i]) * delta[i]; dfPrev[i] = df[i]; } } } while (df.Norm > 1e-7); Console.WriteLine("Iterations:\t{0}", k); return(point); }