pyeggp 1.0.1__cp312-cp312-macosx_14_0_x86_64.whl → 1.0.3__cp312-cp312-macosx_14_0_x86_64.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 CHANGED
@@ -2,6 +2,7 @@ import atexit
2
2
  from contextlib import contextmanager
3
3
  from threading import Lock
4
4
  from typing import Iterator, List
5
+ import string
5
6
  from io import StringIO
6
7
  import tempfile
7
8
  import csv
@@ -58,6 +59,11 @@ def pyeggp_run(dataset: str, gen: int, nPop: int, maxSize: int, nTournament: int
58
59
  with hs_rts_init():
59
60
  return unsafe_hs_pyeggp_run(dataset, gen, nPop, maxSize, nTournament, pc, pm, nonterminals, loss, optIter, optRepeat, nParams, split, simplify, dumpTo, loadFrom)
60
61
 
62
+ def make_function(expression):
63
+ def func(x, t):
64
+ return eval(expression)
65
+ return func
66
+
61
67
  class PyEGGP(BaseEstimator, RegressorMixin):
62
68
  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 = ""):
63
69
  self.gen = gen
@@ -137,6 +143,7 @@ class PyEGGP(BaseEstimator, RegressorMixin):
137
143
  best = self.results[self.results.id==ix].iloc[view]
138
144
  t = np.array(list(map(float, best.theta.split(";"))))
139
145
  return eval(best.Numpy)
146
+
140
147
  def evaluate_model_view(self, x, ix, view):
141
148
  if x.ndim == 1:
142
149
  x = x.reshape(-1,1)
@@ -151,3 +158,19 @@ class PyEGGP(BaseEstimator, RegressorMixin):
151
158
  def score(self, X, y):
152
159
  ypred = self.evaluate_best_model(X)
153
160
  return r2_score(y, ypred)
161
+ def get_model(self, idx):
162
+ alphabet = list(string.ascii_uppercase)
163
+ row = self.results[self.results['id']==idx].iloc[0]
164
+ visual_expression = row['Numpy']
165
+ model = make_function(visual_expression)
166
+ n_params_used = len(row['theta'].split(sep=';'))
167
+
168
+ # Works for solutions with less than 26 parameters
169
+ for i in range(n_params_used):
170
+ visual_expression = visual_expression.replace(f't[{i}]', alphabet[i])
171
+
172
+ # Works for data with less than 50 dimensions
173
+ for i in range(50):
174
+ visual_expression = visual_expression.replace(f'x[:, {i}]', f'X{i}')
175
+
176
+ return model, visual_expression
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyeggp
3
- Version: 1.0.1
3
+ Version: 1.0.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
@@ -1,11 +1,5 @@
1
- pyeggp-1.0.1.dist-info/RECORD,,
2
- pyeggp-1.0.1.dist-info/WHEEL,sha256=1qccgTao8gdGngVW-9p-Z2aT1wDKP0PTzW4kY6yc-Uk,110
3
- pyeggp-1.0.1.dist-info/entry_points.txt,sha256=NJouaQ2UoCLBu7Toqer0FBvNSDYMawR_Wx9STMdopyY,48
4
- pyeggp-1.0.1.dist-info/top_level.txt,sha256=iLrWfWZHh4NruYDgVyn2ntEB-uJ8fIs95nzNVLIhKE4,7
5
- pyeggp-1.0.1.dist-info/METADATA,sha256=vbigkLKhJ_sSORsiKsZkFnU-Mjs8jOSN4Rj7gypQbtU,42220
6
- pyeggp-1.0.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
7
- pyeggp/_binding.cpython-312-darwin.so,sha256=OI0t1dFwPYbYw1vzrlc3SrvSv4wsrBPA5w4tAsYAwlw,55147792
8
- pyeggp/__init__.py,sha256=rzgGMRTJwRU0BDhfUCcE1G0OvFwu3o0qcjTfTRV7q54,5774
1
+ pyeggp/_binding.cpython-312-darwin.so,sha256=Y9UQ4i2zE1ckvaSzUF34jB2JC40-iEGpV24QMM9e4v0,55148496
2
+ pyeggp/__init__.py,sha256=pD4mYwe9-JQ7vmD5zGdC3EtGfyj7o1xmetYBHdTOB5Q,6572
9
3
  pyeggp/_binding.pyi,sha256=TsI8Gar1wpDs3c8V26i3w_u1JjznlE5dReV59bbVUh0,460
10
4
  pyeggp/binding.i,sha256=AdPEymjqByW6OhpJS08o2oTc7Go3-274JqRhbXoyDjg,1908
11
5
  pyeggp/_binding.py,sha256=cavwumzSHDiEB8FoezKN5dunYqKhUQdeKbUEk7raqPQ,580
@@ -13,3 +7,9 @@ pyeggp/typing.py,sha256=qr1vWstl5HiaUT5HGsQFHO4pRq4EhqEc4zG2mn9QHgc,517
13
7
  pyeggp/binding.py,sha256=8PjUmL-TO2k9M1uUdT8hriWKUdTUfqMgXnpcwWklayk,2625
14
8
  pyeggp/__main__.py,sha256=dAMEebAw-mVcR5PUffuRsUDPFm6Vf4qvaam9TPSUs0I,155
15
9
  pyeggp/.dylibs/libnlopt.1.0.0.dylib,sha256=KLCzh-73JgicfAN8r0WwrJmSXeKsu498GZ1uTQiUu6g,480064
10
+ pyeggp-1.0.3.dist-info/RECORD,,
11
+ pyeggp-1.0.3.dist-info/WHEEL,sha256=1qccgTao8gdGngVW-9p-Z2aT1wDKP0PTzW4kY6yc-Uk,110
12
+ pyeggp-1.0.3.dist-info/entry_points.txt,sha256=NJouaQ2UoCLBu7Toqer0FBvNSDYMawR_Wx9STMdopyY,48
13
+ pyeggp-1.0.3.dist-info/top_level.txt,sha256=iLrWfWZHh4NruYDgVyn2ntEB-uJ8fIs95nzNVLIhKE4,7
14
+ pyeggp-1.0.3.dist-info/METADATA,sha256=iubFYUSUPnA_cO2U9VqWB47FKamC7_WdTStNT67bl4o,42220
15
+ pyeggp-1.0.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
File without changes