def __call__(self, data: InputData) -> ResultData: (x, y) = data.initial path = [(x, y)] grad = (data.df_dx1(x, y), data.df_dx2(x, y)) calls_count = 2 f_calls = 0 while (grad[0]**2 + grad[1]**2) >= data.eps**2: (t_x, t_y) = (x - self.alpha * grad[0], y - self.alpha * grad[1]) f_calls += 2 if data.function(t_x, t_y) > data.function( x, y) - self.delta * self.alpha * (grad[0]**2 + grad[1]**2): self.alpha *= self.delta continue (x, y) = (t_x, t_y) grad = (data.df_dx1(x, y), data.df_dx2(x, y)) calls_count += 2 path.append((x, y)) return ResultData(self.name, (x, y), data.function(x, y), f_calls, calls_count, path)
def __call__(self, data: InputData) -> ResultData: (x, y) = data.initial x0 = (x, y) x1 = (x + self.length, y) x2 = (x, y + self.length) xk = [x0, x1, x2] f_calls = 3 path = [x0] fk = [data.function(xi[0], xi[1]) for xi in xk] while sum([(xk[i][0] - xk[0][0])**2 + (xk[i][1] - xk[0][1])**2 for i in range(1, 3)]) / 2 > data.eps**2: min_i = min(range(3), key=lambda i: fk[i]) max_i = max(range(3), key=lambda i: fk[i]) c_x = 0 c_y = 0 for i in range(3): if i != max_i: c_x += xk[i][0] c_y += xk[i][1] c_x /= 2 c_y /= 2 u_k = (2 * c_x - xk[max_i][0], 2 * c_y - xk[max_i][1]) f_u = data.function(u_k[0], u_k[1]) if f_u < fk[max_i]: xk[max_i] = u_k fk[max_i] = f_u f_calls += 1 else: for i in range(0, 3): xk[i] = ((xk[i][0] + xk[min_i][0]) / 2, (xk[i][1] + xk[min_i][1]) / 2) fk[i] = data.function(xk[i][0], xk[i][1]) f_calls += 2 path.append(xk[0]) return ResultData(self.name, xk[0], fk[0], f_calls, 0, path)
def __call__(self, data: InputData) -> ResultData: (x, y) = data.initial h = self.h calls_count = 0 path = [(x, y)] while h > self.delta: x1 = x y1 = y f = data.function(x, y) if data.function(x + h, y) < f: x1 += h if data.function(x - h, y) < f: x1 -= h if data.function(x, y + h) < f: y1 += h if data.function(x, y - h) < f: y1 -= h calls_count += 5 if (x1, y1) == (x, y): h /= 2 continue x += self.lambd * (x1 - x) y += self.lambd * (y1 - y) path.append((x, y)) return ResultData(self.name, (x, y), data.function(x, y), calls_count, 0, path)
def __call__(self, data: InputData) -> ResultData: (x, y) = data.initial path = [(x, y)] grad = (data.df_dx1(x, y), data.df_dx2(x, y)) calls_count = 2 while (grad[0] * grad[0] + grad[1] * grad[1]) >= data.eps * data.eps: (x, y) = (x - self.alpha * grad[0], y - self.alpha * grad[1]) grad = (data.df_dx1(x, y), data.df_dx2(x, y)) calls_count += 2 path.append((x, y)) return ResultData(self.name, (x, y), data.function(x, y), 0, calls_count, path)
def __call__(self, data: InputData) -> ResultData: (x, y) = data.initial path = [(x, y)] dx = data.df_dx1(x, y) x1 = x - self.alpha * dx dy = data.df_dx2(x1, y) y1 = y - self.alpha * dy calls_count = 2 f_calls = 0 while ((x1 - x)**2 + (y1 - y)**2) >= data.eps**2: (x, y) = (x1, y1) dx = data.df_dx1(x, y) x1 = x - self.alpha * dx dy = data.df_dx2(x1, y) y1 = y - self.alpha * dy calls_count += 2 path.append((x, y)) path.append((x1, y1)) return ResultData(self.name, (x1, y1), data.function(x, y), f_calls, calls_count, path)