iita-python 1.2__tar.gz → 1.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iita_python
3
- Version: 1.2
3
+ Version: 1.3
4
4
  Summary: IITA algorithm in python
5
5
  Author-email: Aliaksei Badnarchuk <alexejbodnarchuk@gmail.com>
6
6
  Requires-Python: >=3.9
@@ -0,0 +1,5 @@
1
+ from .dataset import Dataset
2
+ from .quasiorder import ind_gen
3
+ from . import fit_metrics
4
+
5
+ __all__ = ['Dataset', 'ind_gen', 'fit_metrics']
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '1.2'
32
- __version_tuple__ = version_tuple = (1, 2)
31
+ __version__ = version = '1.3'
32
+ __version_tuple__ = version_tuple = (1, 3)
33
33
 
34
- __commit_id__ = commit_id = 'gb97b590cd'
34
+ __commit_id__ = commit_id = 'g087a84930'
@@ -15,12 +15,12 @@ def pairwise_diff_ce(rp: pd.DataFrame) -> pd.DataFrame:
15
15
  items = rp.shape[1]
16
16
  subjects = rp.shape[0]
17
17
 
18
- ce = pd.DataFrame(0, index=np.arange(items), columns=np.arange(items))
18
+ ce = pd.DataFrame(0, index=rp.columns, columns=rp.columns)
19
19
  for i in range(subjects):
20
20
  # for subject i, if a < b, add b - a for all item pairs (a,b)
21
21
  # this is equivalent to ce[a][b] += 1 if a=0 and b=1, but works for non-binary data as well
22
22
 
23
- row = rp.loc[i].to_numpy()
23
+ row = rp.iloc[i].to_numpy()
24
24
  ce -= np.clip(row[:, None] - row[None, :], None, 0)
25
25
 
26
26
  return ce
@@ -39,10 +39,10 @@ def missing_value_substitution_ce(rp: pd.DataFrame) -> pd.DataFrame:
39
39
 
40
40
  for i in range(items):
41
41
  # substitute missing values in item i with the mean of the item
42
- col = rp1.loc[:, i].to_numpy()
42
+ col = rp1.iloc[:, i].to_numpy()
43
43
  mean_val = np.nanmean(col)
44
44
  col = pd.Series(col).fillna(mean_val)
45
- rp1.loc[:, i] = col
45
+ rp1.iloc[:, i] = col
46
46
 
47
47
  # then calculate pairwise difference counterexamples
48
48
  return pairwise_diff_ce(rp1)
@@ -64,10 +64,10 @@ def relativify(calculator: callable):
64
64
  items = rp.shape[1]
65
65
  subjects = rp.shape[0]
66
66
 
67
- valid_cases = pd.DataFrame(0, index=np.arange(items), columns=np.arange(items))
67
+ valid_cases = pd.DataFrame(0, index=rp.columns, columns=rp.columns)
68
68
  for i in range(subjects):
69
69
  #for subject i, increment all cases where neither a nor b are NaN (valid case for counterexamples)
70
- not_nan = np.logical_not(rp.loc[i].isna())
70
+ not_nan = np.logical_not(rp.iloc[i].isna())
71
71
  valid_cases += np.outer(not_nan, not_nan).astype(int)
72
72
 
73
73
  # avoid division by zero
@@ -90,12 +90,10 @@ class AdditionalCEDataset(Dataset):
90
90
  """
91
91
  super().__init__(response_patterns)
92
92
 
93
- self.pairwise_diff_ce = lambda self, relative=False: (
94
- relativify(pairwise_diff_ce) if relative else pairwise_diff_ce
95
- )(self.rp)
93
+ self.pairwise_diff_ce = lambda: pairwise_diff_ce(self.rp)
96
94
  self.pairwise_diff_ce.__doc__ = pairwise_diff_ce.__doc__
97
95
 
98
- self.missing_value_substitution_ce = lambda self, relative=False: (
96
+ self.missing_value_substitution_ce = lambda relative=False: (
99
97
  relativify(missing_value_substitution_ce) if relative else missing_value_substitution_ce
100
98
  )(self.rp)
101
99
  self.missing_value_substitution_ce.__doc__ = missing_value_substitution_ce.__doc__
@@ -47,30 +47,30 @@ class Dataset():
47
47
  Supports pandas dataframes, numpy arrays, and python lists\n
48
48
  Rows represent the subjects, columns - the items\n
49
49
  """
50
- self._rp = pd.DataFrame(response_patterns, index=None, columns=None)
50
+ self._rp = pd.DataFrame(response_patterns)
51
51
  self._ce = None
52
52
  self._eqe = None
53
53
 
54
54
  #counterexamples computation
55
- self.ce = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
55
+ self.ce = pd.DataFrame(0, index=self.rp.columns, columns=self.rp.columns)
56
56
 
57
57
  for i in range(self.subjects):
58
58
  #for subject i, increment all cases where a=0 and b=1 (counterexamples to b->a or a <= b)
59
- not_a = (self.rp.loc[i] == 0)
60
- b = (self.rp.loc[i] == 1)
59
+ not_a = (self.rp.iloc[i] == 0)
60
+ b = (self.rp.iloc[i] == 1)
61
61
  self.ce.loc[not_a, b] += 1
62
62
 
63
63
  #equivalence examples computation
64
- self.eqe = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
64
+ self.eqe = pd.DataFrame(0, index=self.rp.columns, columns=self.rp.columns)
65
65
  for i in range(self.subjects):
66
66
  #for subject i, increment all cases where a=b (examples of equivalence of a and b)
67
- row = self.rp.loc[i].to_numpy()
67
+ row = self.rp.iloc[i].to_numpy()
68
68
  self.eqe += np.equal.outer(row, row).astype(int)
69
69
 
70
- self.valid_ce_cases = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
70
+ self.valid_ce_cases = pd.DataFrame(0, index=self.rp.columns, columns=self.rp.columns)
71
71
  for i in range(self.subjects):
72
72
  #for subject i, increment all cases where neither a nor b are NaN (valid case for counterexamples)
73
- not_nan = np.logical_not(self.rp.loc[i].isna())
73
+ not_nan = np.logical_not(self.rp.iloc[i].isna())
74
74
  self.valid_ce_cases += np.outer(not_nan, not_nan).astype(int)
75
75
 
76
76
  def add(self, dataset_to_add: Self):
@@ -20,31 +20,20 @@ class QuasiOrder:
20
20
  if (self.full_matrix[i][j]):
21
21
  edge_list.append([i+buff, j+buff])
22
22
 
23
- return edge_list
23
+ return edge_list
24
24
 
25
- def unfold_examples(
26
- matrix: pd.DataFrame
27
- ) -> npt.NDArray:
25
+ def ind_gen(counterexamples: pd.DataFrame, n: int) -> list[QuasiOrder]:
28
26
  """
29
- Turns an item/item metric DataFrame into
30
- a list of tuples of the form (x, [i, j]), where matrix[i, j] = x.\n
27
+ Inductively generates quasiorders from counterexample count DataFrame\n
31
28
  """
32
29
 
33
- dfmatrix = pd.DataFrame(matrix)
30
+ dfce = pd.DataFrame(counterexamples)
34
31
 
35
- n = dfmatrix.shape[0]
32
+ n = dfce.shape[0]
36
33
  pos = np.arange(n, dtype=np.int_)
37
34
  i = np.repeat(pos, n)
38
35
  j = np.tile(pos, n)
39
- res = np.array(list(zip(dfmatrix.to_numpy()[i, j], i, j)))
40
- return res[res[:, 1] != res[:, 2]]
41
-
42
- def ind_gen(counterexamples: npt.NDArray, n: int) -> list[QuasiOrder]:
43
- """
44
- Inductively generates quasiorders from counterexample edge list\n
45
- Counterexamples is expected to be of the form returned by unfold_examples (array of (x, i, j) tuples)\n
46
- """
47
- ce = counterexamples
36
+ ce = np.array(list(zip(dfce.to_numpy()[i, j], i, j)))
48
37
 
49
38
  if (len(ce) == 0): raise ValueError("Counterexamples can't be empty")
50
39
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iita_python
3
- Version: 1.2
3
+ Version: 1.3
4
4
  Summary: IITA algorithm in python
5
5
  Author-email: Aliaksei Badnarchuk <alexejbodnarchuk@gmail.com>
6
6
  Requires-Python: >=3.9
@@ -1,4 +0,0 @@
1
- from .dataset import Dataset
2
- from .quasiorder import ind_gen, unfold_examples
3
-
4
- __all__ = ['Dataset', 'unfold_examples', 'ind_gen']
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes