Skip to content

Commit da7ec70

Browse files
merge with main and move file
1 parent 724a21b commit da7ec70

File tree

8 files changed

+269
-260
lines changed

8 files changed

+269
-260
lines changed

GPR_Optimization.py renamed to machine-learning/gpr_optimization.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
@app.cell
1919
def _():
20-
import numpy as np
2120
import matplotlib.pyplot as plt
21+
import numpy as np
2222
from sklearn.gaussian_process import GaussianProcessRegressor
23-
from sklearn.gaussian_process.kernels import Matern, WhiteKernel, ConstantKernel as C
23+
from sklearn.gaussian_process.kernels import ConstantKernel as C
24+
from sklearn.gaussian_process.kernels import Matern, WhiteKernel
2425

2526
def black_box_function(x):
2627
return - (np.sin(3*x) + 0.5 * x)
@@ -81,10 +82,10 @@ def _(X, X_sample, gpr, plt, y, y_sample):
8182

8283
# Plot the result
8384
plt.figure(figsize=(10, 5))
84-
plt.plot(X, y, 'k--', label="True function")
85-
plt.plot(X, mu, 'b-', label="GPR mean")
85+
plt.plot(X, y, "k--", label="True function")
86+
plt.plot(X, mu, "b-", label="GPR mean")
8687
plt.fill_between(X.ravel(), mu - std, mu + std, alpha=0.3, label="Uncertainty")
87-
plt.scatter(X_sample, y_sample, c='red', label="Samples")
88+
plt.scatter(X_sample, y_sample, c="red", label="Samples")
8889
plt.legend()
8990
plt.title("Gaussian Process Fit")
9091
plt.xlabel("x")
@@ -101,7 +102,7 @@ def expected_improvement(X, X_sample, y_sample, model, xi=0.01):
101102
mu, std = model.predict(X, return_std=True)
102103
mu_sample_opt = np.min(y_sample)
103104

104-
with np.errstate(divide='warn'):
105+
with np.errstate(divide="warn"):
105106
imp = mu_sample_opt - mu - xi # because we are minimizing
106107
Z = imp / std
107108
ei = imp * norm.cdf(Z) + std * norm.pdf(Z)
@@ -118,7 +119,7 @@ def _(X, X_sample, expected_improvement, gpr, np, plt, y_sample):
118119

119120
plt.figure(figsize=(10, 4))
120121
plt.plot(X, ei, label="Expected Improvement")
121-
plt.axvline(X[np.argmax(ei)], color='r', linestyle='--', label="Next sample point")
122+
plt.axvline(X[np.argmax(ei)], color="r", linestyle="--", label="Next sample point")
122123
plt.title("Acquisition Function (Expected Improvement)")
123124
plt.xlabel("x")
124125
plt.ylabel("EI(x)")
@@ -135,7 +136,7 @@ def bayesian_optimization(n_iter=10):
135136
X_sample = np.array([[1.0], [2.5], [4.0]])
136137
y_sample = black_box_function(X_sample)
137138

138-
for i in range(n_iter):
139+
for _ in range(n_iter):
139140
gpr.fit(X_sample, y_sample)
140141
ei = expected_improvement(X, X_sample, y_sample, gpr)
141142
x_next = X[np.argmax(ei)].reshape(-1, 1)
@@ -161,8 +162,8 @@ def _(bayesian_optimization):
161162
@app.cell
162163
def _(X, X_opt, black_box_function, plt, y_opt):
163164
# Plot final sampled points
164-
plt.plot(X, black_box_function(X), 'k--', label="True function")
165-
plt.scatter(X_opt, y_opt, c='red', label="Sampled Points")
165+
plt.plot(X, black_box_function(X), "k--", label="True function")
166+
plt.scatter(X_opt, y_opt, c="red", label="Sampled Points")
166167
plt.title("Bayesian Optimization with Gaussian Process")
167168
plt.xlabel("x")
168169
plt.ylabel("f(x)")

public/GPR_Optimization.html

Lines changed: 0 additions & 82 deletions
This file was deleted.

public/index.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ <h2 class="notebook-title">pyspark parametrize</h2>
8686
<a href="data_science_tools/pyspark_parametrize.html" class="notebook-link">View the notebook</a>
8787
</li>
8888
<li class="notebook-item">
89-
<h2 class="notebook-title">pydantic ai examples</h2>
90-
<a href="llm/pydantic_ai_examples.html" class="notebook-link">View the notebook</a>
89+
<h2 class="notebook-title">diffbot llm</h2>
90+
<a href="llm/diffbot_llm.html" class="notebook-link">View the notebook</a>
91+
</li>
92+
<li class="notebook-item">
93+
<h2 class="notebook-title">lchain deepseek</h2>
94+
<a href="llm/lchain_deepseek.html" class="notebook-link">View the notebook</a>
9195
</li>
9296
<li class="notebook-item">
93-
<h2 class="notebook-title">temp</h2>
94-
<a href="temp/temp.html" class="notebook-link">View the notebook</a>
97+
<h2 class="notebook-title">lchain ollama</h2>
98+
<a href="llm/lchain_ollama.html" class="notebook-link">View the notebook</a>
99+
</li>
100+
<li class="notebook-item">
101+
<h2 class="notebook-title">pydantic ai examples</h2>
102+
<a href="llm/pydantic_ai_examples.html" class="notebook-link">View the notebook</a>
95103
</li>
96104
</ul>
97105
</body>

public/llm/diffbot_llm.html

Lines changed: 82 additions & 0 deletions
Large diffs are not rendered by default.

public/llm/lchain_deepseek.html

Lines changed: 82 additions & 0 deletions
Large diffs are not rendered by default.

public/llm/lchain_ollama.html

Lines changed: 82 additions & 0 deletions
Large diffs are not rendered by default.

public/temp.html

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)