eggp 2.2.2__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.2 → eggp-2.2.3}/PKG-INFO +175 -33
- {eggp-2.2.2 → eggp-2.2.3}/README.md +174 -32
- {eggp-2.2.2 → eggp-2.2.3}/pyproject.toml +1 -1
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp/__init__.py +61 -2
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/PKG-INFO +175 -33
- {eggp-2.2.2 → eggp-2.2.3}/LICENSE +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/setup.cfg +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/setup.py +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp/__main__.py +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp/_binding.pyi +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp/binding.i +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp/typing.py +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/SOURCES.txt +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/dependency_links.txt +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/entry_points.txt +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/requires.txt +0 -0
- {eggp-2.2.2 → eggp-2.2.3}/src/eggp.egg-info/top_level.txt +0 -0
- {eggp-2.2.2 → 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
|
|
@@ -955,14 +1074,37 @@ also accepts `eggp +RTS -N8 -RTS ...`.
|
|
|
955
1074
|
| `pc` | float | 0.9 | Probability of performing crossover |
|
|
956
1075
|
| `pm` | float | 0.3 | Probability of performing mutation |
|
|
957
1076
|
| `nonterminals` | str | "add,sub,mul,div" | Comma-separated list of allowed functions |
|
|
958
|
-
| `loss` | str | "MSE" | Loss
|
|
1077
|
+
| `loss` | str | "MSE" | Loss: "MSE", "LOG10", "MAE", "MAPE", "Pinball", "Gaussian", "Bernoulli", or "Poisson" |
|
|
959
1078
|
| `optIter` | int | 50 | Number of iterations for parameter optimization |
|
|
960
1079
|
| `optRepeat` | int | 2 | Number of restarts for parameter optimization |
|
|
961
|
-
| `nParams` | int | -1 | Maximum number of parameters (
|
|
962
|
-
| `
|
|
963
|
-
| `
|
|
964
|
-
| `
|
|
965
|
-
| `
|
|
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
|
+
```
|
|
966
1108
|
|
|
967
1109
|
### Available Functions
|
|
968
1110
|
|
|
@@ -17,32 +17,33 @@ Instructions:
|
|
|
17
17
|
|
|
18
18
|
## CLI
|
|
19
19
|
|
|
20
|
-
### How to use
|
|
20
|
+
### How to use
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
eggp - E-graph Genetic Programming for Symbolic Regression.
|
|
22
|
+
Run `eggp --help` for the authoritative option list. Current usage:
|
|
24
23
|
|
|
24
|
+
```bash
|
|
25
25
|
Usage: eggp (-d|--dataset INPUT-FILE) [-t|--test ARG] [-g|--generations GENS]
|
|
26
|
-
(-s|--maxSize ARG) [-k|--
|
|
27
|
-
[--
|
|
28
|
-
[--
|
|
29
|
-
[--
|
|
30
|
-
[--
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
https://arxiv.org/abs/2501.17848
|
|
26
|
+
(-s|--maxSize ARG) [-k|--folds ARG] [--trace] [--loss ARG]
|
|
27
|
+
[--opt-iter ARG] [--opt-retries ARG] [--number-params ARG]
|
|
28
|
+
[--nPop ARG] [--tournament-size ARG] [--pc ARG] [--pm ARG]
|
|
29
|
+
[--non-terminals ARG] [--dump-to ARG] [--load-from ARG]
|
|
30
|
+
[--generational] [--simplify] [--max-time ARG] [--varnames ARG]
|
|
31
|
+
[--frac-bayes-complexity] [--backend ARG] [--db-file ARG]
|
|
32
|
+
[--db-fit-file ARG] [--db-dataset ARG] [--db-cache-size ARG]
|
|
33
|
+
[--db-flush-every ARG]
|
|
35
34
|
|
|
36
35
|
Available options:
|
|
37
36
|
-d,--dataset INPUT-FILE CSV dataset.
|
|
38
37
|
-t,--test ARG test data (default: "")
|
|
39
38
|
-g,--generations GENS Number of generations. (default: 100)
|
|
40
39
|
-s,--maxSize ARG max-size.
|
|
41
|
-
-k,--
|
|
42
|
-
|
|
40
|
+
-k,--folds ARG number of folds to determine the ratio of
|
|
41
|
+
training-validation (default: 1)
|
|
43
42
|
--trace print all evaluated expressions.
|
|
44
|
-
--loss ARG loss function: MSE,
|
|
45
|
-
(
|
|
43
|
+
--loss ARG loss function: MSE, LOG10, MAE, MAPE, Pinball, or a
|
|
44
|
+
distribution (Gaussian, HGaussian, Poisson,
|
|
45
|
+
Bernoulli, ROXY, LeastSquares).
|
|
46
|
+
(default: NLL LeastSquares)
|
|
46
47
|
--opt-iter ARG number of iterations in parameter optimization.
|
|
47
48
|
(default: 30)
|
|
48
49
|
--opt-retries ARG number of retries of parameter fitting. (default: 1)
|
|
@@ -58,27 +59,145 @@ Available options:
|
|
|
58
59
|
(default: "Add,Sub,Mul,Div,PowerAbs,Recip")
|
|
59
60
|
--dump-to ARG dump final e-graph to a file. (default: "")
|
|
60
61
|
--load-from ARG load initial e-graph from a file. (default: "")
|
|
61
|
-
--
|
|
62
|
-
instead of
|
|
62
|
+
--generational replace the current population with the children
|
|
63
|
+
instead of keeping the pareto front.
|
|
64
|
+
--simplify simplify the expressions before displaying them.
|
|
65
|
+
--max-time ARG maximum allowed time budget (in seconds, -1 it will
|
|
66
|
+
run for the number of generations) (default: -1)
|
|
67
|
+
--varnames ARG comma separated variable names. (default: "")
|
|
68
|
+
--frac-bayes-complexity Use n_nodes * log unique_nodes as the second
|
|
69
|
+
objective.
|
|
70
|
+
--backend ARG AD backend: MultiThread or SingleThread.
|
|
71
|
+
(default: MultiThread)
|
|
72
|
+
--db-file ARG SQLite database file for persistent e-graph (empty =
|
|
73
|
+
in-memory). (default: "")
|
|
74
|
+
--db-fit-file ARG SQLite database file for fitness cache (empty =
|
|
75
|
+
in-memory). (default: "")
|
|
76
|
+
--db-dataset ARG Dataset name for DB mode (empty = derive from CSV
|
|
77
|
+
filename). (default: "")
|
|
78
|
+
--db-cache-size ARG Max entries in the local fitness cache.
|
|
79
|
+
(default: 100000)
|
|
80
|
+
--db-flush-every ARG Flush e-graph to DB every N generations (0 = only at
|
|
81
|
+
end). (default: 0)
|
|
82
|
+
--no-ci Do not compute profile-likelihood confidence
|
|
83
|
+
intervals on the final Pareto front.
|
|
63
84
|
-h,--help Show this help text
|
|
64
85
|
```
|
|
65
86
|
|
|
66
|
-
The
|
|
87
|
+
The final Pareto front includes profile-likelihood confidence intervals. They
|
|
88
|
+
are expensive (each parameter is profiled with many NLopt re-optimizations), so
|
|
89
|
+
the whole stage has a wall-clock budget controlled by the `EGGP_CI_TIMEOUT`
|
|
90
|
+
environment variable: unset = 10 seconds, `0` = skip CIs (columns left empty),
|
|
91
|
+
`-1` = unlimited (old behavior), `N` = `N` seconds. Python users can set the
|
|
92
|
+
same budget with the `ciTimeout` constructor argument.
|
|
93
|
+
|
|
94
|
+
#### Option groups
|
|
95
|
+
|
|
96
|
+
**Input data**
|
|
97
|
+
|
|
98
|
+
- `-d, --dataset FILE` (required) — dataset to fit. Accepts the extended
|
|
99
|
+
`path:start:end:target:features` syntax described below. Several files in
|
|
100
|
+
one quoted argument (`"a.csv b.csv"`) enable multi-view regression.
|
|
101
|
+
- `-t, --test FILE` — optional held-out test set, same syntax as `--dataset`
|
|
102
|
+
(one entry per view). If omitted, the training data is reused for the
|
|
103
|
+
`loss_test`/`R2_test` columns.
|
|
104
|
+
- `-k, --folds N` — splits each view into training/validation. `N=1` (default)
|
|
105
|
+
fits and scores on all rows; `N>1` holds out roughly `1/N` of the rows for
|
|
106
|
+
validation (`loss_val`, `R2_val`, and the validation-based model selection).
|
|
107
|
+
|
|
108
|
+
**Search budget and report**
|
|
109
|
+
|
|
110
|
+
- `-g, --generations N` — number of generations (default 100).
|
|
111
|
+
- `-s, --maxSize N` (required) — maximum expression size in nodes.
|
|
112
|
+
- `--max-time N` — wall-clock budget in seconds (`-1`, default, means run the
|
|
113
|
+
full `--generations`).
|
|
114
|
+
- `--trace` — emit a CSV row for every evaluated expression instead of only
|
|
115
|
+
the final Pareto front.
|
|
116
|
+
- `--simplify` — run a final equality-saturation simplification before printing
|
|
117
|
+
expressions.
|
|
118
|
+
- `--varnames NAMES` — comma-separated column names used when
|
|
119
|
+
rendering expressions (display/numpy/latex output only).
|
|
120
|
+
|
|
121
|
+
**Population and variation**
|
|
122
|
+
|
|
123
|
+
- `--nPop N` — population size (default 100).
|
|
124
|
+
- `--tournament-size N` — tournament size for parent selection (default 2).
|
|
125
|
+
- `--pc P` — crossover probability (default 1.0).
|
|
126
|
+
- `--pm P` — mutation probability (default 0.3).
|
|
127
|
+
- `--non-terminals LIST` — comma-separated function set (default
|
|
128
|
+
`Add,Sub,Mul,Div,PowerAbs,Recip`); see [Available Functions](#available-functions).
|
|
129
|
+
- `--generational` — replace the population with the children each generation
|
|
130
|
+
instead of keeping the Pareto-front-elitist population.
|
|
131
|
+
- `--frac-bayes-complexity` — use `n_nodes * log(unique_nodes)` as the
|
|
132
|
+
secondary objective (fractional Bayes complexity) instead of node count.
|
|
133
|
+
|
|
134
|
+
**Parameter optimisation**
|
|
135
|
+
|
|
136
|
+
- `--opt-iter N` — NLopt iterations per fit (default 30).
|
|
137
|
+
- `--opt-retries N` — random restarts per fit (default 1).
|
|
138
|
+
- `--number-params N` — maximum parameter count. `-1` (default) bounds it by
|
|
139
|
+
`--maxSize` and forbids repeated parameters; `0` disables parameters
|
|
140
|
+
(constants only); `N>0` allows up to `N` parameters, which may repeat.
|
|
141
|
+
- `--backend AD` — automatic-differentiation backend, `MultiThread` (default)
|
|
142
|
+
or `SingleThread`.
|
|
143
|
+
|
|
144
|
+
**Loss function**
|
|
145
|
+
|
|
146
|
+
- `--loss LOSS` — default `NLL LeastSquares` (ordinary least squares). Accepts
|
|
147
|
+
direct losses `MSE`, `LOG10`, `MAE`, `MAPE`, and `Pinball TAU` (quote it,
|
|
148
|
+
e.g. `--loss "Pinball 0.9"`), or a distribution wrapped in an NLL:
|
|
149
|
+
`Gaussian`, `HGaussian`, `Poisson`, `Bernoulli`, `ROXY`, `LeastSquares`
|
|
150
|
+
(e.g. `--loss Gaussian`). The reported `fitness` is the minimised loss.
|
|
151
|
+
|
|
152
|
+
**E-graph persistence**
|
|
153
|
+
|
|
154
|
+
- `--dump-to FILE` — write the final e-graph to a binary file at the end.
|
|
155
|
+
- `--load-from FILE` — resume from a binary e-graph written by `--dump-to`.
|
|
156
|
+
- `--db-file FILE` — SQLite database for the **e-graph structure**. When set
|
|
157
|
+
(and `--load-from` is not), a previous graph in this file is loaded and the
|
|
158
|
+
search resumes from it; the graph is synced every `--db-flush-every`
|
|
159
|
+
generations and at the end. Empty means in-memory only.
|
|
160
|
+
- `--db-fit-file FILE` — SQLite database for the **fitness cache and expression
|
|
161
|
+
index**. Used to skip NLopt for already-fitted e-classes and to avoid
|
|
162
|
+
re-exploring known expressions. Empty disables fitness reuse. Rows that refer
|
|
163
|
+
to e-classes missing from the current graph are pruned at startup.
|
|
164
|
+
- `--db-dataset NAME` — dataset key inside the DB. Defaults to the basename of
|
|
165
|
+
the first `--dataset` file.
|
|
166
|
+
- `--db-cache-size N` — size hint for the local fitness cache (default 100000;
|
|
167
|
+
currently the cache is loaded in full, so this is reserved).
|
|
168
|
+
- `--db-flush-every N` — sync the e-graph to `--db-file` every `N` generations
|
|
169
|
+
(`0`, default, means only at the end).
|
|
170
|
+
|
|
171
|
+
`--db-file` and `--db-fit-file` are intentionally separate: the structural
|
|
172
|
+
e-graph stays read-only during fitting, while the fit cache is written
|
|
173
|
+
frequently, which avoids WAL bloat. Use both for full resumable DB mode:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
eggp -d gaussian_train.csv -s 15 -g 100 \
|
|
177
|
+
--db-file egraph.db --db-fit-file fit_gaussian.db --db-dataset gaussian
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Data format
|
|
181
|
+
|
|
182
|
+
The dataset file must contain a header with the feature names. `--dataset` and
|
|
183
|
+
`--test` accept optional fields separated by `:` in the format:
|
|
67
184
|
|
|
68
185
|
`filename.ext:start_row:end_row:target:features`
|
|
69
186
|
|
|
70
|
-
where each
|
|
187
|
+
where each field is optional. The fields are:
|
|
71
188
|
|
|
72
189
|
- **start_row:end_row** is the range of the training rows (default 0:nrows-1).
|
|
73
190
|
every other row not included in this range will be used as validation
|
|
74
|
-
- **target** is either the name of the
|
|
75
|
-
|
|
191
|
+
- **target** is either the name of the target column (if the file has headers)
|
|
192
|
+
or its index
|
|
76
193
|
- **features** is a comma separated list of names or indices to be used as
|
|
77
194
|
input variables of the regression model.
|
|
78
195
|
|
|
79
|
-
|
|
196
|
+
Examples: `dataset.csv`, `mydata.tsv`, `dataset.csv:20:100`,
|
|
197
|
+
`dataset.tsv:20:100:price:m2,rooms,neighborhood`, `dataset.csv:::5:0,1,2`.
|
|
80
198
|
|
|
81
|
-
The
|
|
199
|
+
The file format is inferred from the extension (e.g. csv, tsv, ...). To use
|
|
200
|
+
multi-view, pass several filenames in one quoted argument:
|
|
82
201
|
|
|
83
202
|
```bash
|
|
84
203
|
eggp --dataset "dataset1.csv dataset2.csv dataset3.csv" ...
|
|
@@ -120,8 +239,8 @@ For Windows, run the following in a PowerShell:
|
|
|
120
239
|
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 $_ }
|
|
121
240
|
```
|
|
122
241
|
|
|
123
|
-
After the installation, run `ghcup tui` and install the latest `stack` or `cabal` together with `ghc-9.
|
|
124
|
-
To install `
|
|
242
|
+
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`).
|
|
243
|
+
To install `eggp` simply run:
|
|
125
244
|
|
|
126
245
|
```bash
|
|
127
246
|
cabal install
|
|
@@ -253,14 +372,37 @@ also accepts `eggp +RTS -N8 -RTS ...`.
|
|
|
253
372
|
| `pc` | float | 0.9 | Probability of performing crossover |
|
|
254
373
|
| `pm` | float | 0.3 | Probability of performing mutation |
|
|
255
374
|
| `nonterminals` | str | "add,sub,mul,div" | Comma-separated list of allowed functions |
|
|
256
|
-
| `loss` | str | "MSE" | Loss
|
|
375
|
+
| `loss` | str | "MSE" | Loss: "MSE", "LOG10", "MAE", "MAPE", "Pinball", "Gaussian", "Bernoulli", or "Poisson" |
|
|
257
376
|
| `optIter` | int | 50 | Number of iterations for parameter optimization |
|
|
258
377
|
| `optRepeat` | int | 2 | Number of restarts for parameter optimization |
|
|
259
|
-
| `nParams` | int | -1 | Maximum number of parameters (
|
|
260
|
-
| `
|
|
261
|
-
| `
|
|
262
|
-
| `
|
|
263
|
-
| `
|
|
378
|
+
| `nParams` | int | -1 | Maximum number of parameters (`-1` = bounded by `maxSize` and no repeats; `0` = constants only) |
|
|
379
|
+
| `folds` | int | 1 | Training/validation split; `1` disables validation scoring, `N>1` holds out ~`1/N` |
|
|
380
|
+
| `max_time` | int | -1 | Wall-clock budget in seconds (`-1` = run all generations) |
|
|
381
|
+
| `simplify` | bool | False | Apply a final equality-saturation simplification before display |
|
|
382
|
+
| `trace` | bool | False | Return every evaluated expression instead of only the Pareto front |
|
|
383
|
+
| `generational` | bool | False | Replace the population with the children instead of keeping the Pareto front |
|
|
384
|
+
| `dumpTo` | str | "" | Filename to save the final e-graph (binary) |
|
|
385
|
+
| `loadFrom` | str | "" | Filename to load an e-graph and resume the search |
|
|
386
|
+
| `useFracBayes` | bool | False | Use fractional Bayes complexity as the secondary objective |
|
|
387
|
+
| `pinball_tau` | float | 0.5 | Quantile used when `loss="Pinball"` |
|
|
388
|
+
| `dbFile` | str | "" | SQLite file for the persistent e-graph (empty = in-memory) |
|
|
389
|
+
| `dbFitFile` | str | "" | SQLite file for the fitness cache / expression index (empty = disabled) |
|
|
390
|
+
| `dbDataset` | str | "" | Dataset key inside the DB (empty = basename of the data source) |
|
|
391
|
+
| `dbCacheSize` | int | 100000 | Size hint for the local fitness cache |
|
|
392
|
+
| `dbFlushEvery` | int | 0 | Sync the e-graph every N generations (`0` = only at the end) |
|
|
393
|
+
| `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) |
|
|
394
|
+
| `computeCI` | bool | True | Set to `False` to skip profile-likelihood CIs entirely (same as `ciTimeout=0`) |
|
|
395
|
+
|
|
396
|
+
For resumable DB-backed runs pass both `dbFile` and `dbFitFile` (the e-graph
|
|
397
|
+
and the frequently-written fit cache live in separate SQLite files):
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
model = EGGP(
|
|
401
|
+
gen=100, maxSize=15,
|
|
402
|
+
dbFile="egraph.db", dbFitFile="fit_mydata.db", dbDataset="mydata",
|
|
403
|
+
)
|
|
404
|
+
model.fit(X, y)
|
|
405
|
+
```
|
|
264
406
|
|
|
265
407
|
### Available Functions
|
|
266
408
|
|
|
@@ -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.3"
|
|
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"
|
|
@@ -27,6 +27,10 @@ _has_n = any(tok == "-N" or (tok.startswith("-N") and tok[2:].isdigit())
|
|
|
27
27
|
if not _has_n:
|
|
28
28
|
os.environ["GHCRTS"] = (_ghcrts + " -N4").strip()
|
|
29
29
|
|
|
30
|
+
# Default CI budget, captured so per-model `ciTimeout` values do not leak into
|
|
31
|
+
# later EGGP instances (and so an externally set EGGP_CI_TIMEOUT is preserved).
|
|
32
|
+
_EGGP_CI_TIMEOUT_ENV = os.environ.get("EGGP_CI_TIMEOUT")
|
|
33
|
+
|
|
30
34
|
from ._binding import (
|
|
31
35
|
unsafe_hs_eggp_version,
|
|
32
36
|
unsafe_hs_eggp_main,
|
|
@@ -55,7 +59,36 @@ def _get_hs_eggp_run_data():
|
|
|
55
59
|
_hs_eggp_run_data = lib.hs_eggp_run_data
|
|
56
60
|
return _hs_eggp_run_data
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
def _preload_peer_ffi(pkg_name: str) -> None:
|
|
63
|
+
"""Best-effort load a sibling package's GHC shared library.
|
|
64
|
+
|
|
65
|
+
GHC hosts a single RTS per process and does not safely support a Haskell
|
|
66
|
+
shared library being dlopen'd *after* the RTS has been initialized/used
|
|
67
|
+
(e.g. importing ``reggression`` after an EGGP fit). Loading the peer
|
|
68
|
+
binding here keeps both Haskell libraries mapped before the first Haskell
|
|
69
|
+
call, independent of Python import order.
|
|
70
|
+
"""
|
|
71
|
+
try:
|
|
72
|
+
import glob
|
|
73
|
+
import importlib.util
|
|
74
|
+
spec = importlib.util.find_spec(pkg_name)
|
|
75
|
+
if spec is None or not spec.origin:
|
|
76
|
+
return
|
|
77
|
+
pkg_dir = os.path.dirname(spec.origin)
|
|
78
|
+
for pattern in ("_binding*.so", "_binding*.dylib", "_binding*.pyd"):
|
|
79
|
+
for path in glob.glob(os.path.join(pkg_dir, pattern)):
|
|
80
|
+
try:
|
|
81
|
+
ctypes.CDLL(path, mode=getattr(ctypes, "RTLD_GLOBAL", 0))
|
|
82
|
+
return
|
|
83
|
+
except OSError:
|
|
84
|
+
continue
|
|
85
|
+
except Exception:
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
_preload_peer_ffi("reggression")
|
|
90
|
+
|
|
91
|
+
VERSION: str = "2.2.3"
|
|
59
92
|
|
|
60
93
|
|
|
61
94
|
_hs_rts_init: bool = False
|
|
@@ -248,7 +281,7 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
248
281
|
>>> estimator = EGGP(loss="Bernoulli")
|
|
249
282
|
>>> estimator.fit(X, y)
|
|
250
283
|
"""
|
|
251
|
-
def __init__(self, gen = 100, nPop = 100, maxSize = 15, nTournament = 3, pc = 0.9, pm = 0.3, nonterminals = "add,sub,mul,div", loss = "MSE", optIter = 50, optRepeat = 2, nParams = -1, folds = 1, max_time = -1, simplify = False, trace = False, generational = False, dumpTo = "", loadFrom = "", useFracBayes = False, pinball_tau = 0.5, dbFile = "", dbFitFile = "", dbDataset = "", dbCacheSize = 100000, dbFlushEvery = 0):
|
|
284
|
+
def __init__(self, gen = 100, nPop = 100, maxSize = 15, nTournament = 3, pc = 0.9, pm = 0.3, nonterminals = "add,sub,mul,div", loss = "MSE", optIter = 50, optRepeat = 2, nParams = -1, folds = 1, max_time = -1, simplify = False, trace = False, generational = False, dumpTo = "", loadFrom = "", useFracBayes = False, pinball_tau = 0.5, dbFile = "", dbFitFile = "", dbDataset = "", dbCacheSize = 100000, dbFlushEvery = 0, ciTimeout = None, computeCI = True):
|
|
252
285
|
nts = "add,sub,mul,div,power,powerabs,\
|
|
253
286
|
aq,abs,sin,cos,tan,sinh,cosh,tanh,\
|
|
254
287
|
asin,acos,atan,asinh,acosh,atanh,sqrt,\
|
|
@@ -290,6 +323,10 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
290
323
|
raise TypeError('useFracBayes must be a boolean')
|
|
291
324
|
if pinball_tau <= 0 or pinball_tau >= 1:
|
|
292
325
|
raise ValueError('pinball_tau must be a value between 0 and 1')
|
|
326
|
+
if ciTimeout is not None and (not isinstance(ciTimeout, int) or ciTimeout < -1):
|
|
327
|
+
raise ValueError('ciTimeout must be None, -1 (unlimited) or a non-negative number of seconds')
|
|
328
|
+
if not isinstance(computeCI, bool):
|
|
329
|
+
raise TypeError('computeCI must be a boolean')
|
|
293
330
|
self.gen = gen
|
|
294
331
|
self.nPop = nPop
|
|
295
332
|
self.maxSize = maxSize
|
|
@@ -316,6 +353,26 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
316
353
|
self.dbDataset = dbDataset
|
|
317
354
|
self.dbCacheSize = dbCacheSize
|
|
318
355
|
self.dbFlushEvery = dbFlushEvery
|
|
356
|
+
self.ciTimeout = ciTimeout
|
|
357
|
+
self.computeCI = computeCI
|
|
358
|
+
|
|
359
|
+
def _apply_ci_timeout(self):
|
|
360
|
+
"""Forward the CI budget to the Haskell runtime.
|
|
361
|
+
|
|
362
|
+
Computing profile-likelihood confidence intervals on the final Pareto
|
|
363
|
+
front re-optimizes the model at hundreds of points per parameter and
|
|
364
|
+
can take minutes for weakly-identified models. ``ciTimeout`` bounds
|
|
365
|
+
that stage: 0 skips CIs (columns left empty), -1 disables the bound,
|
|
366
|
+
and a positive value is the total budget in seconds.
|
|
367
|
+
"""
|
|
368
|
+
if not self.computeCI:
|
|
369
|
+
os.environ["EGGP_CI_TIMEOUT"] = "0"
|
|
370
|
+
elif self.ciTimeout is not None:
|
|
371
|
+
os.environ["EGGP_CI_TIMEOUT"] = str(self.ciTimeout)
|
|
372
|
+
elif _EGGP_CI_TIMEOUT_ENV is not None:
|
|
373
|
+
os.environ["EGGP_CI_TIMEOUT"] = _EGGP_CI_TIMEOUT_ENV
|
|
374
|
+
else:
|
|
375
|
+
os.environ.pop("EGGP_CI_TIMEOUT", None)
|
|
319
376
|
|
|
320
377
|
@property
|
|
321
378
|
def loss_arg(self):
|
|
@@ -405,6 +462,7 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
405
462
|
|
|
406
463
|
dname = self.get_fname("", header)
|
|
407
464
|
|
|
465
|
+
self._apply_ci_timeout()
|
|
408
466
|
csv_data = eggp_run_data(combined, [combined.shape[0]], ",".join(header), dname, self.gen, self.nPop, self.maxSize, self.nTournament, self.pc, self.pm, self.nonterminals, self.loss_arg, self.optIter, self.optRepeat, self.nParams, self.folds, self.max_time, self.simplify, self.trace, self.generational, self.dumpTo, self.loadFrom, varnames, self.useFracBayes, self.dbFile, self.dbFitFile, self.dbDataset, self.dbCacheSize, self.dbFlushEvery)
|
|
409
467
|
|
|
410
468
|
if len(csv_data) > 0:
|
|
@@ -439,6 +497,7 @@ class EGGP(BaseEstimator, RegressorMixin):
|
|
|
439
497
|
nrows = [combined.shape[0] for combined in combineds]
|
|
440
498
|
dname = self.get_fname("", header)
|
|
441
499
|
|
|
500
|
+
self._apply_ci_timeout()
|
|
442
501
|
csv_data = eggp_run_data(data, nrows, ",".join(header), dname, self.gen, self.nPop, self.maxSize, self.nTournament, self.pc, self.pm,
|
|
443
502
|
self.nonterminals, self.loss_arg, self.optIter, self.optRepeat, self.nParams, self.folds, self.max_time, self.simplify, self.trace, self.generational, self.dumpTo, self.loadFrom, varnames, self.useFracBayes, self.dbFile, self.dbFitFile, self.dbDataset, self.dbCacheSize, self.dbFlushEvery)
|
|
444
503
|
|
|
@@ -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
|
|
@@ -955,14 +1074,37 @@ also accepts `eggp +RTS -N8 -RTS ...`.
|
|
|
955
1074
|
| `pc` | float | 0.9 | Probability of performing crossover |
|
|
956
1075
|
| `pm` | float | 0.3 | Probability of performing mutation |
|
|
957
1076
|
| `nonterminals` | str | "add,sub,mul,div" | Comma-separated list of allowed functions |
|
|
958
|
-
| `loss` | str | "MSE" | Loss
|
|
1077
|
+
| `loss` | str | "MSE" | Loss: "MSE", "LOG10", "MAE", "MAPE", "Pinball", "Gaussian", "Bernoulli", or "Poisson" |
|
|
959
1078
|
| `optIter` | int | 50 | Number of iterations for parameter optimization |
|
|
960
1079
|
| `optRepeat` | int | 2 | Number of restarts for parameter optimization |
|
|
961
|
-
| `nParams` | int | -1 | Maximum number of parameters (
|
|
962
|
-
| `
|
|
963
|
-
| `
|
|
964
|
-
| `
|
|
965
|
-
| `
|
|
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
|
+
```
|
|
966
1108
|
|
|
967
1109
|
### Available Functions
|
|
968
1110
|
|
|
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
|