oikan 0.0.3.5__py3-none-any.whl → 0.0.3.7__py3-none-any.whl
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/model.py +65 -20
- oikan/neural.py +1 -0
- {oikan-0.0.3.5.dist-info → oikan-0.0.3.7.dist-info}/METADATA +28 -5
- oikan-0.0.3.7.dist-info/RECORD +10 -0
- {oikan-0.0.3.5.dist-info → oikan-0.0.3.7.dist-info}/WHEEL +1 -1
- oikan-0.0.3.5.dist-info/RECORD +0 -10
- {oikan-0.0.3.5.dist-info → oikan-0.0.3.7.dist-info}/licenses/LICENSE +0 -0
- {oikan-0.0.3.5.dist-info → oikan-0.0.3.7.dist-info}/top_level.txt +0 -0
oikan/model.py
CHANGED
@@ -41,10 +41,12 @@ class OIKAN(ABC):
|
|
41
41
|
Whether to display training progress.
|
42
42
|
evaluate_nn : bool, optional (default=False)
|
43
43
|
Whether to evaluate neural network performance before full training.
|
44
|
+
random_state: int, optional (default=None)
|
45
|
+
Random seed for reproducibility.
|
44
46
|
"""
|
45
47
|
def __init__(self, hidden_sizes=[64, 64], activation='relu', augmentation_factor=10,
|
46
48
|
alpha=0.1, sigma=0.1, epochs=100, lr=0.001, batch_size=32,
|
47
|
-
verbose=False, evaluate_nn=False, top_k=5):
|
49
|
+
verbose=False, evaluate_nn=False, top_k=5, random_state=None):
|
48
50
|
if not isinstance(hidden_sizes, list) or not all(isinstance(x, int) and x > 0 for x in hidden_sizes):
|
49
51
|
raise InvalidParameterError("hidden_sizes must be a list of positive integers")
|
50
52
|
if activation not in ['relu', 'tanh', 'leaky_relu', 'elu', 'swish', 'gelu']:
|
@@ -78,6 +80,11 @@ class OIKAN(ABC):
|
|
78
80
|
self.neural_net = None
|
79
81
|
self.symbolic_model = None
|
80
82
|
self.evaluation_done = False
|
83
|
+
self.random_state = random_state
|
84
|
+
|
85
|
+
if self.random_state is not None:
|
86
|
+
torch.manual_seed(self.random_state)
|
87
|
+
np.random.seed(self.random_state)
|
81
88
|
|
82
89
|
@abstractmethod
|
83
90
|
def fit(self, X, y):
|
@@ -312,11 +319,15 @@ class OIKAN(ABC):
|
|
312
319
|
|
313
320
|
def _generate_augmented_data(self, X):
|
314
321
|
"""Generates augmented data by adding Gaussian noise."""
|
322
|
+
if self.augmentation_factor == 1:
|
323
|
+
return np.array([]).reshape(0, X.shape[1])
|
324
|
+
|
315
325
|
X_aug = []
|
316
|
-
for _ in range(self.augmentation_factor):
|
326
|
+
for _ in range(self.augmentation_factor - 1):
|
317
327
|
noise = np.random.normal(0, self.sigma, X.shape)
|
318
328
|
X_perturbed = X + noise
|
319
329
|
X_aug.append(X_perturbed)
|
330
|
+
|
320
331
|
return np.vstack(X_aug)
|
321
332
|
|
322
333
|
def _perform_symbolic_regression(self, X, y):
|
@@ -438,16 +449,33 @@ class OIKANRegressor(OIKAN):
|
|
438
449
|
"""
|
439
450
|
X = np.asarray(X)
|
440
451
|
y = np.asarray(y).reshape(-1, 1)
|
441
|
-
|
442
|
-
if self.
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
452
|
+
|
453
|
+
if self.augmentation_factor > 1:
|
454
|
+
self._train_neural_net(X, y, output_size=1, loss_fn=nn.MSELoss())
|
455
|
+
|
456
|
+
if self.verbose:
|
457
|
+
print(f"Original data: features shape: {X.shape} | target shape: {y.shape}")
|
458
|
+
|
459
|
+
X_aug = self._generate_augmented_data(X)
|
460
|
+
|
461
|
+
self.neural_net.eval()
|
462
|
+
with torch.no_grad():
|
463
|
+
y_aug = self.neural_net(torch.tensor(X_aug, dtype=torch.float32)).detach().numpy()
|
464
|
+
|
465
|
+
if self.verbose:
|
466
|
+
print(f"Augmented data: features shape: {X_aug.shape} | target shape: {y_aug.shape}")
|
467
|
+
|
468
|
+
X_combined = np.vstack([X, X_aug])
|
469
|
+
y_combined = np.vstack([y, y_aug])
|
470
|
+
else:
|
471
|
+
if self.verbose:
|
472
|
+
print("Skipping neural network training (augmentation_factor=1)")
|
473
|
+
X_combined = X
|
474
|
+
y_combined = y
|
475
|
+
|
476
|
+
self._perform_symbolic_regression(X_combined, y_combined)
|
448
477
|
if self.verbose:
|
449
|
-
print(
|
450
|
-
self._perform_symbolic_regression(X_aug, y_aug)
|
478
|
+
print("OIKANRegressor model training completed successfully!")
|
451
479
|
|
452
480
|
def predict(self, X):
|
453
481
|
"""
|
@@ -490,16 +518,33 @@ class OIKANClassifier(OIKAN):
|
|
490
518
|
self.classes_ = le.classes_
|
491
519
|
n_classes = len(self.classes_)
|
492
520
|
y_onehot = nn.functional.one_hot(torch.tensor(y_encoded), num_classes=n_classes).float()
|
493
|
-
|
494
|
-
if self.
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
521
|
+
|
522
|
+
if self.augmentation_factor > 1:
|
523
|
+
self._train_neural_net(X, y_onehot, output_size=n_classes, loss_fn=nn.CrossEntropyLoss())
|
524
|
+
|
525
|
+
if self.verbose:
|
526
|
+
print(f"Original data: features shape: {X.shape} | target shape: {y.shape}")
|
527
|
+
|
528
|
+
X_aug = self._generate_augmented_data(X)
|
529
|
+
|
530
|
+
self.neural_net.eval()
|
531
|
+
with torch.no_grad():
|
532
|
+
logits_aug = self.neural_net(torch.tensor(X_aug, dtype=torch.float32)).detach().numpy()
|
533
|
+
|
534
|
+
if self.verbose:
|
535
|
+
print(f"Augmented data: features shape: {X_aug.shape} | target shape: {logits_aug.shape}")
|
536
|
+
|
537
|
+
X_combined = np.vstack([X, X_aug])
|
538
|
+
y_combined = np.vstack([y_onehot.numpy(), logits_aug])
|
539
|
+
else:
|
540
|
+
if self.verbose:
|
541
|
+
print("Skipping neural network training (augmentation_factor=1)")
|
542
|
+
X_combined = X
|
543
|
+
y_combined = y_onehot.numpy()
|
544
|
+
|
545
|
+
self._perform_symbolic_regression(X_combined, y_combined)
|
500
546
|
if self.verbose:
|
501
|
-
print(
|
502
|
-
self._perform_symbolic_regression(X_aug, logits_aug)
|
547
|
+
print("OIKANClassifier model training completed successfully!")
|
503
548
|
|
504
549
|
def predict(self, X):
|
505
550
|
"""
|
oikan/neural.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: oikan
|
3
|
-
Version: 0.0.3.
|
3
|
+
Version: 0.0.3.7
|
4
4
|
Summary: OIKAN: Neuro-Symbolic ML for Scientific Discovery
|
5
5
|
Author: Arman Zhalgasbayev
|
6
6
|
License: MIT
|
@@ -34,7 +34,11 @@ OIKAN is a neuro-symbolic machine learning framework inspired by Kolmogorov-Arno
|
|
34
34
|
[](https://opensource.org/licenses/MIT)
|
35
35
|
[](https://github.com/silvermete0r/oikan/issues)
|
36
36
|
[](https://silvermete0r.github.io/oikan/)
|
37
|
+
|
37
38
|
[](https://deepwiki.com/silvermete0r/oikan)
|
39
|
+
[](https://colab.research.google.com/github/silvermete0r/oikan/blob/main/examples/oikan-v0-0-3-get-started-template-notebook.ipynb)
|
40
|
+
[](https://www.kaggle.com/code/armanzhalgasbayev/oikan-v0-0-3-get-started-template-notebook)
|
41
|
+
[](https://github.com/silvermete0r/awesome-oikan)
|
38
42
|
|
39
43
|
> **Important Disclaimer**: OIKAN is an experimental research project. It is not intended for production use or real-world applications. This framework is designed for research purposes, experimentation, and academic exploration of neuro-symbolic machine learning concepts.
|
40
44
|
|
@@ -111,9 +115,20 @@ cd OIKAN
|
|
111
115
|
pip install -e . # Install in development mode
|
112
116
|
```
|
113
117
|
|
118
|
+
#### System Requirements
|
119
|
+
|
120
|
+
| Requirement | Details |
|
121
|
+
|-------------------|--------------------------------------|
|
122
|
+
| Python | Version 3.7 or higher |
|
123
|
+
| Operating System | Platform independent (Windows/macOS/Linux) |
|
124
|
+
| Memory | Recommended minimum 4GB RAM |
|
125
|
+
| Disk Space | ~100MB for installation (including dependencies) |
|
126
|
+
| GPU | Optional (for faster training) |
|
127
|
+
| Dependencies | torch, numpy, scikit-learn, sympy, tqdm |
|
128
|
+
|
114
129
|
### Regression Example
|
115
130
|
```python
|
116
|
-
from oikan
|
131
|
+
from oikan import OIKANRegressor
|
117
132
|
from sklearn.metrics import mean_squared_error
|
118
133
|
|
119
134
|
# Initialize model
|
@@ -128,7 +143,8 @@ model = OIKANRegressor(
|
|
128
143
|
lr=0.001, # Learning rate
|
129
144
|
batch_size=32, # Batch size for training
|
130
145
|
verbose=True, # Verbose output during training
|
131
|
-
evaluate_nn=True # Validate neural network performance before full process
|
146
|
+
evaluate_nn=True, # Validate neural network performance before full process
|
147
|
+
random_state=42 # Random seed for reproducibility
|
132
148
|
)
|
133
149
|
|
134
150
|
# Fit the model
|
@@ -162,7 +178,7 @@ loaded_model.load("outputs/model.json")
|
|
162
178
|
|
163
179
|
### Classification Example
|
164
180
|
```python
|
165
|
-
from oikan
|
181
|
+
from oikan import OIKANClassifier
|
166
182
|
from sklearn.metrics import accuracy_score
|
167
183
|
|
168
184
|
# Initialize model
|
@@ -177,7 +193,8 @@ model = OIKANClassifier(
|
|
177
193
|
lr=0.001, # Learning rate
|
178
194
|
batch_size=32, # Batch size for training
|
179
195
|
verbose=True, # Verbose output during training
|
180
|
-
evaluate_nn=True # Validate neural network performance before full process
|
196
|
+
evaluate_nn=True, # Validate neural network performance before full process
|
197
|
+
random_state=42 # Random seed for reproducibility
|
181
198
|
)
|
182
199
|
|
183
200
|
# Fit the model
|
@@ -211,6 +228,12 @@ loaded_model.load("outputs/model.json")
|
|
211
228
|
|
212
229
|
### Architecture Diagram
|
213
230
|
|
231
|
+
#### High-Level Architecture:
|
232
|
+
|
233
|
+

|
234
|
+
|
235
|
+
#### UML Diagram:
|
236
|
+
|
214
237
|
-architecture-oop.png)
|
215
238
|
|
216
239
|
## OIKAN Symbolic Model Compilers
|
@@ -0,0 +1,10 @@
|
|
1
|
+
oikan/__init__.py,sha256=zEzhm1GYLT4vNaIQ4CgZcNpUk3uo8SWnoaHYtHW_XSQ,628
|
2
|
+
oikan/exceptions.py,sha256=GhHWqy2Q5LVBcteTy4ngnqxr7FOoLNyD8dNt1kfRXyw,901
|
3
|
+
oikan/model.py,sha256=TC2-R00GOjFb7ePzKTqeYkOiVlqUK7KP0mXsnJhg9ik,24736
|
4
|
+
oikan/neural.py,sha256=PZjaffSuABuCNxu-7PinU1GR6ji0Y6xRgSQ3n5HRDxI,1572
|
5
|
+
oikan/utils.py,sha256=7UCm9obO-8Q2zhetdAkukMDOZvGSBWUL_dSF04XqM7k,8808
|
6
|
+
oikan-0.0.3.7.dist-info/licenses/LICENSE,sha256=75ASVmU-XIpN-M4LbVmJ_ibgbzbvRLVti8FhnR0BTf8,1096
|
7
|
+
oikan-0.0.3.7.dist-info/METADATA,sha256=nrel6O7TXdbtJHSNCzvqPq_IELeQWx0azfrU4Jq6sps,12749
|
8
|
+
oikan-0.0.3.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
+
oikan-0.0.3.7.dist-info/top_level.txt,sha256=XwnwKwTJddZwIvtrUsAz-l-58BJRj6HjAGWrfYi_3QY,6
|
10
|
+
oikan-0.0.3.7.dist-info/RECORD,,
|
oikan-0.0.3.5.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
oikan/__init__.py,sha256=zEzhm1GYLT4vNaIQ4CgZcNpUk3uo8SWnoaHYtHW_XSQ,628
|
2
|
-
oikan/exceptions.py,sha256=GhHWqy2Q5LVBcteTy4ngnqxr7FOoLNyD8dNt1kfRXyw,901
|
3
|
-
oikan/model.py,sha256=Ke5FdHOr1YwnUCJieXN2VjTXhxAGxHWzCfNgw0_WYbA,23157
|
4
|
-
oikan/neural.py,sha256=wxmGgzmtpwJ3lvH6u6D4i4BiAzg018czrIdw49phSCY,1558
|
5
|
-
oikan/utils.py,sha256=7UCm9obO-8Q2zhetdAkukMDOZvGSBWUL_dSF04XqM7k,8808
|
6
|
-
oikan-0.0.3.5.dist-info/licenses/LICENSE,sha256=75ASVmU-XIpN-M4LbVmJ_ibgbzbvRLVti8FhnR0BTf8,1096
|
7
|
-
oikan-0.0.3.5.dist-info/METADATA,sha256=sUzI5w2hfUd70B4s1K5vULOvQpQbkvb239NTfS2gAPU,11388
|
8
|
-
oikan-0.0.3.5.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
9
|
-
oikan-0.0.3.5.dist-info/top_level.txt,sha256=XwnwKwTJddZwIvtrUsAz-l-58BJRj6HjAGWrfYi_3QY,6
|
10
|
-
oikan-0.0.3.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|