def hooke_jeeves(x0, epsilon, step, alpha): it = 0 xB = x0 a = b = float('inf') while c(x0) > epsilon or it < 1_000: # # warunek stopu if it == 0: a = c(x0) else: a = b b = c(x0) if a == b: break it += 1 xB = x0 x0 = try_procedure(xB, step) if c(x0) < c(xB): while c(x0) >= c(xB): xB_temp = xB xB = x0 x0 = 2 * xB - xB_temp x0 = try_procedure(x0, step) else: step = alpha * step save(c(x0), 0) save(xB, 0) return xB
def try_procedure(x, s, function): size = len(x) for i in range(size): temp = x temp_val = list(temp) temp_val[i] = temp_val[i] + s temp = tuple(temp_val) if c(temp, function) < c(x, function): x = temp else: temp_val = list(temp) temp_val[i] = temp_val[i] - 2.0 * s temp = tuple(temp_val) if c(temp, function) < c(x, function): x = temp return x
def hooke_jeeves(x0, epsilon, s, alpha, function): it = 0 xB = x0 a = b = float('inf') while s > epsilon or it < 1_000: if it == 0: a = c(x0, function) else: a = b b = c(x0, function) save(function, c(x0, function)) if a == b: break it += 1 xB = x0 x0 = try_procedure(xB, s, function) if c(x0, function) < c(xB, function): while c(x0, function) >= c(xB, function): xB_temp = xB xB = x0 x0 = 2 * xB - xB_temp x0 = try_procedure(x0, s) else: s = alpha * s return xB
def try_procedure(x, step): size = len(x) for i in range(size): temp = x # ograniczenia współczynników if temp[i] + step * temp[i] < dict_constraints[i][ 1] and temp[i] + step * temp[i] > dict_constraints[i][0]: temp[i] = temp[i] + step * temp[i] else: continue # po korekcji współczynników if c(temp) < c(x): x = temp else: temp[i] = temp[i] - 2.0 * step * temp[i] if c(temp) < c(x): x = temp return x
b.看R基测三个字母的缩写 c.看三个字母的缩写测R基 d.看三个字母的缩写测中文 e.看一个字母的缩写测三个字母的缩写 f.See some tips g.Exit''') cho = str(input()) if cho == 'g': exit() if cho == 'f': print(tip.t) nothing = input() continue if cho == 'b': func.b() continue if cho == 'c': func.c() continue if cho == 'd': func.d() continue if cho == 'e': func.e() continue if cho == 'g': nothing = input() exit() else: print("Invalid choice") nothing = input()