oikan 0.0.1.5__tar.gz → 0.0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {oikan-0.0.1.5 → oikan-0.0.1.6}/PKG-INFO +1 -1
- oikan-0.0.1.6/oikan/visualize.py +69 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan.egg-info/PKG-INFO +1 -1
- {oikan-0.0.1.5 → oikan-0.0.1.6}/pyproject.toml +1 -1
- oikan-0.0.1.5/oikan/visualize.py +0 -37
- {oikan-0.0.1.5 → oikan-0.0.1.6}/LICENSE +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/README.md +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/__init__.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/model.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/regularization.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/symbolic.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/trainer.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan/utils.py +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan.egg-info/SOURCES.txt +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan.egg-info/dependency_links.txt +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan.egg-info/requires.txt +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/oikan.egg-info/top_level.txt +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/setup.cfg +0 -0
- {oikan-0.0.1.5 → oikan-0.0.1.6}/setup.py +0 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import matplotlib.pyplot as plt
|
3
|
+
import torch
|
4
|
+
|
5
|
+
def visualize_regression(model, X, y):
|
6
|
+
model.eval()
|
7
|
+
with torch.no_grad():
|
8
|
+
X_tensor = torch.FloatTensor(X)
|
9
|
+
y_pred = model(X_tensor).numpy()
|
10
|
+
|
11
|
+
plt.figure(figsize=(10, 6))
|
12
|
+
plt.scatter(X[:, 0], y, color='blue', label='True')
|
13
|
+
plt.scatter(X[:, 0], y_pred, color='red', label='Predicted')
|
14
|
+
plt.legend()
|
15
|
+
plt.show()
|
16
|
+
|
17
|
+
def visualize_classification(model, X, y):
|
18
|
+
model.eval()
|
19
|
+
|
20
|
+
if X.shape[1] > 2:
|
21
|
+
# SVD projection for high-dimensional inputs.
|
22
|
+
X_mean = np.mean(X, axis=0)
|
23
|
+
X_centered = X - X_mean
|
24
|
+
_, _, Vt = np.linalg.svd(X_centered, full_matrices=False)
|
25
|
+
principal = Vt[:2] # shape: (2, D)
|
26
|
+
X_proj = (X - X_mean) @ principal.T
|
27
|
+
|
28
|
+
x1, x2 = X_proj[:, 0], X_proj[:, 1]
|
29
|
+
x_min, x_max = x1.min() - 1, x1.max() + 1
|
30
|
+
y_min, y_max = x2.min() - 1, x2.max() + 1
|
31
|
+
xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100),
|
32
|
+
np.linspace(y_min, y_max, 100))
|
33
|
+
grid_2d = np.c_[xx.ravel(), yy.ravel()]
|
34
|
+
# Inverse transform grid points to original space.
|
35
|
+
X_grid = X_mean + grid_2d @ principal
|
36
|
+
|
37
|
+
with torch.no_grad():
|
38
|
+
X_grid_tensor = torch.FloatTensor(X_grid)
|
39
|
+
Z = model(X_grid_tensor)
|
40
|
+
Z = torch.argmax(Z, dim=1).numpy()
|
41
|
+
Z = Z.reshape(xx.shape)
|
42
|
+
|
43
|
+
plt.figure(figsize=(10, 8))
|
44
|
+
plt.contourf(xx, yy, Z, alpha=0.4)
|
45
|
+
plt.scatter(X_proj[:, 0], X_proj[:, 1], c=y, alpha=0.8)
|
46
|
+
plt.title("Classification Visualization (SVD Projection)")
|
47
|
+
plt.show()
|
48
|
+
|
49
|
+
else:
|
50
|
+
x1 = X[:, 0]
|
51
|
+
x2 = X[:, 1]
|
52
|
+
x_min, x_max = x1.min() - 1, x1.max() + 1
|
53
|
+
y_min, y_max = x2.min() - 1, x2.max() + 1
|
54
|
+
xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100),
|
55
|
+
np.linspace(y_min, y_max, 100))
|
56
|
+
grid_2d = np.c_[xx.ravel(), yy.ravel()]
|
57
|
+
X_grid = grid_2d
|
58
|
+
|
59
|
+
with torch.no_grad():
|
60
|
+
X_grid_tensor = torch.FloatTensor(X_grid)
|
61
|
+
Z = model(X_grid_tensor)
|
62
|
+
Z = torch.argmax(Z, dim=1).numpy()
|
63
|
+
Z = Z.reshape(xx.shape)
|
64
|
+
|
65
|
+
plt.figure(figsize=(10, 8))
|
66
|
+
plt.contourf(xx, yy, Z, alpha=0.4)
|
67
|
+
plt.scatter(X[:, 0], X[:, 1], c=y, alpha=0.8)
|
68
|
+
plt.title("Classification Visualization")
|
69
|
+
plt.show()
|
oikan-0.0.1.5/oikan/visualize.py
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
import matplotlib.pyplot as plt
|
3
|
-
import torch
|
4
|
-
|
5
|
-
def visualize_regression(model, X, y):
|
6
|
-
model.eval()
|
7
|
-
with torch.no_grad():
|
8
|
-
X_tensor = torch.FloatTensor(X)
|
9
|
-
y_pred = model(X_tensor).numpy()
|
10
|
-
|
11
|
-
plt.figure(figsize=(10, 6))
|
12
|
-
plt.scatter(X[:, 0], y, color='blue', label='True')
|
13
|
-
plt.scatter(X[:, 0], y_pred, color='red', label='Predicted')
|
14
|
-
plt.legend()
|
15
|
-
plt.show()
|
16
|
-
|
17
|
-
def visualize_classification(model, X, y):
|
18
|
-
model.eval()
|
19
|
-
|
20
|
-
# Create a mesh grid
|
21
|
-
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
|
22
|
-
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
|
23
|
-
xx, yy = np.meshgrid(np.linspace(x_min, x_max, 100),
|
24
|
-
np.linspace(y_min, y_max, 100))
|
25
|
-
|
26
|
-
# Make predictions
|
27
|
-
with torch.no_grad():
|
28
|
-
X_grid = torch.FloatTensor(np.c_[xx.ravel(), yy.ravel()])
|
29
|
-
Z = model(X_grid)
|
30
|
-
Z = torch.argmax(Z, dim=1).numpy()
|
31
|
-
Z = Z.reshape(xx.shape)
|
32
|
-
|
33
|
-
# Plot
|
34
|
-
plt.figure(figsize=(10, 8))
|
35
|
-
plt.contourf(xx, yy, Z, alpha=0.4)
|
36
|
-
plt.scatter(X[:, 0], X[:, 1], c=y, alpha=0.8)
|
37
|
-
plt.show()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|