pyeggp 1.0.0__cp39-cp39-win_amd64.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.
pyeggp/__init__.py ADDED
@@ -0,0 +1,144 @@
1
+ """""" # start delvewheel patch
2
+ def _delvewheel_patch_1_10_0():
3
+ import ctypes
4
+ import os
5
+ import platform
6
+ import sys
7
+ libs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'pyeggp.libs'))
8
+ is_conda_cpython = platform.python_implementation() == 'CPython' and (hasattr(ctypes.pythonapi, 'Anaconda_GetVersion') or 'packaged by conda-forge' in sys.version)
9
+ if sys.version_info[:2] >= (3, 8) and not is_conda_cpython or sys.version_info[:2] >= (3, 10):
10
+ if os.path.isdir(libs_dir):
11
+ os.add_dll_directory(libs_dir)
12
+ else:
13
+ load_order_filepath = os.path.join(libs_dir, '.load-order-pyeggp-1.0.0')
14
+ if os.path.isfile(load_order_filepath):
15
+ import ctypes.wintypes
16
+ with open(os.path.join(libs_dir, '.load-order-pyeggp-1.0.0')) as file:
17
+ load_order = file.read().split()
18
+ kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
19
+ kernel32.LoadLibraryExW.restype = ctypes.wintypes.HMODULE
20
+ kernel32.LoadLibraryExW.argtypes = ctypes.wintypes.LPCWSTR, ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD
21
+ for lib in load_order:
22
+ lib_path = os.path.join(os.path.join(libs_dir, lib))
23
+ if os.path.isfile(lib_path) and not kernel32.LoadLibraryExW(lib_path, None, 8):
24
+ raise OSError('Error loading {}; {}'.format(lib, ctypes.FormatError(ctypes.get_last_error())))
25
+
26
+
27
+ _delvewheel_patch_1_10_0()
28
+ del _delvewheel_patch_1_10_0
29
+ # end delvewheel patch
30
+
31
+ import atexit
32
+ from contextlib import contextmanager
33
+ from threading import Lock
34
+ from typing import Iterator, List
35
+ from io import StringIO
36
+ import tempfile
37
+ import csv
38
+
39
+ import numpy as np
40
+ import pandas as pd
41
+ from sklearn.base import BaseEstimator, RegressorMixin
42
+ from sklearn.utils.validation import check_X_y, check_array, check_is_fitted
43
+ from sklearn.metrics import mean_squared_error, r2_score
44
+
45
+ from ._binding import (
46
+ unsafe_hs_pyeggp_version,
47
+ unsafe_hs_pyeggp_main,
48
+ unsafe_hs_pyeggp_run,
49
+ unsafe_hs_pyeggp_init,
50
+ unsafe_hs_pyeggp_exit,
51
+ )
52
+
53
+ VERSION: str = "1.3.0"
54
+
55
+
56
+ _hs_rts_init: bool = False
57
+ _hs_rts_lock: Lock = Lock()
58
+
59
+
60
+ def hs_rts_exit() -> None:
61
+ global _hs_rts_lock
62
+ with _hs_rts_lock:
63
+ unsafe_hs_pyeggp_exit()
64
+
65
+
66
+ @contextmanager
67
+ def hs_rts_init(args: List[str] = []) -> Iterator[None]:
68
+ global _hs_rts_init
69
+ global _hs_rts_lock
70
+ with _hs_rts_lock:
71
+ if not _hs_rts_init:
72
+ _hs_rts_init = True
73
+ unsafe_hs_pyeggp_init(args)
74
+ atexit.register(hs_rts_exit)
75
+ yield None
76
+
77
+
78
+ def version() -> str:
79
+ with hs_rts_init():
80
+ return unsafe_hs_pyeggp_version()
81
+
82
+
83
+ def main(args: List[str] = []) -> int:
84
+ with hs_rts_init(args):
85
+ return unsafe_hs_pyeggp_main()
86
+
87
+ def pyeggp_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, simplify: int, dumpTo: str, loadFrom: str) -> str:
88
+ with hs_rts_init():
89
+ return unsafe_hs_pyeggp_run(dataset, gen, nPop, maxSize, nTournament, pc, pm, nonterminals, loss, optIter, optRepeat, nParams, split, simplify, dumpTo, loadFrom)
90
+
91
+ class PyEGGP(BaseEstimator, RegressorMixin):
92
+ 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, split = 1, simplify = False, dumpTo = "", loadFrom = ""):
93
+ self.gen = gen
94
+ self.nPop = nPop
95
+ self.maxSize = maxSize
96
+ self.nTournament = nTournament
97
+ self.pc = pc
98
+ self.pm = pm
99
+ self.nonterminals = nonterminals
100
+ self.loss = loss
101
+ self.optIter = optIter
102
+ self.optRepeat = optRepeat
103
+ self.nParams = nParams
104
+ self.split = split
105
+ self.simplify = int(simplify)
106
+ self.dumpTo = dumpTo
107
+ self.loadFrom = loadFrom
108
+ self.is_fitted_ = False
109
+
110
+ def fit(self, X, y):
111
+ if X.ndim == 1:
112
+ X = X.reshape(-1,1)
113
+ y = y.reshape(-1, 1)
114
+ combined = np.hstack([X, y])
115
+ header = [f"x{i}" for i in range(X.shape[1])] + ["y"]
116
+ with tempfile.NamedTemporaryFile(mode='w+', newline='', delete=False, suffix='.csv') as temp_file:
117
+ writer = csv.writer(temp_file)
118
+ writer.writerow(header)
119
+ writer.writerows(combined)
120
+ dataset = temp_file.name
121
+
122
+ csv_data = pyeggp_run(dataset, self.gen, self.nPop, self.maxSize, self.nTournament, self.pc, self.pm, self.nonterminals, self.loss, self.optIter, self.optRepeat, self.nParams, self.split, self.simplify, self.dumpTo, self.loadFrom)
123
+ if len(csv_data) > 0:
124
+ csv_io = StringIO(csv_data.strip())
125
+ self.results = pd.read_csv(csv_io, header=0)
126
+ self.is_fitted_ = True
127
+ return self
128
+
129
+ def predict(self, X):
130
+ check_is_fitted(self)
131
+ return self.evaluate_best_model(self.model_, X)
132
+ def evaluate_best_model(self, x):
133
+ if x.ndim == 1:
134
+ x = x.reshape(-1,1)
135
+ t = np.array(list(map(float, self.results.iloc[-1].theta.split(";"))))
136
+ return eval(self.results.iloc[-1].Numpy)
137
+ def evaluate_model(self, ix, x):
138
+ if x.ndim == 1:
139
+ x = x.reshape(-1,1)
140
+ t = np.array(list(map(float, self.results.iloc[-1].theta.split(";"))))
141
+ return eval(self.results.iloc[i].Numpy)
142
+ def score(self, X, y):
143
+ ypred = self.evaluate_best_model(X)
144
+ return r2_score(y, ypred)
pyeggp/__main__.py ADDED
@@ -0,0 +1,11 @@
1
+ import sys
2
+ from typing import NoReturn
3
+ import pyeggp
4
+
5
+
6
+ def main() -> NoReturn:
7
+ sys.exit(pyeggp.main(sys.argv))
8
+
9
+
10
+ if __name__ == "__main__":
11
+ main()
Binary file
pyeggp/_binding.py ADDED
@@ -0,0 +1,20 @@
1
+ def __bootstrap__():
2
+ global __bootstrap__, __file__, __loader__
3
+ import sys, os, pkg_resources, importlib.util
4
+ __file__ = pkg_resources.resource_filename(__name__,'_binding.cp39-win_amd64.pyd')
5
+ del __bootstrap__
6
+ if '__loader__' in globals():
7
+ del __loader__
8
+
9
+ old_dir = os.getcwd()
10
+ try:
11
+ os.chdir(os.path.dirname(__file__))
12
+
13
+ spec = importlib.util.spec_from_file_location(
14
+ __name__, __file__)
15
+ mod = importlib.util.module_from_spec(spec)
16
+ spec.loader.exec_module(mod)
17
+ finally:
18
+
19
+ os.chdir(old_dir)
20
+ __bootstrap__()
pyeggp/_binding.pyi ADDED
@@ -0,0 +1,7 @@
1
+ from typing import List
2
+
3
+ def unsafe_hs_pyeggp_version() -> str: ...
4
+ def unsafe_hs_pyeggp_main() -> int: ...
5
+ def unsafe_hs_pyeggp_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, simplify: int, dumpTo: str, loadFrom: str) -> str: ...
6
+ def unsafe_hs_pyeggp_init(args: List[str]) -> None: ...
7
+ def unsafe_hs_pyeggp_exit() -> None: ...
pyeggp/binding.i ADDED
@@ -0,0 +1,64 @@
1
+ %module binding
2
+ %{
3
+ #include "Pyeggp_stub.h"
4
+
5
+ char * unsafe_hs_pyeggp_version() {
6
+ return hs_pyeggp_version();
7
+ }
8
+
9
+ int unsafe_hs_pyeggp_main() {
10
+ return hs_pyeggp_main();
11
+ }
12
+
13
+ char * unsafe_hs_pyeggp_run( char *dataset, int gens, int nPop, int maxSize, int nTournament, double pc, double pm, char *nonterminals, char *loss, int optIter, int optRepeat, int nParams, int split, int simplify, char *dumpTo, char *loadFrom ) {
14
+ return hs_pyeggp_run(dataset, gens, nPop, maxSize, nTournament, pc, pm, nonterminals, loss, optIter, optRepeat, nParams, split, simplify, dumpTo, loadFrom);
15
+ }
16
+
17
+ void unsafe_hs_pyeggp_init(int argc, char **argv) {
18
+ hs_init(&argc, &argv);
19
+ }
20
+
21
+ void unsafe_hs_pyeggp_exit() {
22
+ hs_exit();
23
+ }
24
+
25
+ void unsafe_py_write_stdout( char * str) {
26
+ PySys_FormatStdout("%s", str);
27
+ }
28
+
29
+ void unsafe_py_write_stderr( char * str) {
30
+ PySys_FormatStderr("%s", str);
31
+ }
32
+ %}
33
+
34
+ %typemap(in) (int argc, char **argv) {
35
+ /* Check if is a list */
36
+ if (PyList_Check($input)) {
37
+ int i;
38
+ $1 = PyList_Size($input);
39
+ $2 = (char **) malloc(($1+1)*sizeof(char *));
40
+ for (i = 0; i < $1; i++) {
41
+ PyObject *o = PyList_GetItem($input, i);
42
+ if (PyUnicode_Check(o)) {
43
+ $2[i] = (char *) PyUnicode_AsUTF8AndSize(o, 0);
44
+ } else {
45
+ PyErr_SetString(PyExc_TypeError, "list must contain strings");
46
+ SWIG_fail;
47
+ }
48
+ }
49
+ $2[i] = 0;
50
+ } else {
51
+ PyErr_SetString(PyExc_TypeError, "not a list");
52
+ SWIG_fail;
53
+ }
54
+ }
55
+
56
+ %typemap(freearg) (int argc, char **argv) {
57
+ free((char *) $2);
58
+ }
59
+
60
+ char * unsafe_hs_pyeggp_version();
61
+ int unsafe_hs_pyeggp_main();
62
+ char * unsafe_hs_pyeggp_run( char *dataset, int gens, int nPop, int maxSize, int nTournament, double p, double pm, char *nonterminals, char *loss, int optIter, int optRepeat, int nParams, int split, int simplify, char *dumpTo, char *loadFrom);
63
+ void unsafe_hs_pyeggp_init(int argc, char **argv);
64
+ void unsafe_hs_pyeggp_exit();
pyeggp/typing.py ADDED
@@ -0,0 +1,14 @@
1
+ import sys
2
+
3
+ from typing import List
4
+
5
+ if sys.version_info < (3, 8):
6
+ from typing_extensions import Protocol
7
+ else:
8
+ from typing import Protocol
9
+
10
+
11
+ class Session(Protocol):
12
+ def version(self) -> str: ...
13
+ def main(self, args: List[str] = []) -> int: ...
14
+ def pyeggp_run(self, 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, simplify: int, dumpTo: str, loadFrom: str) -> str: ...
@@ -0,0 +1,2 @@
1
+ Version: 1.10.0
2
+ Arguments: ['C:\\hostedtoolcache\\windows\\Python\\3.12.9\\x64\\Scripts\\delvewheel', 'repair', '-w', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-08n10a1r\\cp39-win_amd64\\repaired_wheel', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-08n10a1r\\cp39-win_amd64\\built_wheel\\pyeggp-1.0.0-cp39-cp39-win_amd64.whl', '--add-path', 'C:\\nlopt\\bin']