@@ -53,6 +53,12 @@ def apply_codecut_style(ax=None):
53
53
return apply_codecut_style , plt
54
54
55
55
56
+ @app .cell (hide_code = True )
57
+ def _ (mo ):
58
+ mo .md (r"""## Motivation""" )
59
+ return
60
+
61
+
56
62
@app .cell
57
63
def _ ():
58
64
import random
@@ -86,6 +92,12 @@ def evaluate_model(model):
86
92
return
87
93
88
94
95
+ @app .cell (hide_code = True )
96
+ def _ (mo ):
97
+ mo .md (r"""## Setup""" )
98
+ return
99
+
100
+
89
101
@app .cell
90
102
def _ ():
91
103
import numpy as np
@@ -119,11 +131,31 @@ def _(X, apply_codecut_style, plt, y):
119
131
return
120
132
121
133
134
+ @app .cell (hide_code = True )
135
+ def _ (mo ):
136
+ mo .md (r"""## Brute force hyperparameter search""" )
137
+ return
138
+
139
+
122
140
@app .cell
123
141
def _ (black_box_function , np ):
124
142
X_grid = np .linspace (0 , 2 , 100 ).reshape (- 1 , 1 )
125
143
y_grid = black_box_function (X_grid )
126
144
x_best = X_grid [np .argmax (y_grid )]
145
+ return X_grid , x_best , y_grid
146
+
147
+
148
+ @app .cell
149
+ def _ (X_grid , apply_codecut_style , black_box_function , plt , x_best , y_grid ):
150
+ plt .plot (X_grid , y_grid , "--" , color = "white" , label = "True function" )
151
+ plt .scatter (X_grid , y_grid , c = "#E583B6" , label = "Evaluated Points" )
152
+ plt .scatter (x_best , black_box_function (x_best ), c = "#72BEFA" , s = 80 , edgecolors = "black" , label = "Best Point" )
153
+
154
+ plt .title ("Brute Force Search Over Full Range" )
155
+ plt .xlabel ("x" )
156
+ plt .ylabel ("f(x)" )
157
+ plt .legend ()
158
+ apply_codecut_style ()
127
159
return
128
160
129
161
@@ -148,6 +180,12 @@ def _():
148
180
return
149
181
150
182
183
+ @app .cell (hide_code = True )
184
+ def _ (mo ):
185
+ mo .md (r"""## Introducing Gaussian Process Regression""" )
186
+ return
187
+
188
+
151
189
@app .cell
152
190
def _ (black_box_function , np ):
153
191
# Initial sample points (simulate prior evaluations)
@@ -186,6 +224,12 @@ def _(X, X_sample, apply_codecut_style, gpr, plt, y, y_sample):
186
224
return
187
225
188
226
227
+ @app .cell (hide_code = True )
228
+ def _ (mo ):
229
+ mo .md (r"""## Bayesian Optimization Step""" )
230
+ return
231
+
232
+
189
233
@app .cell
190
234
def _ (np ):
191
235
from scipy .stats import norm
@@ -229,6 +273,12 @@ def _(
229
273
return
230
274
231
275
276
+ @app .cell (hide_code = True )
277
+ def _ (mo ):
278
+ mo .md (r"""## Hypeparameter Search Loop""" )
279
+ return
280
+
281
+
232
282
@app .cell
233
283
def _ (X , black_box_function , expected_improvement , gpr , np ):
234
284
def bayesian_optimization (n_iter = 10 ):
@@ -272,5 +322,11 @@ def _(X, X_opt, apply_codecut_style, black_box_function, plt, y_opt):
272
322
return
273
323
274
324
325
+ @app .cell
326
+ def _ ():
327
+ import marimo as mo
328
+ return (mo ,)
329
+
330
+
275
331
if __name__ == "__main__" :
276
332
app .run ()
0 commit comments