MCPcopy Create free account
hub / github.com/blackrock/HOLA / example_2d

Function example_2d

hola-py/examples/basic_optimization.py:51–84  ·  view source on GitHub ↗

Optimize the 2D Branin function with ask/tell.

()

Source from the content-addressed store, hash-verified

49 print(f" TLP score: {best.scores['value']:.4f} (0 = at target, 1 = at limit)")
50 print(f" At x = {best.params['x']:.4f}")
51 print(f" Gap from known optimum: {best.metrics['value'] - (-6.0207400558):.4f}")
52 print()
53
54
55def example_2d():
56 """Optimize the 2D Branin function with ask/tell."""
57 print("=" * 60)
58 print("Example 2: Branin function (2D) — ask/tell loop")
59 print(" Known minimum: 0.397887")
60 print("=" * 60)
61
62 study = Study(
63 space=Space(
64 x1=Real(-5.0, 10.0),
65 x2=Real(0.0, 15.0),
66 ),
67 objectives=[Minimize("value", target=0.5, limit=50.0)],
68 strategy="sobol",
69 )
70
71 # Manual ask/tell loop
72 for i in range(100):
73 trial = study.ask()
74 result = branin(trial.params)
75 study.tell(trial.trial_id, {"value": result})
76
77 if (i + 1) % 25 == 0:
78 best = study.top_k(1)[0]
79 print(
80 f" Trial {i + 1:3d}: best = {best.metrics['value']:.6f}"
81 f" (TLP: {best.scores['value']:.4f})"
82 )
83
84 best = study.top_k(1)[0]
85 print(f"\n Final best: {best.metrics['value']:.6f} (TLP: {best.scores['value']:.4f})")
86 print(f" At x1={best.params['x1']:.4f}, x2={best.params['x2']:.4f}")
87 print(f" Gap: {best.metrics['value'] - 0.397887:.6f}")

Callers 1

Calls 8

askMethod · 0.95
tellMethod · 0.95
top_kMethod · 0.95
braninFunction · 0.90
StudyClass · 0.85
SpaceClass · 0.85
RealClass · 0.85
MinimizeClass · 0.85

Tested by

no test coverage detected