psyke 0.7.3.dev9__py3-none-any.whl → 0.7.5.dev1__py3-none-any.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.

Potentially problematic release.


This version of psyke might be problematic. Click here for more details.

@@ -43,7 +43,7 @@ class GridEx(HyperCubeExtractor):
43
43
  ranges[feature] = [(a + size * i, a + size * (i + 1)) for i in range(n_bins)]
44
44
  return ranges
45
45
 
46
- def _cubes_to_split(self, cube, iteration, dataframe, fake, keep_empty=False):
46
+ def _cubes_to_split(self, cube, surrounding, iteration, dataframe, fake, keep_empty=False):
47
47
  to_split = []
48
48
  for (pn, p) in enumerate(list(product(*self._create_ranges(cube, iteration).values()))):
49
49
  cube = self._default_cube()
@@ -51,10 +51,10 @@ class GridEx(HyperCubeExtractor):
51
51
  cube.update_dimension(f, p[i])
52
52
  n = cube.count(dataframe)
53
53
  if n > 0 or keep_empty:
54
- fake = pd.concat([fake, cube.create_samples(self.min_examples - n, self._generator)])
54
+ fake = pd.concat([fake, cube.create_samples(self.min_examples - n, surrounding, self._generator)])
55
55
  cube.update(fake, self.predictor)
56
56
  to_split.append(cube)
57
- return to_split
57
+ return to_split, fake
58
58
 
59
59
  def _iterate(self, surrounding: HyperCube, dataframe: pd.DataFrame):
60
60
  fake = dataframe.copy()
@@ -69,7 +69,8 @@ class GridEx(HyperCubeExtractor):
69
69
  if cube.diversity < self.threshold:
70
70
  self._hypercubes += [cube]
71
71
  continue
72
- next_iteration += [c for c in self._merge(self._cubes_to_split(cube, iteration, dataframe, fake), fake)]
72
+ to_split, fake = self._cubes_to_split(cube, surrounding, iteration, dataframe, fake)
73
+ next_iteration += [c for c in self._merge(to_split, fake)]
73
74
  prev = next_iteration.copy()
74
75
  self._hypercubes += [cube for cube in next_iteration]
75
76
 
@@ -1,3 +1,4 @@
1
+ import numpy as np
1
2
  import pandas as pd
2
3
  from sklearn.linear_model import LinearRegression
3
4
 
@@ -41,10 +42,13 @@ class HEx(GridEx):
41
42
  for cube in prev:
42
43
  # subcubes =
43
44
  # [c for c in self._merge(self._cubes_to_split(cube, iteration, dataframe, fake, True), fake)]
44
- subcubes = [c for c in self._cubes_to_split(cube, iteration, dataframe, fake, True)]
45
+ subcubes, fake = self._cubes_to_split(cube, surrounding, iteration, dataframe, fake, True)
45
46
  cleaned = [c for c in subcubes if c.count(dataframe) > 0 and self._gain(cube, c)]
46
47
  if len(subcubes) > len(cleaned):
48
+ if len(cleaned) > 0:
49
+ idx = np.any([c.filter_indices(fake.iloc[:, :-1]) for c in cleaned], axis=0)
50
+ cube.update(fake[~idx], self.predictor)
47
51
  self._hypercubes = [cube] + self._hypercubes
48
- next_iteration += cleaned
52
+ next_iteration += self._merge(cleaned, fake)
49
53
  prev = next_iteration.copy()
50
54
  self._hypercubes = [cube for cube in next_iteration] + self._hypercubes
@@ -158,8 +158,9 @@ class HyperCube:
158
158
  return '*'
159
159
  raise Exception('Too many limits for this feature')
160
160
 
161
- def create_samples(self, n: int = 1, generator: Random = Random(get_default_random_seed())) -> pd.DataFrame:
162
- return pd.DataFrame([self._create_tuple(generator) for _ in range(n)])
161
+ def create_samples(self, n: int = 1, surrounding: GenericCube = None,
162
+ generator: Random = Random(get_default_random_seed())) -> pd.DataFrame:
163
+ return pd.DataFrame([self._create_tuple(generator, surrounding) for _ in range(n)])
163
164
 
164
165
  @staticmethod
165
166
  def check_overlap(to_check: Iterable[HyperCube], hypercubes: Iterable[HyperCube]) -> bool:
@@ -208,9 +209,10 @@ class HyperCube:
208
209
  return RegressionCube(dimensions)
209
210
  return HyperCube(dimensions)
210
211
 
211
- def _create_tuple(self, generator: Random) -> dict:
212
- return {k: generator.uniform(self.get_first(k, False), self.get_second(k, False))
213
- for k in self._dimensions.keys()}
212
+ def _create_tuple(self, generator: Random, surrounding: GenericCube) -> dict:
213
+ minmax = {k: (self[k][0] if np.isfinite(self[k][0]) else surrounding[k][0],
214
+ self[k][1] if np.isfinite(self[k][1]) else surrounding[k][1]) for k in self._dimensions.keys()}
215
+ return {k: generator.uniform(minmax[k][0], minmax[k][1]) for k in self._dimensions.keys()}
214
216
 
215
217
  @staticmethod
216
218
  def cube_from_point(point: dict[str, float], output=None) -> GenericCube:
@@ -243,11 +245,11 @@ class HyperCube:
243
245
  for update in updates:
244
246
  self._expand_one(update, surrounding, ratio)
245
247
 
246
- def get_first(self, feature: str, inf: bool = True) -> float:
247
- return self[feature][0] if inf or np.isfinite(self[feature][0]) else 0.0
248
+ def get_first(self, feature: str) -> float:
249
+ return self[feature][0]
248
250
 
249
- def get_second(self, feature: str, inf: bool = True) -> float:
250
- return self[feature][1] if inf or np.isfinite(self[feature][1]) else 0.0
251
+ def get_second(self, feature: str) -> float:
252
+ return self[feature][1]
251
253
 
252
254
  def has_volume(self) -> bool:
253
255
  return all([dimension[1] - dimension[0] > HyperCube.EPSILON for dimension in self._dimensions.values()])
@@ -38,7 +38,8 @@ class ITER(HyperCubeExtractor):
38
38
  expansions = []
39
39
  for limit in cubes:
40
40
  count = limit.cube.count(dataframe)
41
- dataframe = pd.concat([dataframe, limit.cube.create_samples(self.min_examples - count, self.__generator)])
41
+ dataframe = pd.concat([dataframe, limit.cube.create_samples(self.min_examples - count,
42
+ generator=self.__generator)])
42
43
  limit.cube.update(dataframe, self.predictor)
43
44
  expansions.append(Expansion(
44
45
  limit.cube, limit.feature, limit.direction,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: psyke
3
- Version: 0.7.3.dev9
3
+ Version: 0.7.5.dev1
4
4
  Summary: Python-based implementation of PSyKE, i.e. a Platform for Symbolic Knowledge Extraction
5
5
  Home-page: https://github.com/psykei/psyke-python
6
6
  Author: Matteo Magnini
@@ -8,16 +8,16 @@ psyke/extraction/__init__.py,sha256=Zmq83HqmmDVyw-4KsaEVm52h8T2_Hy-lYSHF75hDIL8,
8
8
  psyke/extraction/cart/__init__.py,sha256=IilEP4DxSAK9_x5ehPTvopuwlQqBMpGMiNRo-f90rqQ,4179
9
9
  psyke/extraction/cart/predictor.py,sha256=2-2mv5fI0lTwwfTaEonxKh0ZUdhxuIEE6OP_rJxgmqc,3019
10
10
  psyke/extraction/hypercubic/__init__.py,sha256=0XUHTtUCClMBdyA0cLIq9D5gHfqqFiSVt3DsHDQy94M,6786
11
- psyke/extraction/hypercubic/hypercube.py,sha256=V-6dazg3ULOvcnco45gZRFSrCft8jOQjX_-UKL5BEl4,19727
11
+ psyke/extraction/hypercubic/hypercube.py,sha256=QqQdaelyrvv79r_rNErkeTCVPHVPahUe9KCrhAs_3HI,19849
12
12
  psyke/extraction/hypercubic/strategy.py,sha256=X-roIsfcpJyMdo2px5JtbhP7-XE-zUNkaEK7XGXoWA8,1636
13
13
  psyke/extraction/hypercubic/utils.py,sha256=D2FN5CCm_T3h23DmLFoTnIcFo7LvIq__ktl4hjUqkcA,1525
14
14
  psyke/extraction/hypercubic/cosmik/__init__.py,sha256=OIfAZFFZVXKdvQvOut6NfUbey3TClR-W76DrlQH8LrM,1937
15
15
  psyke/extraction/hypercubic/creepy/__init__.py,sha256=QcYGm3OHzUxutuuQ159oUNwr-4Cmh6RIC-9xQzoOOyA,1893
16
16
  psyke/extraction/hypercubic/divine/__init__.py,sha256=qWoOeTNwNRD8VHZQLqVuv8Jfr4X2sGaQOylm8fw0m9g,3619
17
- psyke/extraction/hypercubic/gridex/__init__.py,sha256=E5ElK-_A8UMCIGRWd21UKphMfVlexbCwbzI86yRmgPQ,5601
17
+ psyke/extraction/hypercubic/gridex/__init__.py,sha256=QWgfIDojpb38DC7Z49KyyPCHqb2-3GIkBWa2ApjMNl4,5688
18
18
  psyke/extraction/hypercubic/gridrex/__init__.py,sha256=h9usK5tFqd6ngBmRydsgkfQ1jlcQKj2uG72Tr1puFHk,595
19
- psyke/extraction/hypercubic/hex/__init__.py,sha256=RR-xJwyHqR4NXBEC0Jbdz8rqVw_ND-jb_53jYtn2xBU,2391
20
- psyke/extraction/hypercubic/iter/__init__.py,sha256=r3M4xLxtYdV94UChMn6t0gyBkjKsfQPfr0UoPgGV8CY,10059
19
+ psyke/extraction/hypercubic/hex/__init__.py,sha256=uLO8geJ1BjWPkhhjXkhDafx8rlNGSWI5Z-jEL3SN41o,2641
20
+ psyke/extraction/hypercubic/iter/__init__.py,sha256=E_Z8KLTei71n_Hd4p7eXvR8tjRoLdVBWLh-ph7x0JSs,10141
21
21
  psyke/extraction/real/__init__.py,sha256=DN9z51QdldUh1g9rzh7H8bgvZJZ-qOKpTQvHKR8NkAI,6417
22
22
  psyke/extraction/real/utils.py,sha256=eHGU-Y0inn_8jrk9lMcuRUKXpsTkI-s_myXSWz4bALQ,2190
23
23
  psyke/extraction/trepan/__init__.py,sha256=1aiV7nZa4qGJhF8vASCeakzyV_vr-ojeO7ONH7oAj0Y,6640
@@ -33,8 +33,8 @@ psyke/utils/logic.py,sha256=7bbW6qcKof5PlqoQ0n5Kt3Obcot-KqGAvpE8rMXvEPE,12419
33
33
  psyke/utils/metrics.py,sha256=Oo5BOonOSfo0qYsXWT5dmypZ7jiStByFC2MKEU0uMHg,2250
34
34
  psyke/utils/plot.py,sha256=dE8JJ6tQ0Ezosid-r2jqAisREjFe5LqExRzsVi5Ns-c,7785
35
35
  psyke/utils/sorted.py,sha256=C3CPW2JisND30BRk5c1sAAHs3Lb_wsRB2qZrYFuRnfM,678
36
- psyke-0.7.3.dev9.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
- psyke-0.7.3.dev9.dist-info/METADATA,sha256=-yYy2yWqlmf0sXU1CRm4IjF7ulluktEGsp9NH2ejigE,8107
38
- psyke-0.7.3.dev9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
39
- psyke-0.7.3.dev9.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
- psyke-0.7.3.dev9.dist-info/RECORD,,
36
+ psyke-0.7.5.dev1.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
+ psyke-0.7.5.dev1.dist-info/METADATA,sha256=_yWIdr9goCEHEmXcULb5LiPT0eFY9-TqQ6EEQe9VavQ,8107
38
+ psyke-0.7.5.dev1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
39
+ psyke-0.7.5.dev1.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
+ psyke-0.7.5.dev1.dist-info/RECORD,,