psyke 0.8.2.dev9__py3-none-any.whl → 0.8.2.dev15__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.

@@ -44,38 +44,68 @@ class HyperCubeExtractor(HyperCubePredictor, PedagogicalExtractor, ABC):
44
44
  self._surrounding.update(dataframe, self.predictor)
45
45
  return theory
46
46
 
47
- def predict_counter(self, data: dict[str, float]):
47
+ def pairwise_fairness(self, data: dict[str, float], neighbor: dict[str, float]):
48
+ cube1 = self._find_cube(data.copy())
49
+ cube2 = self._find_cube(neighbor.copy())
50
+ different_prediction_reasons = []
51
+
52
+ if cube1.output == cube2.output:
53
+ print("Prediction", cube1.output, "is FAIR")
54
+ else:
55
+ print("Prediction", cube1.output, "may be UNFAIR")
56
+ print("It could be", cube2.output, "if:")
57
+ for d in data:
58
+ a, b = cube2.dimensions[d]
59
+ if data[d] < a:
60
+ print(' ', d, 'increases above', round(a, 1))
61
+ different_prediction_reasons.append(d)
62
+ elif data[d] > b:
63
+ print(' ', d, 'decreases below', round(b, 1))
64
+ different_prediction_reasons.append(d)
65
+ return different_prediction_reasons
66
+
67
+ def predict_counter(self, data: dict[str, float], verbose=True):
68
+ output = ""
69
+ prediction = None
48
70
  cube = self._find_cube(data.copy())
49
71
  if cube is None:
50
- print("The extracted knowledge is not exhaustive; impossible to predict this instance")
72
+ output += "The extracted knowledge is not exhaustive; impossible to predict this instance"
51
73
  else:
52
- print("The output is", self._predict_from_cubes(data))
74
+ prediction = self._predict_from_cubes(data)
75
+ output += f"The output is {prediction}\n"
53
76
 
54
77
  point = Point(list(data.keys()), list(data.values()))
55
78
  cubes = self._hypercubes if cube is None else [c for c in self._hypercubes if cube.output != c.output]
56
79
  cubes = sorted([(cube.surface_distance(point), cube.volume(), cube) for cube in cubes])
57
80
  outputs = []
81
+ different_prediction_reasons = []
58
82
  for _, _, c in cubes:
59
83
  if c.output not in outputs:
60
84
  outputs.append(c.output)
61
- print("The output may be", c.output, 'if')
85
+ output += f"The output may be {c.output} if"
62
86
 
63
87
  for d in point.dimensions.keys():
64
88
  lower, upper = c[d]
65
89
  p = point[d]
66
90
  if p < lower:
67
- print(' ', d, '=', round(lower, 1))
91
+ output += f"\n {d} increases above {round(lower, 1)}"
92
+ different_prediction_reasons.append((d, '>=', lower))
68
93
  elif p > upper:
69
- print(' ', d, '=', round(upper, 1))
94
+ output += f"\n {d} decreses below {round(upper, 1)}"
95
+ different_prediction_reasons.append((d, '<=', upper))
96
+ if verbose:
97
+ print(output)
98
+ return prediction, different_prediction_reasons
70
99
 
71
- def __get_local_conditions(self, cube: GenericCube) -> dict[list[Value]]:
100
+ def __get_local_conditions(self, data: dict[str, float], cube: GenericCube) -> dict[list[Value]]:
72
101
  conditions = {d: [] for d in cube.dimensions}
73
102
  for d in cube.finite_dimensions:
74
103
  conditions[d].append(Between(*cube.dimensions[d]))
75
104
  subcubes = cube.subcubes(self._hypercubes)
76
105
  for c in [c for c in subcubes if sum(c in sc and c != sc for sc in subcubes) == 0]:
77
- for d in c.finite_dimensions:
78
- conditions[d].append(Outside(*c.dimensions[d]))
106
+ for d in [d for d in c.finite_dimensions if d in data]:
107
+ if c.dimensions[d][0] > data[d] or c.dimensions[d][1] < data[d]:
108
+ conditions[d].append(Outside(*c.dimensions[d]))
79
109
  return conditions
80
110
 
81
111
  def predict_why(self, data: dict[str, float]):
@@ -85,7 +115,7 @@ class HyperCubeExtractor(HyperCubePredictor, PedagogicalExtractor, ABC):
85
115
  else:
86
116
  output = self._predict_from_cubes(data)
87
117
  print(f"The output is {output} because")
88
- conditions = self.__get_local_conditions(cube)
118
+ conditions = self.__get_local_conditions(data, cube)
89
119
  for d in data.keys():
90
120
  simplified = HyperCubeExtractor.__simplify(conditions[d])
91
121
  for i, condition in enumerate(simplified):
@@ -38,7 +38,7 @@ class GridEx(HyperCubeExtractor):
38
38
  n_bins = self.grid.get(feature, iteration)
39
39
  if n_bins == 1:
40
40
  ranges[feature] = [(a, b)]
41
- self._dimensions_to_ignore.append(feature)
41
+ self._dimensions_to_ignore.add(feature)
42
42
  else:
43
43
  size = (b - a) / n_bins
44
44
  ranges[feature] = [(a + size * i, a + size * (i + 1)) for i in range(n_bins)]
@@ -14,7 +14,7 @@ class HyperCubePredictor(EvaluableModel):
14
14
  def __init__(self, output=Target.CONSTANT, discretization=None, normalization=None):
15
15
  super().__init__(discretization, normalization)
16
16
  self._hypercubes = []
17
- self._dimensions_to_ignore = []
17
+ self._dimensions_to_ignore = set()
18
18
  self._output = output
19
19
  self._surrounding = None
20
20
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: psyke
3
- Version: 0.8.2.dev9
3
+ Version: 0.8.2.dev15
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,5 +1,5 @@
1
1
  psyke/__init__.py,sha256=weEnLws23jzCu_wqZVfq-jVlikiGle14coSMrjUnt7w,18155
2
- psyke/hypercubepredictor.py,sha256=YuTvleaotC3wWK33qhwdYNmA1MTz3kUXSnqnTI_jj8s,4588
2
+ psyke/hypercubepredictor.py,sha256=sc0_bel93LOCfTXsoQ9UJGRneQGBtldOl2JurCl9rr0,4591
3
3
  psyke/clustering/__init__.py,sha256=36MokTVwwWR_-o0mesvXHaYEYVTK2pn2m0ZY4G3Y3qU,581
4
4
  psyke/clustering/utils.py,sha256=S0YwCKyHVYp9qUAQVzCMrTwcQFPJ5TD14Jwn10DE-Z4,1616
5
5
  psyke/clustering/cream/__init__.py,sha256=W6k7vdjuUdA_azYA4vb5JtpWrofhDJ0DbM2jsnRKzfw,2994
@@ -7,14 +7,14 @@ psyke/clustering/exact/__init__.py,sha256=GpMGOcN2bGn3wfaUKOdis3vnLEtAx9j886qsk-
7
7
  psyke/extraction/__init__.py,sha256=ziZ8T9eAOZjKipepE5_j1zfZgyFPONjW8MGERSk83nI,743
8
8
  psyke/extraction/cart/__init__.py,sha256=s8tr7jPhONgF0pfetHieFax2MD8cy6ddOS7dRWzZLjc,3579
9
9
  psyke/extraction/cart/predictor.py,sha256=2-2mv5fI0lTwwfTaEonxKh0ZUdhxuIEE6OP_rJxgmqc,3019
10
- psyke/extraction/hypercubic/__init__.py,sha256=4RZkE5uLpLGUSY6G7cmwwEx1PC1cAaGZhM_HSwzlmOw,10368
10
+ psyke/extraction/hypercubic/__init__.py,sha256=2Y9C-bjwqFPlwRDv02sgZyyZv9-DGb8Sk4BHw9f_cVI,11842
11
11
  psyke/extraction/hypercubic/hypercube.py,sha256=vYJoIEAsiIY5koh84hnSdd72PPc-7-RP_1Eo5vvjxk4,22754
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=XQUvOtMFpR0vMHYtwIVl3G626HMqN8Clt6BqNm4nvFs,1880
15
15
  psyke/extraction/hypercubic/creepy/__init__.py,sha256=ssNMKgkY9MRbcDgvxL9kt13-k_pMwi_SVR1dt8KWy2o,1681
16
16
  psyke/extraction/hypercubic/divine/__init__.py,sha256=RLvRZkCT1lKdh1mrxEuVWEaKa43zNtWkw9as7nEGFHE,3562
17
- psyke/extraction/hypercubic/gridex/__init__.py,sha256=cVW0o7wkq4d78w_Dn7HAKwon8snNFnTqWcRh-37UYNg,5679
17
+ psyke/extraction/hypercubic/gridex/__init__.py,sha256=YPNH1dLUatfdgzxUKocpF0InmZhLaMMh8I4Ua59mL48,5676
18
18
  psyke/extraction/hypercubic/gridrex/__init__.py,sha256=h9usK5tFqd6ngBmRydsgkfQ1jlcQKj2uG72Tr1puFHk,595
19
19
  psyke/extraction/hypercubic/hex/__init__.py,sha256=vP0n30iKi0eVi_6Jqorw8MendBwm7zOQQEvj8bFkfas,4562
20
20
  psyke/extraction/hypercubic/iter/__init__.py,sha256=vpbOLYYqXvKheyOoa1qmVz2wi4F7B4lJ2I6MRHJ7Xg0,10084
@@ -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.8.2.dev9.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
- psyke-0.8.2.dev9.dist-info/METADATA,sha256=m__SZz14ZVd-kWp_ctCl7_w8QVB56rBL5kFsufGP5s4,8107
38
- psyke-0.8.2.dev9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
- psyke-0.8.2.dev9.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
- psyke-0.8.2.dev9.dist-info/RECORD,,
36
+ psyke-0.8.2.dev15.dist-info/LICENSE,sha256=KP9K6Hgezf_xdMFW7ORyKz9uA8Y8k52YJn292wcP-_E,11354
37
+ psyke-0.8.2.dev15.dist-info/METADATA,sha256=y8no9N9QPkZkBZoFTrqyF6ubDuoUWsVGZGsDbWQOGVo,8108
38
+ psyke-0.8.2.dev15.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
+ psyke-0.8.2.dev15.dist-info/top_level.txt,sha256=q1HglxOqqoIRukFtyis_ZNHczZg4gANRUPWkD7HAUTU,6
40
+ psyke-0.8.2.dev15.dist-info/RECORD,,