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 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)