eggp 2.2.1__tar.gz → 2.2.3__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.1 → eggp-2.2.3}/PKG-INFO +211 -33
- eggp-2.2.3/README.md +481 -0
- {eggp-2.2.1 → eggp-2.2.3}/pyproject.toml +1 -1
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp/__init__.py +89 -15
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp/binding.i +5 -1
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/PKG-INFO +211 -33
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/SOURCES.txt +0 -1
- eggp-2.2.1/README.md +0 -303
- eggp-2.2.1/src/eggp/binding.py +0 -66
- {eggp-2.2.1 → eggp-2.2.3}/LICENSE +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/setup.cfg +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/setup.py +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp/__main__.py +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp/_binding.pyi +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp/typing.py +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/dependency_links.txt +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/entry_points.txt +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/requires.txt +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/src/eggp.egg-info/top_level.txt +0 -0
- {eggp-2.2.1 → eggp-2.2.3}/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.3
|
|
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
|
|
@@ -719,32 +719,33 @@ Instructions:
|
|
|
719
719
|
|
|
720
720
|
## CLI
|
|
721
721
|
|
|
722
|
-
### How to use
|
|
722
|
+
### How to use
|
|
723
723
|
|
|
724
|
-
|
|
725
|
-
eggp - E-graph Genetic Programming for Symbolic Regression.
|
|
724
|
+
Run `eggp --help` for the authoritative option list. Current usage:
|
|
726
725
|
|
|
726
|
+
```bash
|
|
727
727
|
Usage: eggp (-d|--dataset INPUT-FILE) [-t|--test ARG] [-g|--generations GENS]
|
|
728
|
-
(-s|--maxSize ARG) [-k|--
|
|
729
|
-
[--
|
|
730
|
-
[--
|
|
731
|
-
[--
|
|
732
|
-
[--
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
https://arxiv.org/abs/2501.17848
|
|
728
|
+
(-s|--maxSize ARG) [-k|--folds ARG] [--trace] [--loss ARG]
|
|
729
|
+
[--opt-iter ARG] [--opt-retries ARG] [--number-params ARG]
|
|
730
|
+
[--nPop ARG] [--tournament-size ARG] [--pc ARG] [--pm ARG]
|
|
731
|
+
[--non-terminals ARG] [--dump-to ARG] [--load-from ARG]
|
|
732
|
+
[--generational] [--simplify] [--max-time ARG] [--varnames ARG]
|
|
733
|
+
[--frac-bayes-complexity] [--backend ARG] [--db-file ARG]
|
|
734
|
+
[--db-fit-file ARG] [--db-dataset ARG] [--db-cache-size ARG]
|
|
735
|
+
[--db-flush-every ARG]
|
|
737
736
|
|
|
738
737
|
Available options:
|
|
739
738
|
-d,--dataset INPUT-FILE CSV dataset.
|
|
740
739
|
-t,--test ARG test data (default: "")
|
|
741
740
|
-g,--generations GENS Number of generations. (default: 100)
|
|
742
741
|
-s,--maxSize ARG max-size.
|
|
743
|
-
-k,--
|
|
744
|
-
|
|
742
|
+
-k,--folds ARG number of folds to determine the ratio of
|
|
743
|
+
training-validation (default: 1)
|
|
745
744
|
--trace print all evaluated expressions.
|
|
746
|
-
--loss ARG loss function: MSE,
|
|
747
|
-
(
|
|
745
|
+
--loss ARG loss function: MSE, LOG10, MAE, MAPE, Pinball, or a
|
|
746
|
+
distribution (Gaussian, HGaussian, Poisson,
|
|
747
|
+
Bernoulli, ROXY, LeastSquares).
|
|
748
|
+
(default: NLL LeastSquares)
|
|
748
749
|
--opt-iter ARG number of iterations in parameter optimization.
|
|
749
750
|
(default: 30)
|
|
750
751
|
--opt-retries ARG number of retries of parameter fitting. (default: 1)
|
|
@@ -760,27 +761,145 @@ Available options:
|
|
|
760
761
|
(default: "Add,Sub,Mul,Div,PowerAbs,Recip")
|
|
761
762
|
--dump-to ARG dump final e-graph to a file. (default: "")
|
|
762
763
|
--load-from ARG load initial e-graph from a file. (default: "")
|
|
763
|
-
--
|
|
764
|
-
instead of
|
|
764
|
+
--generational replace the current population with the children
|
|
765
|
+
instead of keeping the pareto front.
|
|
766
|
+
--simplify simplify the expressions before displaying them.
|
|
767
|
+
--max-time ARG maximum allowed time budget (in seconds, -1 it will
|
|
768
|
+
run for the number of generations) (default: -1)
|
|
769
|
+
--varnames ARG comma separated variable names. (default: "")
|
|
770
|
+
--frac-bayes-complexity Use n_nodes * log unique_nodes as the second
|
|
771
|
+
objective.
|
|
772
|
+
--backend ARG AD backend: MultiThread or SingleThread.
|
|
773
|
+
(default: MultiThread)
|
|
774
|
+
--db-file ARG SQLite database file for persistent e-graph (empty =
|
|
775
|
+
in-memory). (default: "")
|
|
776
|
+
--db-fit-file ARG SQLite database file for fitness cache (empty =
|
|
777
|
+
in-memory). (default: "")
|
|
778
|
+
--db-dataset ARG Dataset name for DB mode (empty = derive from CSV
|
|
779
|
+
filename). (default: "")
|
|
780
|
+
--db-cache-size ARG Max entries in the local fitness cache.
|
|
781
|
+
(default: 100000)
|
|
782
|
+
--db-flush-every ARG Flush e-graph to DB every N generations (0 = only at
|
|
783
|
+
end). (default: 0)
|
|
784
|
+
--no-ci Do not compute profile-likelihood confidence
|
|
785
|
+
intervals on the final Pareto front.
|
|
765
786
|
-h,--help Show this help text
|
|
766
787
|
```
|
|
767
788
|
|
|
768
|
-
The
|
|
789
|
+
The final Pareto front includes profile-likelihood confidence intervals. They
|
|
790
|
+
are expensive (each parameter is profiled with many NLopt re-optimizations), so
|
|
791
|
+
the whole stage has a wall-clock budget controlled by the `EGGP_CI_TIMEOUT`
|
|
792
|
+
environment variable: unset = 10 seconds, `0` = skip CIs (columns left empty),
|
|
793
|
+
`-1` = unlimited (old behavior), `N` = `N` seconds. Python users can set the
|
|
794
|
+
same budget with the `ciTimeout` constructor argument.
|
|
795
|
+
|
|
796
|
+
#### Option groups
|
|
797
|
+
|
|
798
|
+
**Input data**
|
|
799
|
+
|
|
800
|
+
- `-d, --dataset FILE` (required) — dataset to fit. Accepts the extended
|
|
801
|
+
`path:start:end:target:features` syntax described below. Several files in
|
|
802
|
+
one quoted argument (`"a.csv b.csv"`) enable multi-view regression.
|
|
803
|
+
- `-t, --test FILE` — optional held-out test set, same syntax as `--dataset`
|
|
804
|
+
(one entry per view). If omitted, the training data is reused for the
|
|
805
|
+
`loss_test`/`R2_test` columns.
|
|
806
|
+
- `-k, --folds N` — splits each view into training/validation. `N=1` (default)
|
|
807
|
+
fits and scores on all rows; `N>1` holds out roughly `1/N` of the rows for
|
|
808
|
+
validation (`loss_val`, `R2_val`, and the validation-based model selection).
|
|
809
|
+
|
|
810
|
+
**Search budget and report**
|
|
811
|
+
|
|
812
|
+
- `-g, --generations N` — number of generations (default 100).
|
|
813
|
+
- `-s, --maxSize N` (required) — maximum expression size in nodes.
|
|
814
|
+
- `--max-time N` — wall-clock budget in seconds (`-1`, default, means run the
|
|
815
|
+
full `--generations`).
|
|
816
|
+
- `--trace` — emit a CSV row for every evaluated expression instead of only
|
|
817
|
+
the final Pareto front.
|
|
818
|
+
- `--simplify` — run a final equality-saturation simplification before printing
|
|
819
|
+
expressions.
|
|
820
|
+
- `--varnames NAMES` — comma-separated column names used when
|
|
821
|
+
rendering expressions (display/numpy/latex output only).
|
|
822
|
+
|
|
823
|
+
**Population and variation**
|
|
824
|
+
|
|
825
|
+
- `--nPop N` — population size (default 100).
|
|
826
|
+
- `--tournament-size N` — tournament size for parent selection (default 2).
|
|
827
|
+
- `--pc P` — crossover probability (default 1.0).
|
|
828
|
+
- `--pm P` — mutation probability (default 0.3).
|
|
829
|
+
- `--non-terminals LIST` — comma-separated function set (default
|
|
830
|
+
`Add,Sub,Mul,Div,PowerAbs,Recip`); see [Available Functions](#available-functions).
|
|
831
|
+
- `--generational` — replace the population with the children each generation
|
|
832
|
+
instead of keeping the Pareto-front-elitist population.
|
|
833
|
+
- `--frac-bayes-complexity` — use `n_nodes * log(unique_nodes)` as the
|
|
834
|
+
secondary objective (fractional Bayes complexity) instead of node count.
|
|
835
|
+
|
|
836
|
+
**Parameter optimisation**
|
|
837
|
+
|
|
838
|
+
- `--opt-iter N` — NLopt iterations per fit (default 30).
|
|
839
|
+
- `--opt-retries N` — random restarts per fit (default 1).
|
|
840
|
+
- `--number-params N` — maximum parameter count. `-1` (default) bounds it by
|
|
841
|
+
`--maxSize` and forbids repeated parameters; `0` disables parameters
|
|
842
|
+
(constants only); `N>0` allows up to `N` parameters, which may repeat.
|
|
843
|
+
- `--backend AD` — automatic-differentiation backend, `MultiThread` (default)
|
|
844
|
+
or `SingleThread`.
|
|
845
|
+
|
|
846
|
+
**Loss function**
|
|
847
|
+
|
|
848
|
+
- `--loss LOSS` — default `NLL LeastSquares` (ordinary least squares). Accepts
|
|
849
|
+
direct losses `MSE`, `LOG10`, `MAE`, `MAPE`, and `Pinball TAU` (quote it,
|
|
850
|
+
e.g. `--loss "Pinball 0.9"`), or a distribution wrapped in an NLL:
|
|
851
|
+
`Gaussian`, `HGaussian`, `Poisson`, `Bernoulli`, `ROXY`, `LeastSquares`
|
|
852
|
+
(e.g. `--loss Gaussian`). The reported `fitness` is the minimised loss.
|
|
853
|
+
|
|
854
|
+
**E-graph persistence**
|
|
855
|
+
|
|
856
|
+
- `--dump-to FILE` — write the final e-graph to a binary file at the end.
|
|
857
|
+
- `--load-from FILE` — resume from a binary e-graph written by `--dump-to`.
|
|
858
|
+
- `--db-file FILE` — SQLite database for the **e-graph structure**. When set
|
|
859
|
+
(and `--load-from` is not), a previous graph in this file is loaded and the
|
|
860
|
+
search resumes from it; the graph is synced every `--db-flush-every`
|
|
861
|
+
generations and at the end. Empty means in-memory only.
|
|
862
|
+
- `--db-fit-file FILE` — SQLite database for the **fitness cache and expression
|
|
863
|
+
index**. Used to skip NLopt for already-fitted e-classes and to avoid
|
|
864
|
+
re-exploring known expressions. Empty disables fitness reuse. Rows that refer
|
|
865
|
+
to e-classes missing from the current graph are pruned at startup.
|
|
866
|
+
- `--db-dataset NAME` — dataset key inside the DB. Defaults to the basename of
|
|
867
|
+
the first `--dataset` file.
|
|
868
|
+
- `--db-cache-size N` — size hint for the local fitness cache (default 100000;
|
|
869
|
+
currently the cache is loaded in full, so this is reserved).
|
|
870
|
+
- `--db-flush-every N` — sync the e-graph to `--db-file` every `N` generations
|
|
871
|
+
(`0`, default, means only at the end).
|
|
872
|
+
|
|
873
|
+
`--db-file` and `--db-fit-file` are intentionally separate: the structural
|
|
874
|
+
e-graph stays read-only during fitting, while the fit cache is written
|
|
875
|
+
frequently, which avoids WAL bloat. Use both for full resumable DB mode:
|
|
876
|
+
|
|
877
|
+
```bash
|
|
878
|
+
eggp -d gaussian_train.csv -s 15 -g 100 \
|
|
879
|
+
--db-file egraph.db --db-fit-file fit_gaussian.db --db-dataset gaussian
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
#### Data format
|
|
883
|
+
|
|
884
|
+
The dataset file must contain a header with the feature names. `--dataset` and
|
|
885
|
+
`--test` accept optional fields separated by `:` in the format:
|
|
769
886
|
|
|
770
887
|
`filename.ext:start_row:end_row:target:features`
|
|
771
888
|
|
|
772
|
-
where each
|
|
889
|
+
where each field is optional. The fields are:
|
|
773
890
|
|
|
774
891
|
- **start_row:end_row** is the range of the training rows (default 0:nrows-1).
|
|
775
892
|
every other row not included in this range will be used as validation
|
|
776
|
-
- **target** is either the name of the
|
|
777
|
-
|
|
893
|
+
- **target** is either the name of the target column (if the file has headers)
|
|
894
|
+
or its index
|
|
778
895
|
- **features** is a comma separated list of names or indices to be used as
|
|
779
896
|
input variables of the regression model.
|
|
780
897
|
|
|
781
|
-
|
|
898
|
+
Examples: `dataset.csv`, `mydata.tsv`, `dataset.csv:20:100`,
|
|
899
|
+
`dataset.tsv:20:100:price:m2,rooms,neighborhood`, `dataset.csv:::5:0,1,2`.
|
|
782
900
|
|
|
783
|
-
The
|
|
901
|
+
The file format is inferred from the extension (e.g. csv, tsv, ...). To use
|
|
902
|
+
multi-view, pass several filenames in one quoted argument:
|
|
784
903
|
|
|
785
904
|
```bash
|
|
786
905
|
eggp --dataset "dataset1.csv dataset2.csv dataset3.csv" ...
|
|
@@ -822,8 +941,8 @@ For Windows, run the following in a PowerShell:
|
|
|
822
941
|
Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { & ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -Interactive -DisableCurl } catch { Write-Error $_ }
|
|
823
942
|
```
|
|
824
943
|
|
|
825
|
-
After the installation, run `ghcup tui` and install the latest `stack` or `cabal` together with `ghc-9.
|
|
826
|
-
To install `
|
|
944
|
+
After the installation, run `ghcup tui` and install the latest `stack` or `cabal` together with `ghc-9.14.1` (select the items and press `i`).
|
|
945
|
+
To install `eggp` simply run:
|
|
827
946
|
|
|
828
947
|
```bash
|
|
829
948
|
cabal install
|
|
@@ -908,6 +1027,42 @@ mse = mean_squared_error(y_test, y_pred)
|
|
|
908
1027
|
print(f"Test MSE: {mse}")
|
|
909
1028
|
```
|
|
910
1029
|
|
|
1030
|
+
### Multithreading / RTS options
|
|
1031
|
+
|
|
1032
|
+
eggp uses GHC's runtime system; the number of Haskell capabilities is
|
|
1033
|
+
controlled by the RTS `-N` flag and defaults to **4**. Set `GHCRTS` before the
|
|
1034
|
+
first eggp call (ideally before `import eggp`):
|
|
1035
|
+
|
|
1036
|
+
```bash
|
|
1037
|
+
GHCRTS="-N8" python script.py # 8 capabilities
|
|
1038
|
+
GHCRTS="-N" python script.py # all available cores
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
or in Python, before the first fit:
|
|
1042
|
+
|
|
1043
|
+
```python
|
|
1044
|
+
import os
|
|
1045
|
+
os.environ["GHCRTS"] = "-N8" # or "-N"
|
|
1046
|
+
import eggp
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
For an explicit override of `GHCRTS`, initialize the RTS yourself before the
|
|
1050
|
+
first run:
|
|
1051
|
+
|
|
1052
|
+
```python
|
|
1053
|
+
import eggp
|
|
1054
|
+
|
|
1055
|
+
with eggp.hs_rts_init(["eggp", "+RTS", "-N8", "-RTS"]):
|
|
1056
|
+
model = eggp.EGGP(...)
|
|
1057
|
+
model.fit(X, y)
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
The RTS can only be initialized once per process, so set this before the first
|
|
1061
|
+
eggp call. `-N` only controls Haskell capabilities; numerical libraries such as
|
|
1062
|
+
OpenBLAS/OpenMP use their own environment variables (`OPENBLAS_NUM_THREADS`,
|
|
1063
|
+
`OMP_NUM_THREADS`). The standalone `eggp` executable (built with `-rtsopts`)
|
|
1064
|
+
also accepts `eggp +RTS -N8 -RTS ...`.
|
|
1065
|
+
|
|
911
1066
|
## Parameters
|
|
912
1067
|
|
|
913
1068
|
| Parameter | Type | Default | Description |
|
|
@@ -919,14 +1074,37 @@ print(f"Test MSE: {mse}")
|
|
|
919
1074
|
| `pc` | float | 0.9 | Probability of performing crossover |
|
|
920
1075
|
| `pm` | float | 0.3 | Probability of performing mutation |
|
|
921
1076
|
| `nonterminals` | str | "add,sub,mul,div" | Comma-separated list of allowed functions |
|
|
922
|
-
| `loss` | str | "MSE" | Loss
|
|
1077
|
+
| `loss` | str | "MSE" | Loss: "MSE", "LOG10", "MAE", "MAPE", "Pinball", "Gaussian", "Bernoulli", or "Poisson" |
|
|
923
1078
|
| `optIter` | int | 50 | Number of iterations for parameter optimization |
|
|
924
1079
|
| `optRepeat` | int | 2 | Number of restarts for parameter optimization |
|
|
925
|
-
| `nParams` | int | -1 | Maximum number of parameters (
|
|
926
|
-
| `
|
|
927
|
-
| `
|
|
928
|
-
| `
|
|
929
|
-
| `
|
|
1080
|
+
| `nParams` | int | -1 | Maximum number of parameters (`-1` = bounded by `maxSize` and no repeats; `0` = constants only) |
|
|
1081
|
+
| `folds` | int | 1 | Training/validation split; `1` disables validation scoring, `N>1` holds out ~`1/N` |
|
|
1082
|
+
| `max_time` | int | -1 | Wall-clock budget in seconds (`-1` = run all generations) |
|
|
1083
|
+
| `simplify` | bool | False | Apply a final equality-saturation simplification before display |
|
|
1084
|
+
| `trace` | bool | False | Return every evaluated expression instead of only the Pareto front |
|
|
1085
|
+
| `generational` | bool | False | Replace the population with the children instead of keeping the Pareto front |
|
|
1086
|
+
| `dumpTo` | str | "" | Filename to save the final e-graph (binary) |
|
|
1087
|
+
| `loadFrom` | str | "" | Filename to load an e-graph and resume the search |
|
|
1088
|
+
| `useFracBayes` | bool | False | Use fractional Bayes complexity as the secondary objective |
|
|
1089
|
+
| `pinball_tau` | float | 0.5 | Quantile used when `loss="Pinball"` |
|
|
1090
|
+
| `dbFile` | str | "" | SQLite file for the persistent e-graph (empty = in-memory) |
|
|
1091
|
+
| `dbFitFile` | str | "" | SQLite file for the fitness cache / expression index (empty = disabled) |
|
|
1092
|
+
| `dbDataset` | str | "" | Dataset key inside the DB (empty = basename of the data source) |
|
|
1093
|
+
| `dbCacheSize` | int | 100000 | Size hint for the local fitness cache |
|
|
1094
|
+
| `dbFlushEvery` | int | 0 | Sync the e-graph every N generations (`0` = only at the end) |
|
|
1095
|
+
| `ciTimeout` | int/None | None | Wall-clock budget (seconds) for the final profile-likelihood CIs: `0` skips them, `-1` is unlimited, `None` uses `EGGP_CI_TIMEOUT` (default 10 s) |
|
|
1096
|
+
| `computeCI` | bool | True | Set to `False` to skip profile-likelihood CIs entirely (same as `ciTimeout=0`) |
|
|
1097
|
+
|
|
1098
|
+
For resumable DB-backed runs pass both `dbFile` and `dbFitFile` (the e-graph
|
|
1099
|
+
and the frequently-written fit cache live in separate SQLite files):
|
|
1100
|
+
|
|
1101
|
+
```python
|
|
1102
|
+
model = EGGP(
|
|
1103
|
+
gen=100, maxSize=15,
|
|
1104
|
+
dbFile="egraph.db", dbFitFile="fit_mydata.db", dbDataset="mydata",
|
|
1105
|
+
)
|
|
1106
|
+
model.fit(X, y)
|
|
1107
|
+
```
|
|
930
1108
|
|
|
931
1109
|
### Available Functions
|
|
932
1110
|
|