psyke 0.8.6.dev2__py3-none-any.whl → 0.8.7__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.

psyke/__init__.py CHANGED
@@ -289,14 +289,15 @@ class Extractor(EvaluableModel, ABC):
289
289
 
290
290
  @staticmethod
291
291
  def iter(predictor, min_update: float = 0.1, n_points: int = 1, max_iterations: int = 600, min_examples: int = 250,
292
- threshold: float = 0.1, fill_gaps: bool = True, normalization: dict[str, tuple[float, float]] = None,
293
- output=None, seed: int = get_default_random_seed()) -> Extractor:
292
+ threshold: float = 0.1, fill_gaps: bool = True, ignore_dimensions=None,
293
+ normalization: dict[str, tuple[float, float]] = None, output=None,
294
+ seed: int = get_default_random_seed()) -> Extractor:
294
295
  """
295
296
  Creates a new ITER extractor.
296
297
  """
297
298
  from psyke.extraction.hypercubic.iter import ITER
298
299
  return ITER(predictor, min_update, n_points, max_iterations, min_examples, threshold, fill_gaps,
299
- normalization, output, seed)
300
+ ignore_dimensions, normalization, output, seed)
300
301
 
301
302
  @staticmethod
302
303
  def gridex(predictor, grid, min_examples: int = 250, threshold: float = 0.1, output: Target = Target.CONSTANT,
@@ -16,8 +16,9 @@ class ITER(HyperCubeExtractor):
16
16
  """
17
17
 
18
18
  def __init__(self, predictor, min_update, n_points, max_iterations, min_examples, threshold, fill_gaps,
19
- normalization, output: Target = Target.CONSTANT, seed=get_default_random_seed()):
20
- super().__init__(predictor, output, normalization)
19
+ ignore_dimensions: Iterable, normalization, output: Target = Target.CONSTANT,
20
+ seed=get_default_random_seed()):
21
+ super().__init__(predictor, output, normalization=normalization)
21
22
  if output is Target.REGRESSION:
22
23
  raise NotImplementedError
23
24
  self.predictor = predictor
@@ -30,6 +31,7 @@ class ITER(HyperCubeExtractor):
30
31
  self._output = Target.CLASSIFICATION if isinstance(predictor, ClassifierMixin) else \
31
32
  output if output is not None else Target.CONSTANT
32
33
  self.seed = seed
34
+ self.ignore_dimensions = ignore_dimensions if ignore_dimensions is not None else []
33
35
 
34
36
  def _best_cube(self, dataframe: pd.DataFrame, cube: GenericCube, cubes: Iterable[Expansion]) -> Expansion | None:
35
37
  expansions = []
@@ -74,6 +76,8 @@ class ITER(HyperCubeExtractor):
74
76
  hypercubes: Iterable[GenericCube]) -> Iterable[Expansion]:
75
77
  tmp_cubes = []
76
78
  for feature in self._surrounding.dimensions.keys():
79
+ if feature in self.ignore_dimensions:
80
+ continue
77
81
  limit = cube.check_limits(feature)
78
82
  if limit == '*':
79
83
  continue
@@ -132,6 +136,8 @@ class ITER(HyperCubeExtractor):
132
136
  hypercubes = self._generate_starting_points(dataframe)
133
137
  for hypercube in hypercubes:
134
138
  hypercube.expand_all(min_updates, self._surrounding)
139
+ for d in self.ignore_dimensions:
140
+ hypercube[d] = self._surrounding[d]
135
141
  self.n_points = self.n_points - 1
136
142
  if not HyperCube.check_overlap(hypercubes, hypercubes):
137
143
  break
psyke/schema/__init__.py CHANGED
@@ -9,9 +9,15 @@ _EMPTY_INTERSECTION_EXCEPTION: Callable = lambda x, y: \
9
9
  _NOT_IMPLEMENTED_INTERSECTION: Callable = lambda x, y: \
10
10
  Exception("Not implemented intersection between: " + str(x) + ' and ' + str(y))
11
11
 
12
- _INTERSECTION_WITH_WRONG_TYPE: Callable = lambda x, y: \
12
+ _OPERATION_WITH_WRONG_TYPE: Callable = lambda x, y: \
13
13
  Exception("Calling method with wrong type argument: " + str(x) + ' and ' + str(y))
14
14
 
15
+ _EMPTY_UNION_EXCEPTION: Callable = lambda x, y: \
16
+ Exception(f"Empty union between two Value: {str(x)} and {str(y)}")
17
+
18
+ _NOT_IMPLEMENTED_UNION: Callable = lambda x, y: \
19
+ Exception("Not implemented union between: " + str(x) + ' and ' + str(y))
20
+
15
21
  PRECISION = get_int_precision()
16
22
  STRING_PRECISION = str(PRECISION)
17
23
 
@@ -109,7 +115,7 @@ class Value:
109
115
  else:
110
116
  raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
111
117
  else:
112
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
118
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
113
119
 
114
120
  def intersection_with_outside(first_value: Outside, second_value: Value) -> Value:
115
121
  if isinstance(first_value, Outside):
@@ -154,9 +160,9 @@ class Value:
154
160
  elif isinstance(second_value, Constant):
155
161
  return intersection_with_constant(second_value, first_value)
156
162
  else:
157
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
163
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
158
164
  else:
159
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
165
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
160
166
 
161
167
  def intersection_with_between(first_value: Between, second_value: Value) -> Value:
162
168
  if isinstance(first_value, Between):
@@ -194,9 +200,9 @@ class Value:
194
200
  elif isinstance(second_value, Outside):
195
201
  return intersection_with_outside(second_value, first_value)
196
202
  else:
197
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
203
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
198
204
  else:
199
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
205
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
200
206
 
201
207
  def intersection_with_less_than(first_value: LessThan, second_value: Value) -> Value:
202
208
  if isinstance(first_value, LessThan):
@@ -214,9 +220,9 @@ class Value:
214
220
  elif isinstance(second_value, Between):
215
221
  return intersection_with_between(second_value, first_value)
216
222
  else:
217
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
223
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
218
224
  else:
219
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
225
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
220
226
 
221
227
  def intersection_with_greater_than(first_value: GreaterThan, second_value: Value) -> Value:
222
228
  if isinstance(first_value, GreaterThan):
@@ -231,9 +237,9 @@ class Value:
231
237
  elif isinstance(second_value, LessThan):
232
238
  return intersection_with_less_than(second_value, first_value)
233
239
  else:
234
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
240
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
235
241
  else:
236
- raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
242
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
237
243
 
238
244
  if other is None:
239
245
  return self
@@ -248,7 +254,151 @@ class Value:
248
254
  elif isinstance(self, GreaterThan):
249
255
  return intersection_with_greater_than(self, other)
250
256
  else:
251
- raise _INTERSECTION_WITH_WRONG_TYPE(self, other)
257
+ raise _OPERATION_WITH_WRONG_TYPE(self, other)
258
+
259
+ def __add__(self, other) -> Value:
260
+
261
+ def union_with_constant(first_value: Constant, second_value: Value) -> Value:
262
+ if isinstance(first_value, Constant):
263
+ if first_value in second_value:
264
+ return second_value
265
+ else:
266
+ raise _NOT_IMPLEMENTED_UNION(first_value, second_value)
267
+ else:
268
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
269
+
270
+ def union_with_outside(first_value: Outside, second_value: Value) -> Value:
271
+ if isinstance(first_value, Outside):
272
+ if isinstance(second_value, LessThan):
273
+ if second_value.value > first_value.upper:
274
+ return Between(-math.inf, math.inf)
275
+ elif second_value.value > first_value.lower:
276
+ return Outside(second_value.value, first_value.upper)
277
+ else:
278
+ return first_value
279
+ elif isinstance(second_value, GreaterThan):
280
+ if second_value.value < first_value.lower:
281
+ return Between(-math.inf, math.inf)
282
+ elif second_value.value < first_value.upper:
283
+ return Outside(first_value.lower, second_value.value)
284
+ else:
285
+ return first_value
286
+ elif isinstance(second_value, Between):
287
+ if second_value.upper <= first_value.lower or second_value.lower >= first_value.upper:
288
+ return first_value
289
+ elif second_value.lower <= first_value.lower <= second_value.upper <= first_value.upper:
290
+ return Outside(second_value.upper, first_value.lower)
291
+ elif first_value.lower <= second_value.lower <= first_value.upper <= second_value.upper:
292
+ return Outside(first_value.upper, second_value.lower)
293
+ elif second_value.lower <= first_value.lower <= first_value.upper <= second_value.upper:
294
+ return Between(-math.inf, math.inf)
295
+ else:
296
+ raise _NOT_IMPLEMENTED_UNION(first_value, second_value)
297
+ elif isinstance(second_value, Outside):
298
+ if second_value.lower <= first_value.lower <= first_value.upper <= second_value.upper:
299
+ return first_value
300
+ elif first_value.lower <= second_value.lower <= second_value.upper <= first_value.upper:
301
+ return second_value
302
+ elif second_value.lower <= first_value.lower <= second_value.upper <= first_value.upper:
303
+ return Outside(first_value.lower, second_value.upper)
304
+ elif first_value.lower <= second_value.lower <= first_value.upper <= second_value.upper:
305
+ return Outside(second_value.lower, first_value.upper)
306
+ else:
307
+ return Between(-math.inf, math.inf)
308
+ elif isinstance(second_value, Constant):
309
+ return union_with_constant(second_value, first_value)
310
+ else:
311
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
312
+ else:
313
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
314
+
315
+ def union_with_between(first_value: Between, second_value: Value) -> Value:
316
+ if isinstance(first_value, Between):
317
+ if isinstance(second_value, LessThan):
318
+ if second_value.value <= first_value.lower:
319
+ raise _NOT_IMPLEMENTED_UNION(first_value, second_value)
320
+ elif first_value.lower <= second_value.value <= first_value.upper:
321
+ return LessThan(first_value.upper)
322
+ else:
323
+ return second_value
324
+ elif isinstance(second_value, GreaterThan):
325
+ if second_value.value <= first_value.lower:
326
+ return second_value
327
+ elif first_value.lower <= second_value.value <= first_value.upper:
328
+ return GreaterThan(first_value.lower)
329
+ else:
330
+ raise _NOT_IMPLEMENTED_UNION(first_value, second_value)
331
+ elif isinstance(second_value, Between):
332
+ if second_value in first_value:
333
+ return first_value
334
+ elif first_value in second_value:
335
+ return second_value
336
+ elif first_value.lower <= second_value.lower <= first_value.upper:
337
+ return Between(first_value.lower, second_value.upper)
338
+ elif second_value.lower <= first_value.lower <= second_value.upper <= first_value.upper:
339
+ return Between(second_value.lower, first_value.upper)
340
+ else:
341
+ raise _NOT_IMPLEMENTED_UNION(first_value, second_value)
342
+ elif isinstance(second_value, Constant):
343
+ return union_with_constant(second_value, first_value)
344
+ elif isinstance(second_value, Outside):
345
+ return union_with_outside(second_value, first_value)
346
+ else:
347
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
348
+ else:
349
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
350
+
351
+ def union_with_less_than(first_value: LessThan, second_value: Value) -> Value:
352
+ if isinstance(first_value, LessThan):
353
+ if isinstance(second_value, LessThan):
354
+ return second_value if first_value in second_value else first_value
355
+ elif isinstance(second_value, GreaterThan):
356
+ if second_value.value <= first_value.value:
357
+ return Between(-math.inf, math.inf)
358
+ else:
359
+ return Outside(first_value.value, second_value.value)
360
+ elif isinstance(second_value, Constant):
361
+ return union_with_constant(second_value, first_value)
362
+ elif isinstance(second_value, Outside):
363
+ return union_with_outside(second_value, first_value)
364
+ elif isinstance(second_value, Between):
365
+ return union_with_between(second_value, first_value)
366
+ else:
367
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
368
+ else:
369
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
370
+
371
+ def union_with_greater_than(first_value: GreaterThan, second_value: Value) -> Value:
372
+ if isinstance(first_value, GreaterThan):
373
+ if isinstance(second_value, GreaterThan):
374
+ return second_value if first_value in second_value else first_value
375
+ elif isinstance(second_value, Constant):
376
+ return union_with_constant(second_value, first_value)
377
+ elif isinstance(second_value, Outside):
378
+ return union_with_outside(second_value, first_value)
379
+ elif isinstance(second_value, Between):
380
+ return union_with_between(second_value, first_value)
381
+ elif isinstance(second_value, LessThan):
382
+ return union_with_less_than(second_value, first_value)
383
+ else:
384
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
385
+ else:
386
+ raise _OPERATION_WITH_WRONG_TYPE(first_value, second_value)
387
+
388
+ if other is None:
389
+ return self
390
+ elif isinstance(self, Constant):
391
+ return union_with_constant(self, other)
392
+ elif isinstance(self, Outside):
393
+ return union_with_outside(self, other)
394
+ elif isinstance(self, Between):
395
+ return union_with_between(self, other)
396
+ elif isinstance(self, LessThan):
397
+ return union_with_less_than(self, other)
398
+ elif isinstance(self, GreaterThan):
399
+ return union_with_greater_than(self, other)
400
+ else:
401
+ raise _OPERATION_WITH_WRONG_TYPE(self, other)
252
402
 
253
403
  def print(self) -> str:
254
404
  pass
@@ -98,14 +98,15 @@ class PEDRO(SKEOptimizer, IterativeOptimizer):
98
98
  return False
99
99
 
100
100
  def search(self):
101
+ max_partitions = 200
101
102
  base_partitions = FixedStrategy(2).partition_number(self.dataframe.columns[:-1]) * 3
102
- if base_partitions <= 50:
103
+ if base_partitions <= max_partitions:
103
104
  strategies = [FixedStrategy(2)]
104
- if FixedStrategy(3).partition_number(self.dataframe.columns[:-1]) <= base_partitions:
105
+ if FixedStrategy(3).partition_number(self.dataframe.columns[:-1]) <= max_partitions:
105
106
  strategies.append(FixedStrategy(3))
106
107
  else:
107
108
  strategies = []
108
- base_partitions = 50
109
+ base_partitions = max_partitions
109
110
 
110
111
  for n in [2, 3, 5, 10]:
111
112
  for th in [0.99, 0.75, 0.67, 0.5, 0.3]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: psyke
3
- Version: 0.8.6.dev2
3
+ Version: 0.8.7
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
@@ -1,4 +1,4 @@
1
- psyke/__init__.py,sha256=MSMiwvVth4kqmGvQt6HiYNR3J4EdINe8PBmK8-DQVSo,18545
1
+ psyke/__init__.py,sha256=_Gm4C_o9AifRNXjsPVe0znQy-kTfGxDih7O1YeO3KlY,18601
2
2
  psyke/hypercubepredictor.py,sha256=MlSRLky6J1I07qKcH98c9WvEjFHGyBiz_LU9W_oDnqs,4572
3
3
  psyke/clustering/__init__.py,sha256=36MokTVwwWR_-o0mesvXHaYEYVTK2pn2m0ZY4G3Y3qU,581
4
4
  psyke/clustering/utils.py,sha256=S0YwCKyHVYp9qUAQVzCMrTwcQFPJ5TD14Jwn10DE-Z4,1616
@@ -17,24 +17,24 @@ psyke/extraction/hypercubic/divine/__init__.py,sha256=ClO8CITKKXoo7nhlBJagR1yAac
17
17
  psyke/extraction/hypercubic/gridex/__init__.py,sha256=o7tNU3JH8AqA2PRj839-rPb6zhwAdpaCVGC__0DH-b0,5543
18
18
  psyke/extraction/hypercubic/gridrex/__init__.py,sha256=h9usK5tFqd6ngBmRydsgkfQ1jlcQKj2uG72Tr1puFHk,595
19
19
  psyke/extraction/hypercubic/hex/__init__.py,sha256=553AZjOT9thfqDGtVDI6WtgYNex2Y6dg53cEyuf7Q80,4805
20
- psyke/extraction/hypercubic/iter/__init__.py,sha256=QAnxS-8Bn2gTMWyGMCoiC3skdVMjZed-12wO1sWQgdw,9722
20
+ psyke/extraction/hypercubic/iter/__init__.py,sha256=9wE9pdEVNM9a9VfkNVKZjemFESyNJRoJPUF0AbitTsk,10054
21
21
  psyke/extraction/real/__init__.py,sha256=fFqiwgWTpu5Jx9lz5CdSfs1QyqWYFLQDG7tc5M6Q7UM,6065
22
22
  psyke/extraction/real/utils.py,sha256=eHGU-Y0inn_8jrk9lMcuRUKXpsTkI-s_myXSWz4bALQ,2190
23
23
  psyke/extraction/trepan/__init__.py,sha256=KpZpk0btCWV4bS-DOmpgpYscSQ5FEMyP54ekm7ZedME,6583
24
24
  psyke/extraction/trepan/utils.py,sha256=iSUJ1ooNQT_VO1KfBZuIUeUsyUbGdQf_pSEE87vMeQg,2320
25
- psyke/schema/__init__.py,sha256=66Jm4hk9s2ZBdXUF7tg43_zG0X6XicMYOPsBkXyY0wE,17444
25
+ psyke/schema/__init__.py,sha256=GjT4Wyw008pS8WuuGz5-YC4iQphvk83B8dtkzL-3a_g,25929
26
26
  psyke/tuning/__init__.py,sha256=yd_ForFmHeYbtRXltY1fOa-mPJvpE6ijzg50M_8Sdxw,3649
27
27
  psyke/tuning/crash/__init__.py,sha256=zIHEF75EFy_mRIieqzP04qKLG3GLsSc_mYZHpPfkzxU,2623
28
28
  psyke/tuning/orchid/__init__.py,sha256=s64iABbteik27CrRPHSVHNZX25JKlDu7YYjhseOizxw,3618
29
- psyke/tuning/pedro/__init__.py,sha256=TXDL4iN3XOM3x5KVxjIr_btyY8m5QWxXKSrFYWcwxQY,6596
29
+ psyke/tuning/pedro/__init__.py,sha256=Q7Te3FWeLvJ7g2dkDraorUs6eRtxFgE9HEc3MshcATs,6648
30
30
  psyke/utils/__init__.py,sha256=F-fgBT9CkthIwW8dDCuF5OoQDVMBNvIsZyvNqkgZNUA,1767
31
31
  psyke/utils/dataframe.py,sha256=cPbCl_paACCtO0twCiHKUcEKIYiT89WDwQ-f5I9oKrg,6841
32
32
  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.8.6.dev2.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
- psyke-0.8.6.dev2.dist-info/METADATA,sha256=Ox4Wzc68dha1K1ETGKaqjWGd0J7yFjenqKceV2nJ-FE,8107
38
- psyke-0.8.6.dev2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
- psyke-0.8.6.dev2.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
- psyke-0.8.6.dev2.dist-info/RECORD,,
36
+ psyke-0.8.7.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
+ psyke-0.8.7.dist-info/METADATA,sha256=DefC2-n4FXf0UlT6xFToHNOUuCbPGQZwrKrkjnYwX8k,8102
38
+ psyke-0.8.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
+ psyke-0.8.7.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
+ psyke-0.8.7.dist-info/RECORD,,