diff --git a/GPR_Optimization.py b/GPR_Optimization.py
new file mode 100644
index 00000000..7d6f814e
--- /dev/null
+++ b/GPR_Optimization.py
@@ -0,0 +1,181 @@
+# /// script
+# requires-python = ">=3.12"
+# dependencies = [
+# "marimo",
+# "matplotlib==3.10.3",
+# "numpy==2.2.6",
+# "scikit-learn==1.6.1",
+# "scipy==1.15.3",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.13.7"
+app = marimo.App(width="medium")
+
+
+@app.cell
+def _():
+ import numpy as np
+ import matplotlib.pyplot as plt
+ from sklearn.gaussian_process import GaussianProcessRegressor
+ from sklearn.gaussian_process.kernels import Matern, WhiteKernel, ConstantKernel as C
+
+ def black_box_function(x):
+ return - (np.sin(3*x) + 0.5 * x)
+ return (
+ C,
+ GaussianProcessRegressor,
+ Matern,
+ WhiteKernel,
+ black_box_function,
+ np,
+ plt,
+ )
+
+
+@app.cell
+def _(black_box_function, np, plt):
+ X = np.linspace(0, 5.5, 1000).reshape(-1, 1)
+ y = black_box_function(X)
+ plt.plot(X, y)
+ plt.title("Black-box function")
+ plt.xlabel("x")
+ plt.ylabel("f(x)")
+ plt.show()
+ return X, y
+
+
+@app.cell
+def _(black_box_function, np):
+ X_grid = np.linspace(0, 2, 100).reshape(-1, 1)
+ y_grid = black_box_function(X_grid)
+ x_best = X_grid[np.argmax(y_grid)]
+ return
+
+
+@app.cell
+def _(black_box_function, np):
+ # Initial sample points (simulate prior evaluations)
+ X_sample = np.array([[1.0], [3.0], [5.5]])
+ y_sample = black_box_function(X_sample)
+ return X_sample, y_sample
+
+
+@app.cell
+def _(C, GaussianProcessRegressor, Matern, WhiteKernel, X_sample, y_sample):
+ # Define the kernel
+ kernel = C(1.0) * Matern(length_scale=1.0, nu=2.5) + WhiteKernel(noise_level=1e-5, noise_level_bounds=(1e-10, 1e1))
+
+ # Create and fit the Gaussian Process model
+ gpr = GaussianProcessRegressor(kernel=kernel, alpha=0.0)
+ gpr.fit(X_sample, y_sample)
+ return (gpr,)
+
+
+@app.cell
+def _(X, X_sample, gpr, plt, y, y_sample):
+ # Predict across the domain
+ mu, std = gpr.predict(X, return_std=True)
+
+ # Plot the result
+ plt.figure(figsize=(10, 5))
+ plt.plot(X, y, 'k--', label="True function")
+ plt.plot(X, mu, 'b-', label="GPR mean")
+ plt.fill_between(X.ravel(), mu - std, mu + std, alpha=0.3, label="Uncertainty")
+ plt.scatter(X_sample, y_sample, c='red', label="Samples")
+ plt.legend()
+ plt.title("Gaussian Process Fit")
+ plt.xlabel("x")
+ plt.ylabel("f(x)")
+ plt.show()
+ return
+
+
+@app.cell
+def _(np):
+ from scipy.stats import norm
+
+ def expected_improvement(X, X_sample, y_sample, model, xi=0.01):
+ mu, std = model.predict(X, return_std=True)
+ mu_sample_opt = np.min(y_sample)
+
+ with np.errstate(divide='warn'):
+ imp = mu_sample_opt - mu - xi # because we are minimizing
+ Z = imp / std
+ ei = imp * norm.cdf(Z) + std * norm.pdf(Z)
+ ei[std == 0.0] = 0.0
+
+ return ei
+
+ return (expected_improvement,)
+
+
+@app.cell
+def _(X, X_sample, expected_improvement, gpr, np, plt, y_sample):
+ ei = expected_improvement(X, X_sample, y_sample, gpr)
+
+ plt.figure(figsize=(10, 4))
+ plt.plot(X, ei, label="Expected Improvement")
+ plt.axvline(X[np.argmax(ei)], color='r', linestyle='--', label="Next sample point")
+ plt.title("Acquisition Function (Expected Improvement)")
+ plt.xlabel("x")
+ plt.ylabel("EI(x)")
+ plt.legend()
+ plt.show()
+
+ return
+
+
+@app.cell
+def _(X, black_box_function, expected_improvement, gpr, np):
+ def bayesian_optimization(n_iter=10):
+ # Initial data
+ X_sample = np.array([[1.0], [2.5], [4.0]])
+ y_sample = black_box_function(X_sample)
+
+ for i in range(n_iter):
+ gpr.fit(X_sample, y_sample)
+ ei = expected_improvement(X, X_sample, y_sample, gpr)
+ x_next = X[np.argmax(ei)].reshape(-1, 1)
+
+ # Evaluate the function at the new point
+ y_next = black_box_function(x_next)
+
+ # Add the new sample to our dataset
+ X_sample = np.vstack((X_sample, x_next))
+ y_sample = np.append(y_sample, y_next)
+ return X_sample, y_sample
+
+ return (bayesian_optimization,)
+
+
+@app.cell
+def _(bayesian_optimization):
+ X_opt, y_opt = bayesian_optimization(n_iter=10)
+
+ return X_opt, y_opt
+
+
+@app.cell
+def _(X, X_opt, black_box_function, plt, y_opt):
+ # Plot final sampled points
+ plt.plot(X, black_box_function(X), 'k--', label="True function")
+ plt.scatter(X_opt, y_opt, c='red', label="Sampled Points")
+ plt.title("Bayesian Optimization with Gaussian Process")
+ plt.xlabel("x")
+ plt.ylabel("f(x)")
+ plt.legend()
+ plt.show()
+
+ return
+
+
+@app.cell
+def _():
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/public/GPR_Optimization.html b/public/GPR_Optimization.html
new file mode 100644
index 00000000..6bb3dc95
--- /dev/null
+++ b/public/GPR_Optimization.html
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ GPR_Optimization.py
+
+
+
+
+
+ GPR Optimization
+
+
+
+
+
+
+
+
+
+ import%20marimo%0A%0A__generated_with%20%3D%20%220.13.7%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20sklearn.gaussian_process%20import%20GaussianProcessRegressor%0A%20%20%20%20from%20sklearn.gaussian_process.kernels%20import%20Matern%2C%20WhiteKernel%2C%20ConstantKernel%20as%20C%0A%0A%20%20%20%20def%20black_box_function(x)%3A%0A%20%20%20%20%20%20%20%20return%20-%20(np.sin(3*x)%20%2B%200.5%20*%20x)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20C%2C%0A%20%20%20%20%20%20%20%20GaussianProcessRegressor%2C%0A%20%20%20%20%20%20%20%20Matern%2C%0A%20%20%20%20%20%20%20%20WhiteKernel%2C%0A%20%20%20%20%20%20%20%20black_box_function%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20plt%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(black_box_function%2C%20np%2C%20plt)%3A%0A%20%20%20%20X%20%3D%20np.linspace(0%2C%205.5%2C%201000).reshape(-1%2C%201)%0A%20%20%20%20y%20%3D%20black_box_function(X)%0A%20%20%20%20plt.plot(X%2C%20y)%0A%20%20%20%20plt.title(%22Black-box%20function%22)%0A%20%20%20%20plt.xlabel(%22x%22)%0A%20%20%20%20plt.ylabel(%22f(x)%22)%0A%20%20%20%20plt.show()%0A%20%20%20%20return%20X%2C%20y%0A%0A%0A%40app.cell%0Adef%20_(black_box_function%2C%20np)%3A%0A%20%20%20%20X_grid%20%3D%20np.linspace(0%2C%202%2C%20100).reshape(-1%2C%201)%0A%20%20%20%20y_grid%20%3D%20black_box_function(X_grid)%0A%20%20%20%20x_best%20%3D%20X_grid%5Bnp.argmax(y_grid)%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(black_box_function%2C%20np)%3A%0A%20%20%20%20%23%20Initial%20sample%20points%20(simulate%20prior%20evaluations)%0A%20%20%20%20X_sample%20%3D%20np.array(%5B%5B1.0%5D%2C%20%5B3.0%5D%2C%20%5B5.5%5D%5D)%0A%20%20%20%20y_sample%20%3D%20black_box_function(X_sample)%0A%20%20%20%20return%20X_sample%2C%20y_sample%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20GaussianProcessRegressor%2C%20Matern%2C%20WhiteKernel%2C%20X_sample%2C%20y_sample)%3A%0A%20%20%20%20%23%20Define%20the%20kernel%0A%20%20%20%20kernel%20%3D%20C(1.0)%20*%20Matern(length_scale%3D1.0%2C%20nu%3D2.5)%20%2B%20WhiteKernel(noise_level%3D1e-5%2C%20noise_level_bounds%3D(1e-10%2C%201e1))%0A%0A%20%20%20%20%23%20Create%20and%20fit%20the%20Gaussian%20Process%20model%0A%20%20%20%20gpr%20%3D%20GaussianProcessRegressor(kernel%3Dkernel%2C%20alpha%3D0.0)%0A%20%20%20%20gpr.fit(X_sample%2C%20y_sample)%0A%20%20%20%20return%20(gpr%2C)%0A%0A%0A%40app.cell%0Adef%20_(X%2C%20X_sample%2C%20gpr%2C%20plt%2C%20y%2C%20y_sample)%3A%0A%20%20%20%20%23%20Predict%20across%20the%20domain%0A%20%20%20%20mu%2C%20std%20%3D%20gpr.predict(X%2C%20return_std%3DTrue)%0A%0A%20%20%20%20%23%20Plot%20the%20result%0A%20%20%20%20plt.figure(figsize%3D(10%2C%205))%0A%20%20%20%20plt.plot(X%2C%20y%2C%20'k--'%2C%20label%3D%22True%20function%22)%0A%20%20%20%20plt.plot(X%2C%20mu%2C%20'b-'%2C%20label%3D%22GPR%20mean%22)%0A%20%20%20%20plt.fill_between(X.ravel()%2C%20mu%20-%20std%2C%20mu%20%2B%20std%2C%20alpha%3D0.3%2C%20label%3D%22Uncertainty%22)%0A%20%20%20%20plt.scatter(X_sample%2C%20y_sample%2C%20c%3D'red'%2C%20label%3D%22Samples%22)%0A%20%20%20%20plt.legend()%0A%20%20%20%20plt.title(%22Gaussian%20Process%20Fit%22)%0A%20%20%20%20plt.xlabel(%22x%22)%0A%20%20%20%20plt.ylabel(%22f(x)%22)%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20from%20scipy.stats%20import%20norm%0A%0A%20%20%20%20def%20expected_improvement(X%2C%20X_sample%2C%20y_sample%2C%20model%2C%20xi%3D0.01)%3A%0A%20%20%20%20%20%20%20%20mu%2C%20std%20%3D%20model.predict(X%2C%20return_std%3DTrue)%0A%20%20%20%20%20%20%20%20mu_sample_opt%20%3D%20np.min(y_sample)%0A%0A%20%20%20%20%20%20%20%20with%20np.errstate(divide%3D'warn')%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20imp%20%3D%20mu_sample_opt%20-%20mu%20-%20xi%20%20%23%20because%20we%20are%20minimizing%0A%20%20%20%20%20%20%20%20%20%20%20%20Z%20%3D%20imp%20%2F%20std%0A%20%20%20%20%20%20%20%20%20%20%20%20ei%20%3D%20imp%20*%20norm.cdf(Z)%20%2B%20std%20*%20norm.pdf(Z)%0A%20%20%20%20%20%20%20%20%20%20%20%20ei%5Bstd%20%3D%3D%200.0%5D%20%3D%200.0%0A%0A%20%20%20%20%20%20%20%20return%20ei%0A%0A%20%20%20%20return%20(expected_improvement%2C)%0A%0A%0A%40app.cell%0Adef%20_(X%2C%20X_sample%2C%20expected_improvement%2C%20gpr%2C%20np%2C%20plt%2C%20y_sample)%3A%0A%20%20%20%20ei%20%3D%20expected_improvement(X%2C%20X_sample%2C%20y_sample%2C%20gpr)%0A%0A%20%20%20%20plt.figure(figsize%3D(10%2C%204))%0A%20%20%20%20plt.plot(X%2C%20ei%2C%20label%3D%22Expected%20Improvement%22)%0A%20%20%20%20plt.axvline(X%5Bnp.argmax(ei)%5D%2C%20color%3D'r'%2C%20linestyle%3D'--'%2C%20label%3D%22Next%20sample%20point%22)%0A%20%20%20%20plt.title(%22Acquisition%20Function%20(Expected%20Improvement)%22)%0A%20%20%20%20plt.xlabel(%22x%22)%0A%20%20%20%20plt.ylabel(%22EI(x)%22)%0A%20%20%20%20plt.legend()%0A%20%20%20%20plt.show()%0A%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X%2C%20black_box_function%2C%20expected_improvement%2C%20gpr%2C%20np)%3A%0A%20%20%20%20def%20bayesian_optimization(n_iter%3D10)%3A%0A%20%20%20%20%20%20%20%20%23%20Initial%20data%0A%20%20%20%20%20%20%20%20X_sample%20%3D%20np.array(%5B%5B1.0%5D%2C%20%5B2.5%5D%2C%20%5B4.0%5D%5D)%0A%20%20%20%20%20%20%20%20y_sample%20%3D%20black_box_function(X_sample)%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(n_iter)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20gpr.fit(X_sample%2C%20y_sample)%0A%20%20%20%20%20%20%20%20%20%20%20%20ei%20%3D%20expected_improvement(X%2C%20X_sample%2C%20y_sample%2C%20gpr)%0A%20%20%20%20%20%20%20%20%20%20%20%20x_next%20%3D%20X%5Bnp.argmax(ei)%5D.reshape(-1%2C%201)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Evaluate%20the%20function%20at%20the%20new%20point%0A%20%20%20%20%20%20%20%20%20%20%20%20y_next%20%3D%20black_box_function(x_next)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Add%20the%20new%20sample%20to%20our%20dataset%0A%20%20%20%20%20%20%20%20%20%20%20%20X_sample%20%3D%20np.vstack((X_sample%2C%20x_next))%0A%20%20%20%20%20%20%20%20%20%20%20%20y_sample%20%3D%20np.append(y_sample%2C%20y_next)%0A%20%20%20%20%20%20%20%20return%20X_sample%2C%20y_sample%0A%0A%20%20%20%20return%20(bayesian_optimization%2C)%0A%0A%0A%40app.cell%0Adef%20_(bayesian_optimization)%3A%0A%20%20%20%20X_opt%2C%20y_opt%20%3D%20bayesian_optimization(n_iter%3D10)%0A%0A%20%20%20%20return%20X_opt%2C%20y_opt%0A%0A%0A%40app.cell%0Adef%20_(X%2C%20X_opt%2C%20black_box_function%2C%20plt%2C%20y_opt)%3A%0A%20%20%20%20%23%20Plot%20final%20sampled%20points%0A%20%20%20%20plt.plot(X%2C%20black_box_function(X)%2C%20'k--'%2C%20label%3D%22True%20function%22)%0A%20%20%20%20plt.scatter(X_opt%2C%20y_opt%2C%20c%3D'red'%2C%20label%3D%22Sampled%20Points%22)%0A%20%20%20%20plt.title(%22Bayesian%20Optimization%20with%20Gaussian%20Process%22)%0A%20%20%20%20plt.xlabel(%22x%22)%0A%20%20%20%20plt.ylabel(%22f(x)%22)%0A%20%20%20%20plt.legend()%0A%20%20%20%20plt.show()%0A%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
+
+
+5b6ca0cf371431f4cf60ff4f6e7e10e8c3b01c3e27a72f0ca92acba39db1f941
+
+
diff --git a/public/index.html b/public/index.html
index b5373537..6c8c1cd4 100644
--- a/public/index.html
+++ b/public/index.html
@@ -85,22 +85,14 @@ polars vs pandas
pyspark parametrize
View the notebook
-
- diffbot llm
- View the notebook
-
-
- lchain deepseek
- View the notebook
-
-
- lchain ollama
- View the notebook
-
pydantic ai examples
View the notebook
+
+ temp
+ View the notebook
+