eggp 2.2.0__tar.gz → 2.2.2__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.
- {eggp-2.2.0 → eggp-2.2.2}/PKG-INFO +37 -1
- {eggp-2.2.0 → eggp-2.2.2}/README.md +36 -0
- {eggp-2.2.0 → eggp-2.2.2}/pyproject.toml +1 -1
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp/__init__.py +39 -18
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp/binding.i +5 -1
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/PKG-INFO +37 -1
- {eggp-2.2.0 → eggp-2.2.2}/LICENSE +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/setup.cfg +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/setup.py +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp/__main__.py +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp/_binding.pyi +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp/typing.py +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/SOURCES.txt +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/dependency_links.txt +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/entry_points.txt +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/requires.txt +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/src/eggp.egg-info/top_level.txt +0 -0
- {eggp-2.2.0 → eggp-2.2.2}/test/test_pyeggp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: eggp
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.2
|
|
4
4
|
Summary: Python Wheels for eggp algorithm.
|
|
5
5
|
Author-email: Fabricio Olivetti <folivetti@users.noreply.github.com>
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -908,6 +908,42 @@ mse = mean_squared_error(y_test, y_pred)
|
|
|
908
908
|
print(f"Test MSE: {mse}")
|
|
909
909
|
```
|
|
910
910
|
|
|
911
|
+
### Multithreading / RTS options
|
|
912
|
+
|
|
913
|
+
eggp uses GHC's runtime system; the number of Haskell capabilities is
|
|
914
|
+
controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
|
|
915
|
+
first eggp call (ideally before `import eggp`):
|
|
916
|
+
|
|
917
|
+
```bash
|
|
918
|
+
GHCRTS="-N8" python script.py # 8 capabilities
|
|
919
|
+
GHCRTS="-N" python script.py # all available cores
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
or in Python, before the first fit:
|
|
923
|
+
|
|
924
|
+
```python
|
|
925
|
+
import os
|
|
926
|
+
os.environ["GHCRTS"] = "-N8" # or "-N"
|
|
927
|
+
import eggp
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
For an explicit override of `GHCRTS`, initialize the RTS yourself before the
|
|
931
|
+
first run:
|
|
932
|
+
|
|
933
|
+
```python
|
|
934
|
+
import eggp
|
|
935
|
+
|
|
936
|
+
with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
|
|
937
|
+
model = eggp.EGGP(...)
|
|
938
|
+
model.fit(X, y)
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
The RTS can only be initialized once per process, so set this before the first
|
|
942
|
+
eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
|
|
943
|
+
OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
|
|
944
|
+
`OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
|
|
945
|
+
also accepts `eggp +RTS -N8 -RTS ...`.
|
|
946
|
+
|
|
911
947
|
## Parameters
|
|
912
948
|
|
|
913
949
|
| Parameter | Type | Default | Description |
|
|
@@ -206,6 +206,42 @@ mse = mean_squared_error(y_test, y_pred)
|
|
|
206
206
|
print(f"Test MSE: {mse}")
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
+
### Multithreading / RTS options
|
|
210
|
+
|
|
211
|
+
eggp uses GHC's runtime system; the number of Haskell capabilities is
|
|
212
|
+
controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
|
|
213
|
+
first eggp call (ideally before `import eggp`):
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
GHCRTS="-N8" python script.py # 8 capabilities
|
|
217
|
+
GHCRTS="-N" python script.py # all available cores
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
or in Python, before the first fit:
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
import os
|
|
224
|
+
os.environ["GHCRTS"] = "-N8" # or "-N"
|
|
225
|
+
import eggp
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
For an explicit override of `GHCRTS`, initialize the RTS yourself before the
|
|
229
|
+
first run:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
import eggp
|
|
233
|
+
|
|
234
|
+
with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
|
|
235
|
+
model = eggp.EGGP(...)
|
|
236
|
+
model.fit(X, y)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The RTS can only be initialized once per process, so set this before the first
|
|
240
|
+
eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
|
|
241
|
+
OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
|
|
242
|
+
`OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
|
|
243
|
+
also accepts `eggp +RTS -N8 -RTS ...`.
|
|
244
|
+
|
|
209
245
|
## Parameters
|
|
210
246
|
|
|
211
247
|
| Parameter | Type | Default | Description |
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "eggp"
|
|
15
|
-
version = "2.2.
|
|
15
|
+
version = "2.2.2"
|
|
16
16
|
authors = [{ name = "Fabricio Olivetti", email = "folivetti@users.noreply.github.com" }]
|
|
17
17
|
description = "Python Wheels for eggp algorithm."
|
|
18
18
|
readme = "README.md"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import atexit
|
|
2
2
|
from contextlib import contextmanager
|
|
3
3
|
from threading import Lock
|
|
4
|
-
from typing import Iterator, List
|
|
4
|
+
from typing import Iterator, List, Optional
|
|
5
5
|
import string
|
|
6
6
|
from io import StringIO
|
|
7
7
|
import os
|
|
@@ -15,12 +15,17 @@ from sklearn.utils.validation import check_X_y, check_array, check_is_fitted
|
|
|
15
15
|
from sklearn.metrics import mean_squared_error, r2_score
|
|
16
16
|
import matplotlib.pyplot as plt
|
|
17
17
|
|
|
18
|
-
# GHC
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
# GHC reads the GHCRTS env var when the RTS is initialized (at the first
|
|
19
|
+
# hs_init call, during the first eggp call). Set GHCRTS before the first eggp
|
|
20
|
+
# call (ideally before this import) to customize the runtime, e.g.
|
|
21
|
+
# GHCRTS="-N8" for 8 capabilities or GHCRTS="-N" for all cores. Keep the
|
|
22
|
+
# historical default of 4 capabilities when the user did not specify -N
|
|
23
|
+
# themselves; other GHCRTS flags (e.g. GC tuning) are preserved.
|
|
24
|
+
_ghcrts = os.environ.get("GHCRTS", "")
|
|
25
|
+
_has_n = any(tok == "-N" or (tok.startswith("-N") and tok[2:].isdigit())
|
|
26
|
+
for tok in _ghcrts.split())
|
|
27
|
+
if not _has_n:
|
|
28
|
+
os.environ["GHCRTS"] = (_ghcrts + " -N4").strip()
|
|
24
29
|
|
|
25
30
|
from ._binding import (
|
|
26
31
|
unsafe_hs_eggp_version,
|
|
@@ -50,7 +55,7 @@ def _get_hs_eggp_run_data():
|
|
|
50
55
|
_hs_eggp_run_data = lib.hs_eggp_run_data
|
|
51
56
|
return _hs_eggp_run_data
|
|
52
57
|
|
|
53
|
-
VERSION: str = "2.2.
|
|
58
|
+
VERSION: str = "2.2.2"
|
|
54
59
|
|
|
55
60
|
|
|
56
61
|
_hs_rts_init: bool = False
|
|
@@ -63,13 +68,24 @@ def hs_rts_exit() -> None:
|
|
|
63
68
|
|
|
64
69
|
|
|
65
70
|
@contextmanager
|
|
66
|
-
def hs_rts_init(args: List[str] =
|
|
71
|
+
def hs_rts_init(args: Optional[List[str]] = None) -> Iterator[None]:
|
|
72
|
+
''' Initialize the GHC RTS once (the first eggp call does this implicitly).
|
|
73
|
+
|
|
74
|
+
With no ``args`` the RTS reads ``GHCRTS``: e.g. ``GHCRTS="-N8"`` for 8
|
|
75
|
+
capabilities or ``GHCRTS="-N"`` for all cores. The package defaults to
|
|
76
|
+
``-N4`` when no ``-N`` is present in ``GHCRTS``. Passing explicit
|
|
77
|
+
arguments such as ``["eggp", "+RTS", "-N8", "-RTS"]`` overrides
|
|
78
|
+
``GHCRTS``.
|
|
79
|
+
|
|
80
|
+
The RTS can only be initialized once per process, so set ``GHCRTS`` or
|
|
81
|
+
call this before the first eggp run.
|
|
82
|
+
'''
|
|
67
83
|
global _hs_rts_init
|
|
68
84
|
global _hs_rts_lock
|
|
69
85
|
with _hs_rts_lock:
|
|
70
86
|
if not _hs_rts_init:
|
|
71
87
|
_hs_rts_init = True
|
|
72
|
-
unsafe_hs_eggp_init(args)
|
|
88
|
+
unsafe_hs_eggp_init(["eggp"] if args is None else args)
|
|
73
89
|
atexit.register(hs_rts_exit)
|
|
74
90
|
yield None
|
|
75
91
|
|
|
@@ -81,11 +97,10 @@ def version() -> str:
|
|
|
81
97
|
|
|
82
98
|
def main(args: List[str] = []) -> int:
|
|
83
99
|
# args often come from sys.argv which includes the program name at [0].
|
|
84
|
-
# Strip it
|
|
100
|
+
# Strip it; GHCRTS (or an explicit +RTS section in the CLI args) controls
|
|
101
|
+
# the RTS, so do not inject -N here.
|
|
85
102
|
cli_args = args[1:] if args and not args[0].startswith('-') else args
|
|
86
|
-
|
|
87
|
-
rts_args = ["eggp"] + rts_flags
|
|
88
|
-
with hs_rts_init(rts_args + cli_args):
|
|
103
|
+
with hs_rts_init(["eggp"] + cli_args):
|
|
89
104
|
return unsafe_hs_eggp_main()
|
|
90
105
|
|
|
91
106
|
def eggp_run(dataset: str, gen: int, nPop: int, maxSize: int, nTournament: int, pc: float, pm: float, nonterminals: str, loss: str, optIter: int, optRepeat: int, nParams: int, split: int, max_time : int, simplify: int, trace : int, generational : int, dumpTo: str, loadFrom: str, varnames : str, useFracBayes: int, dbFile: str = "", dbFitFile: str = "", dbDataset: str = "", dbCacheSize: int = 100000, dbFlushEvery: int = 0) -> str:
|
|
@@ -486,14 +501,20 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
486
501
|
|
|
487
502
|
if x.ndim == 1:
|
|
488
503
|
x = x.reshape(-1,1)
|
|
489
|
-
|
|
504
|
+
best = self._best_row()
|
|
505
|
+
tStr = best.theta.split(";")
|
|
490
506
|
t = np.array(list(map(float, tStr))) if len(tStr[0]) > 0 else np.array([])
|
|
491
|
-
y = eval(
|
|
507
|
+
y = eval(best.Numpy)
|
|
492
508
|
if self.loss == "Bernoulli":
|
|
493
509
|
return 1/(1 + np.exp(-y))
|
|
494
510
|
elif self.loss == "Poisson":
|
|
495
511
|
return np.exp(y)
|
|
496
512
|
return y
|
|
513
|
+
def _best_row(self):
|
|
514
|
+
"""Select the best model (lowest training loss)."""
|
|
515
|
+
lt = pd.to_numeric(self.results["loss_train"], errors="coerce")
|
|
516
|
+
return self.results.loc[lt.idxmin()]
|
|
517
|
+
|
|
497
518
|
def evaluate_best_model_view(self, x, view):
|
|
498
519
|
if view not in np.unique(self.results.view.values):
|
|
499
520
|
raise ValueError("Invalid view index")
|
|
@@ -501,8 +522,8 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
501
522
|
x = x.to_numpy()
|
|
502
523
|
if x.ndim == 1:
|
|
503
524
|
x = x.reshape(-1,1)
|
|
504
|
-
ix = self.
|
|
505
|
-
best = self.results[self.results.id==ix].iloc[
|
|
525
|
+
ix = self._best_row().id
|
|
526
|
+
best = self.results[(self.results.id==ix) & (self.results.view==view)].iloc[0]
|
|
506
527
|
t = np.array(list(map(float, best.theta.split(";")))) if len(best.theta) > 0 else np.array([])
|
|
507
528
|
y = eval(best.Numpy)
|
|
508
529
|
if self.loss == "Bernoulli":
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
%{
|
|
3
3
|
#include "EGGP_stub.h"
|
|
4
4
|
|
|
5
|
+
/* RTS options are accepted only through hs_init_with_rtsopts for a shared
|
|
6
|
+
library; declare it explicitly (RtsAPI.h) since the stub header may not. */
|
|
7
|
+
extern void hs_init_with_rtsopts(int *argc, char **argv[]);
|
|
8
|
+
|
|
5
9
|
char * unsafe_hs_eggp_version() {
|
|
6
10
|
return hs_eggp_version();
|
|
7
11
|
}
|
|
@@ -15,7 +19,7 @@ char * unsafe_hs_eggp_run( char *dataset, int gens, int nPop, int maxSize, int n
|
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
void unsafe_hs_eggp_init(int argc, char **argv) {
|
|
18
|
-
|
|
22
|
+
hs_init_with_rtsopts(&argc, &argv);
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
void unsafe_hs_eggp_exit() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: eggp
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.2
|
|
4
4
|
Summary: Python Wheels for eggp algorithm.
|
|
5
5
|
Author-email: Fabricio Olivetti <folivetti@users.noreply.github.com>
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -908,6 +908,42 @@ mse = mean_squared_error(y_test, y_pred)
|
|
|
908
908
|
print(f"Test MSE: {mse}")
|
|
909
909
|
```
|
|
910
910
|
|
|
911
|
+
### Multithreading / RTS options
|
|
912
|
+
|
|
913
|
+
eggp uses GHC's runtime system; the number of Haskell capabilities is
|
|
914
|
+
controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
|
|
915
|
+
first eggp call (ideally before `import eggp`):
|
|
916
|
+
|
|
917
|
+
```bash
|
|
918
|
+
GHCRTS="-N8" python script.py # 8 capabilities
|
|
919
|
+
GHCRTS="-N" python script.py # all available cores
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
or in Python, before the first fit:
|
|
923
|
+
|
|
924
|
+
```python
|
|
925
|
+
import os
|
|
926
|
+
os.environ["GHCRTS"] = "-N8" # or "-N"
|
|
927
|
+
import eggp
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
For an explicit override of `GHCRTS`, initialize the RTS yourself before the
|
|
931
|
+
first run:
|
|
932
|
+
|
|
933
|
+
```python
|
|
934
|
+
import eggp
|
|
935
|
+
|
|
936
|
+
with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
|
|
937
|
+
model = eggp.EGGP(...)
|
|
938
|
+
model.fit(X, y)
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
The RTS can only be initialized once per process, so set this before the first
|
|
942
|
+
eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
|
|
943
|
+
OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
|
|
944
|
+
`OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
|
|
945
|
+
also accepts `eggp +RTS -N8 -RTS ...`.
|
|
946
|
+
|
|
911
947
|
## Parameters
|
|
912
948
|
|
|
913
949
|
| Parameter | Type | Default | Description |
|
|
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
|