iita-python 1.0.2__tar.gz → 1.2__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.
- {iita_python-1.0.2/iita_python.egg-info → iita_python-1.2}/PKG-INFO +2 -2
- {iita_python-1.0.2 → iita_python-1.2}/README.md +1 -1
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/_version.py +3 -3
- iita_python-1.2/iita_python/additional_ce.py +101 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/dataset.py +20 -7
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/quasiorder.py +3 -13
- {iita_python-1.0.2 → iita_python-1.2/iita_python.egg-info}/PKG-INFO +2 -2
- {iita_python-1.0.2 → iita_python-1.2}/iita_python.egg-info/SOURCES.txt +2 -5
- iita_python-1.0.2/test_ipynbs/fit_metrics.ipynb +0 -235
- iita_python-1.0.2/test_ipynbs/pisa.csv +0 -340
- iita_python-1.0.2/test_ipynbs/quasi-order-gen.ipynb +0 -219
- iita_python-1.0.2/test_ipynbs/sim_missing_data.ipynb +0 -176
- {iita_python-1.0.2 → iita_python-1.2}/.github/workflows/release.yaml +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/.gitignore +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/__init__.py +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/fit_metrics.py +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python/utils.py +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python.egg-info/dependency_links.txt +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python.egg-info/requires.txt +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/iita_python.egg-info/top_level.txt +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/pyproject.toml +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/setuf.cfg +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/setup.cfg +0 -0
- {iita_python-1.0.2 → iita_python-1.2}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iita_python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Summary: IITA algorithm in python
|
|
5
5
|
Author-email: Aliaksei Badnarchuk <alexejbodnarchuk@gmail.com>
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -111,7 +111,7 @@ Returns: float (MSE, lower is better)
|
|
|
111
111
|
|
|
112
112
|
## Testing
|
|
113
113
|
|
|
114
|
-
See the `
|
|
114
|
+
See the `testing` branch. You can open the Jupyter notebooks in Google Colab and run all cells to see test results.
|
|
115
115
|
|
|
116
116
|
I am comparing my results on the PISA dataset to those of Milan Segedinac ([his implementation](https://github.com/milansegedinac/kst))
|
|
117
117
|
|
|
@@ -101,7 +101,7 @@ Returns: float (MSE, lower is better)
|
|
|
101
101
|
|
|
102
102
|
## Testing
|
|
103
103
|
|
|
104
|
-
See the `
|
|
104
|
+
See the `testing` branch. You can open the Jupyter notebooks in Google Colab and run all cells to see test results.
|
|
105
105
|
|
|
106
106
|
I am comparing my results on the PISA dataset to those of Milan Segedinac ([his implementation](https://github.com/milansegedinac/kst))
|
|
107
107
|
|
|
@@ -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.
|
|
32
|
-
__version_tuple__ = version_tuple = (1,
|
|
31
|
+
__version__ = version = '1.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'gb97b590cd'
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy.typing as npt
|
|
4
|
+
from typing import Self, List
|
|
5
|
+
|
|
6
|
+
from iita_python.dataset import Dataset
|
|
7
|
+
|
|
8
|
+
def pairwise_diff_ce(rp: pd.DataFrame) -> pd.DataFrame:
|
|
9
|
+
"""
|
|
10
|
+
Computes counterexamples from a response pattern DataFrame by using pairwise differences of item correspondences\n
|
|
11
|
+
Can be used for non-binary data because of not relying on strict 0/1 values\n
|
|
12
|
+
Does not support missing values in the response patterns\n
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
items = rp.shape[1]
|
|
16
|
+
subjects = rp.shape[0]
|
|
17
|
+
|
|
18
|
+
ce = pd.DataFrame(0, index=np.arange(items), columns=np.arange(items))
|
|
19
|
+
for i in range(subjects):
|
|
20
|
+
# for subject i, if a < b, add b - a for all item pairs (a,b)
|
|
21
|
+
# this is equivalent to ce[a][b] += 1 if a=0 and b=1, but works for non-binary data as well
|
|
22
|
+
|
|
23
|
+
row = rp.loc[i].to_numpy()
|
|
24
|
+
ce -= np.clip(row[:, None] - row[None, :], None, 0)
|
|
25
|
+
|
|
26
|
+
return ce
|
|
27
|
+
|
|
28
|
+
def missing_value_substitution_ce(rp: pd.DataFrame) -> pd.DataFrame:
|
|
29
|
+
"""
|
|
30
|
+
Computes counterexamples from a response pattern DataFrame by using pairwise differences of item correspondences\n
|
|
31
|
+
Substitutes missing values in the response patterns with the mean of the item, making some counterexample amounts fractional\n
|
|
32
|
+
Can be used for non-binary data because of not relying on strict 0/1 values\n
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
items = rp.shape[1]
|
|
36
|
+
subjects = rp.shape[0]
|
|
37
|
+
|
|
38
|
+
rp1 = rp.copy()
|
|
39
|
+
|
|
40
|
+
for i in range(items):
|
|
41
|
+
# substitute missing values in item i with the mean of the item
|
|
42
|
+
col = rp1.loc[:, i].to_numpy()
|
|
43
|
+
mean_val = np.nanmean(col)
|
|
44
|
+
col = pd.Series(col).fillna(mean_val)
|
|
45
|
+
rp1.loc[:, i] = col
|
|
46
|
+
|
|
47
|
+
# then calculate pairwise difference counterexamples
|
|
48
|
+
return pairwise_diff_ce(rp1)
|
|
49
|
+
|
|
50
|
+
def relativify(calculator: callable):
|
|
51
|
+
"""
|
|
52
|
+
Decorator to relativify counterexample calculators\n
|
|
53
|
+
The counterexample amounts are divided by the number of cases for each item pair where both items are not missing\n
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def wrapper(rp: pd.DataFrame):
|
|
57
|
+
f"""
|
|
58
|
+
Computes counterexamples relative to the amount of valid cases using {calculator.__name__} as base calculator\n
|
|
59
|
+
The counterexample amounts are divided by the number of cases for each item pair where both items are not missing\n
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
ce = calculator(rp)
|
|
63
|
+
|
|
64
|
+
items = rp.shape[1]
|
|
65
|
+
subjects = rp.shape[0]
|
|
66
|
+
|
|
67
|
+
valid_cases = pd.DataFrame(0, index=np.arange(items), columns=np.arange(items))
|
|
68
|
+
for i in range(subjects):
|
|
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())
|
|
71
|
+
valid_cases += np.outer(not_nan, not_nan).astype(int)
|
|
72
|
+
|
|
73
|
+
# avoid division by zero
|
|
74
|
+
valid_cases = valid_cases.replace(0, 1)
|
|
75
|
+
|
|
76
|
+
return ce / valid_cases
|
|
77
|
+
|
|
78
|
+
return wrapper
|
|
79
|
+
|
|
80
|
+
class AdditionalCEDataset(Dataset):
|
|
81
|
+
def __init__(self, response_patterns: pd.DataFrame | npt.NDArray | List[List[int]]):
|
|
82
|
+
"""
|
|
83
|
+
Computes the counterexamples and equivalence examples from response patterns\n
|
|
84
|
+
Supports pandas dataframes, numpy arrays, and python lists\n
|
|
85
|
+
Rows represent the subjects, columns - the items\n
|
|
86
|
+
|
|
87
|
+
In addition to the base Dataset, this class provides additional counterexample calculators:\n
|
|
88
|
+
- pairwise_diff_ce: computes counterexamples using pairwise differences of item correspondences, allowing for non-binary data\n
|
|
89
|
+
- missing_value_substitution_ce: computes counterexamples using pairwise differences with missing values substituted by item means\n
|
|
90
|
+
"""
|
|
91
|
+
super().__init__(response_patterns)
|
|
92
|
+
|
|
93
|
+
self.pairwise_diff_ce = lambda self, relative=False: (
|
|
94
|
+
relativify(pairwise_diff_ce) if relative else pairwise_diff_ce
|
|
95
|
+
)(self.rp)
|
|
96
|
+
self.pairwise_diff_ce.__doc__ = pairwise_diff_ce.__doc__
|
|
97
|
+
|
|
98
|
+
self.missing_value_substitution_ce = lambda self, relative=False: (
|
|
99
|
+
relativify(missing_value_substitution_ce) if relative else missing_value_substitution_ce
|
|
100
|
+
)(self.rp)
|
|
101
|
+
self.missing_value_substitution_ce.__doc__ = missing_value_substitution_ce.__doc__
|
|
@@ -31,7 +31,7 @@ class Dataset():
|
|
|
31
31
|
|
|
32
32
|
@property
|
|
33
33
|
def items(self):
|
|
34
|
-
return self.
|
|
34
|
+
return self.rp.shape[1]
|
|
35
35
|
|
|
36
36
|
@property
|
|
37
37
|
def subjects(self):
|
|
@@ -52,31 +52,44 @@ class Dataset():
|
|
|
52
52
|
self._eqe = None
|
|
53
53
|
|
|
54
54
|
#counterexamples computation
|
|
55
|
-
self.ce = pd.DataFrame(0, index=np.arange(self.
|
|
55
|
+
self.ce = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
|
|
56
56
|
|
|
57
|
-
for i in range(
|
|
58
|
-
#for subject i,
|
|
57
|
+
for i in range(self.subjects):
|
|
58
|
+
#for subject i, increment all cases where a=0 and b=1 (counterexamples to b->a or a <= b)
|
|
59
59
|
not_a = (self.rp.loc[i] == 0)
|
|
60
60
|
b = (self.rp.loc[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.
|
|
65
|
-
for i in range(
|
|
64
|
+
self.eqe = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
|
|
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
67
|
row = self.rp.loc[i].to_numpy()
|
|
68
68
|
self.eqe += np.equal.outer(row, row).astype(int)
|
|
69
|
+
|
|
70
|
+
self.valid_ce_cases = pd.DataFrame(0, index=np.arange(self.items), columns=np.arange(self.items))
|
|
71
|
+
for i in range(self.subjects):
|
|
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())
|
|
74
|
+
self.valid_ce_cases += np.outer(not_nan, not_nan).astype(int)
|
|
69
75
|
|
|
70
76
|
def add(self, dataset_to_add: Self):
|
|
71
77
|
"""
|
|
72
78
|
Add a second IITA_Dataset: concatenate the response patterns, add counterexamples and equivalence examples\n
|
|
73
79
|
Item amounts must match, else ValueError
|
|
74
80
|
"""
|
|
75
|
-
if (self.
|
|
81
|
+
if (self.items != dataset_to_add.items):
|
|
76
82
|
raise ValueError('Item amounts must match')
|
|
77
83
|
|
|
78
84
|
self.rp = pd.concat(self.rp, dataset_to_add.rp)
|
|
79
85
|
self.ce = self.ce + dataset_to_add.ce
|
|
80
86
|
self.eqe = self.eqe + dataset_to_add.eqe
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def relative_ce(self) -> pd.DataFrame:
|
|
90
|
+
"""
|
|
91
|
+
Returns the counterexamples matrix accounting for missing values
|
|
92
|
+
"""
|
|
93
|
+
return self.ce / self.valid_ce_cases
|
|
81
94
|
|
|
82
95
|
__iadd__ = add
|
|
@@ -23,30 +23,20 @@ class QuasiOrder:
|
|
|
23
23
|
return edge_list
|
|
24
24
|
|
|
25
25
|
def unfold_examples(
|
|
26
|
-
matrix: pd.DataFrame
|
|
27
|
-
relativity: npt.NDArray | None = None,
|
|
28
|
-
dtype=np.float32
|
|
26
|
+
matrix: pd.DataFrame
|
|
29
27
|
) -> npt.NDArray:
|
|
30
28
|
"""
|
|
31
29
|
Turns an item/item metric DataFrame into
|
|
32
30
|
a list of tuples of the form (x, [i, j]), where matrix[i, j] = x.\n
|
|
33
|
-
Can input a relativity matrix, then exery x gets divided by relativity[i, j].
|
|
34
|
-
This can be used to account for missing values
|
|
35
31
|
"""
|
|
36
32
|
|
|
37
|
-
dfmatrix = pd.DataFrame(matrix)
|
|
38
|
-
|
|
39
|
-
rel = relativity
|
|
40
|
-
if (rel is None):
|
|
41
|
-
rel = np.ones(dfmatrix.shape, dtype=int)
|
|
42
|
-
|
|
43
|
-
dfmatrix = dfmatrix / rel
|
|
33
|
+
dfmatrix = pd.DataFrame(matrix)
|
|
44
34
|
|
|
45
35
|
n = dfmatrix.shape[0]
|
|
46
36
|
pos = np.arange(n, dtype=np.int_)
|
|
47
37
|
i = np.repeat(pos, n)
|
|
48
38
|
j = np.tile(pos, n)
|
|
49
|
-
res = np.array(list(zip(dfmatrix.to_numpy()[i, j], i, j))
|
|
39
|
+
res = np.array(list(zip(dfmatrix.to_numpy()[i, j], i, j)))
|
|
50
40
|
return res[res[:, 1] != res[:, 2]]
|
|
51
41
|
|
|
52
42
|
def ind_gen(counterexamples: npt.NDArray, n: int) -> list[QuasiOrder]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iita_python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Summary: IITA algorithm in python
|
|
5
5
|
Author-email: Aliaksei Badnarchuk <alexejbodnarchuk@gmail.com>
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -111,7 +111,7 @@ Returns: float (MSE, lower is better)
|
|
|
111
111
|
|
|
112
112
|
## Testing
|
|
113
113
|
|
|
114
|
-
See the `
|
|
114
|
+
See the `testing` branch. You can open the Jupyter notebooks in Google Colab and run all cells to see test results.
|
|
115
115
|
|
|
116
116
|
I am comparing my results on the PISA dataset to those of Milan Segedinac ([his implementation](https://github.com/milansegedinac/kst))
|
|
117
117
|
|
|
@@ -6,6 +6,7 @@ setup.py
|
|
|
6
6
|
.github/workflows/release.yaml
|
|
7
7
|
iita_python/__init__.py
|
|
8
8
|
iita_python/_version.py
|
|
9
|
+
iita_python/additional_ce.py
|
|
9
10
|
iita_python/dataset.py
|
|
10
11
|
iita_python/fit_metrics.py
|
|
11
12
|
iita_python/quasiorder.py
|
|
@@ -14,8 +15,4 @@ iita_python.egg-info/PKG-INFO
|
|
|
14
15
|
iita_python.egg-info/SOURCES.txt
|
|
15
16
|
iita_python.egg-info/dependency_links.txt
|
|
16
17
|
iita_python.egg-info/requires.txt
|
|
17
|
-
iita_python.egg-info/top_level.txt
|
|
18
|
-
test_ipynbs/fit_metrics.ipynb
|
|
19
|
-
test_ipynbs/pisa.csv
|
|
20
|
-
test_ipynbs/quasi-order-gen.ipynb
|
|
21
|
-
test_ipynbs/sim_missing_data.ipynb
|
|
18
|
+
iita_python.egg-info/top_level.txt
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cells": [
|
|
3
|
-
{
|
|
4
|
-
"cell_type": "markdown",
|
|
5
|
-
"id": "aefc5a77",
|
|
6
|
-
"metadata": {
|
|
7
|
-
"id": "aefc5a77"
|
|
8
|
-
},
|
|
9
|
-
"source": [
|
|
10
|
-
"# Testing the fit metric calculation on the PISA dataset, comparing to the KST library by Milan Segedinac"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"cell_type": "markdown",
|
|
15
|
-
"source": [
|
|
16
|
-
"1. Imporitng both libraries and requirements"
|
|
17
|
-
],
|
|
18
|
-
"metadata": {
|
|
19
|
-
"id": "dzpt8hYXs7kO"
|
|
20
|
-
},
|
|
21
|
-
"id": "dzpt8hYXs7kO"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"cell_type": "code",
|
|
25
|
-
"source": [
|
|
26
|
-
"!git clone https://github.com/Alexe1900/iita_python.git\n",
|
|
27
|
-
"!git clone https://github.com/milansegedinac/kst.git\n",
|
|
28
|
-
"!pip install numpy\n",
|
|
29
|
-
"!pip install pandas\n",
|
|
30
|
-
"import sys\n",
|
|
31
|
-
"sys.path.append(\"/content/iita_python\")\n",
|
|
32
|
-
"sys.path.append(\"/content/kst\")\n",
|
|
33
|
-
"import numpy as np\n",
|
|
34
|
-
"import pandas as pd\n",
|
|
35
|
-
"import iita_python as test_iita\n",
|
|
36
|
-
"import learning_spaces.kst as kst"
|
|
37
|
-
],
|
|
38
|
-
"metadata": {
|
|
39
|
-
"id": "s4P_gsz7tDlG",
|
|
40
|
-
"outputId": "03b37282-44e0-43f1-996e-ba3de8248eab",
|
|
41
|
-
"colab": {
|
|
42
|
-
"base_uri": "https://localhost:8080/"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"id": "s4P_gsz7tDlG",
|
|
46
|
-
"execution_count": 1,
|
|
47
|
-
"outputs": [
|
|
48
|
-
{
|
|
49
|
-
"output_type": "stream",
|
|
50
|
-
"name": "stdout",
|
|
51
|
-
"text": [
|
|
52
|
-
"fatal: destination path 'iita_python' already exists and is not an empty directory.\n",
|
|
53
|
-
"fatal: destination path 'kst' already exists and is not an empty directory.\n",
|
|
54
|
-
"Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (2.0.2)\n",
|
|
55
|
-
"Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (2.2.2)\n",
|
|
56
|
-
"Requirement already satisfied: numpy>=1.26.0 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.0.2)\n",
|
|
57
|
-
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.9.0.post0)\n",
|
|
58
|
-
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n",
|
|
59
|
-
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n",
|
|
60
|
-
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n"
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"cell_type": "markdown",
|
|
67
|
-
"source": [
|
|
68
|
-
"2. Importing the dataset, generating quasi-orders"
|
|
69
|
-
],
|
|
70
|
-
"metadata": {
|
|
71
|
-
"id": "Wwxr0c_rtSMN"
|
|
72
|
-
},
|
|
73
|
-
"id": "Wwxr0c_rtSMN"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"cell_type": "code",
|
|
77
|
-
"source": [
|
|
78
|
-
"from iita_python.utils import read_rp\n",
|
|
79
|
-
"\n",
|
|
80
|
-
"data_raw = read_rp(\"iita_python/test_ipynbs/pisa.csv\")\n",
|
|
81
|
-
"data = test_iita.Dataset(data_raw)\n",
|
|
82
|
-
"\n",
|
|
83
|
-
"unfolded_ce = test_iita.unfold_examples(data.counterexamples)\n",
|
|
84
|
-
"qos = test_iita.ind_gen(unfolded_ce, data.items)"
|
|
85
|
-
],
|
|
86
|
-
"metadata": {
|
|
87
|
-
"id": "7CZKj4kktWg6"
|
|
88
|
-
},
|
|
89
|
-
"id": "7CZKj4kktWg6",
|
|
90
|
-
"execution_count": 2,
|
|
91
|
-
"outputs": []
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"cell_type": "markdown",
|
|
95
|
-
"source": [
|
|
96
|
-
"3. Testing the fit metrics"
|
|
97
|
-
],
|
|
98
|
-
"metadata": {
|
|
99
|
-
"id": "t-RqTjTEuBUo"
|
|
100
|
-
},
|
|
101
|
-
"id": "t-RqTjTEuBUo"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
"cell_type": "markdown",
|
|
105
|
-
"source": [
|
|
106
|
-
"3.1. Original IITA fit metric"
|
|
107
|
-
],
|
|
108
|
-
"metadata": {
|
|
109
|
-
"id": "oXyUJR12jT22"
|
|
110
|
-
},
|
|
111
|
-
"id": "oXyUJR12jT22"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"cell_type": "code",
|
|
115
|
-
"source": [
|
|
116
|
-
"import iita_python.fit_metrics as test_fit\n",
|
|
117
|
-
"corrects = kst.iita(data.response_patterns, 3)['diff']\n",
|
|
118
|
-
"\n",
|
|
119
|
-
"for i, qo in enumerate(qos):\n",
|
|
120
|
-
" test_metric = round(test_fit.orig_iita_fit(data, qo), 3)\n",
|
|
121
|
-
" corr_metric = round(corrects[i], 3)\n",
|
|
122
|
-
"\n",
|
|
123
|
-
" try:\n",
|
|
124
|
-
" assert (test_metric == corr_metric)\n",
|
|
125
|
-
" print(f'Fit metric {i}/{len(qos)} correct ✅')\n",
|
|
126
|
-
" except AssertionError:\n",
|
|
127
|
-
" print(f'Fit metric {i}/{len(qos)} incorrect ❌')\n",
|
|
128
|
-
" print(f'Test: {test_metric}')\n",
|
|
129
|
-
" print(f'Correct: {corr_metric}')"
|
|
130
|
-
],
|
|
131
|
-
"metadata": {
|
|
132
|
-
"id": "a5IvxR1I7-BG",
|
|
133
|
-
"outputId": "abc3c1be-79b3-4721-9c7c-a6e0e6669ba7",
|
|
134
|
-
"colab": {
|
|
135
|
-
"base_uri": "https://localhost:8080/"
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
"id": "a5IvxR1I7-BG",
|
|
139
|
-
"execution_count": 8,
|
|
140
|
-
"outputs": [
|
|
141
|
-
{
|
|
142
|
-
"output_type": "stream",
|
|
143
|
-
"name": "stdout",
|
|
144
|
-
"text": [
|
|
145
|
-
"Fit metric 0/13 correct ✅\n",
|
|
146
|
-
"Fit metric 1/13 correct ✅\n",
|
|
147
|
-
"Fit metric 2/13 correct ✅\n",
|
|
148
|
-
"Fit metric 3/13 correct ✅\n",
|
|
149
|
-
"Fit metric 4/13 correct ✅\n",
|
|
150
|
-
"Fit metric 5/13 correct ✅\n",
|
|
151
|
-
"Fit metric 6/13 correct ✅\n",
|
|
152
|
-
"Fit metric 7/13 correct ✅\n",
|
|
153
|
-
"Fit metric 8/13 correct ✅\n",
|
|
154
|
-
"Fit metric 9/13 correct ✅\n",
|
|
155
|
-
"Fit metric 10/13 correct ✅\n",
|
|
156
|
-
"Fit metric 11/13 correct ✅\n",
|
|
157
|
-
"Fit metric 12/13 correct ✅\n"
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"cell_type": "markdown",
|
|
164
|
-
"source": [
|
|
165
|
-
"3.2. Corrected fit metric"
|
|
166
|
-
],
|
|
167
|
-
"metadata": {
|
|
168
|
-
"id": "VIPtCas5jXP3"
|
|
169
|
-
},
|
|
170
|
-
"id": "VIPtCas5jXP3"
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
"cell_type": "code",
|
|
174
|
-
"source": [
|
|
175
|
-
"corrects = kst.iita(data.response_patterns, 2)['diff']\n",
|
|
176
|
-
"\n",
|
|
177
|
-
"for i, qo in enumerate(qos):\n",
|
|
178
|
-
" test_metric = round(test_fit.corr_iita_fit(data, qo), 3)\n",
|
|
179
|
-
" corr_metric = round(corrects[i], 3)\n",
|
|
180
|
-
"\n",
|
|
181
|
-
" try:\n",
|
|
182
|
-
" assert (test_metric == corr_metric)\n",
|
|
183
|
-
" print(f'Fit metric {i}/{len(qos)} correct ✅')\n",
|
|
184
|
-
" except AssertionError:\n",
|
|
185
|
-
" print(f'Fit metric {i}/{len(qos)} incorrect ❌')\n",
|
|
186
|
-
" print(f'Test: {test_metric}')\n",
|
|
187
|
-
" print(f'Correct: {corr_metric}')"
|
|
188
|
-
],
|
|
189
|
-
"metadata": {
|
|
190
|
-
"id": "j1LoyigWjc5t",
|
|
191
|
-
"outputId": "bd2ca738-1a94-4ce8-b507-325a1acdf9e1",
|
|
192
|
-
"colab": {
|
|
193
|
-
"base_uri": "https://localhost:8080/"
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
"id": "j1LoyigWjc5t",
|
|
197
|
-
"execution_count": 9,
|
|
198
|
-
"outputs": [
|
|
199
|
-
{
|
|
200
|
-
"output_type": "stream",
|
|
201
|
-
"name": "stdout",
|
|
202
|
-
"text": [
|
|
203
|
-
"Fit metric 0/13 correct ✅\n",
|
|
204
|
-
"Fit metric 1/13 correct ✅\n",
|
|
205
|
-
"Fit metric 2/13 correct ✅\n",
|
|
206
|
-
"Fit metric 3/13 correct ✅\n",
|
|
207
|
-
"Fit metric 4/13 correct ✅\n",
|
|
208
|
-
"Fit metric 5/13 correct ✅\n",
|
|
209
|
-
"Fit metric 6/13 correct ✅\n",
|
|
210
|
-
"Fit metric 7/13 correct ✅\n",
|
|
211
|
-
"Fit metric 8/13 correct ✅\n",
|
|
212
|
-
"Fit metric 9/13 correct ✅\n",
|
|
213
|
-
"Fit metric 10/13 correct ✅\n",
|
|
214
|
-
"Fit metric 11/13 correct ✅\n",
|
|
215
|
-
"Fit metric 12/13 correct ✅\n"
|
|
216
|
-
]
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
}
|
|
220
|
-
],
|
|
221
|
-
"metadata": {
|
|
222
|
-
"language_info": {
|
|
223
|
-
"name": "python"
|
|
224
|
-
},
|
|
225
|
-
"colab": {
|
|
226
|
-
"provenance": []
|
|
227
|
-
},
|
|
228
|
-
"kernelspec": {
|
|
229
|
-
"name": "python3",
|
|
230
|
-
"display_name": "Python 3"
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
"nbformat": 4,
|
|
234
|
-
"nbformat_minor": 5
|
|
235
|
-
}
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
1,0,0,0,0
|
|
2
|
-
0,0,0,0,0
|
|
3
|
-
1,0,0,0,0
|
|
4
|
-
1,0,0,0,0
|
|
5
|
-
0,1,0,0,0
|
|
6
|
-
1,1,0,0,0
|
|
7
|
-
0,0,0,0,0
|
|
8
|
-
1,1,0,0,1
|
|
9
|
-
1,1,0,0,0
|
|
10
|
-
1,1,0,0,0
|
|
11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
|
216
|
-
1,1,1,0,0
|
|
217
|
-
1,1,1,1,0
|
|
218
|
-
1,0,1,0,0
|
|
219
|
-
1,1,1,0,0
|
|
220
|
-
0,1,1,0,0
|
|
221
|
-
1,1,1,1,1
|
|
222
|
-
1,1,1,0,0
|
|
223
|
-
1,1,1,1,0
|
|
224
|
-
1,1,1,1,0
|
|
225
|
-
1,0,1,1,0
|
|
226
|
-
1,1,1,0,1
|
|
227
|
-
1,1,1,0,0
|
|
228
|
-
1,1,1,1,0
|
|
229
|
-
1,1,1,0,0
|
|
230
|
-
1,1,1,0,0
|
|
231
|
-
1,1,1,1,0
|
|
232
|
-
1,1,1,0,0
|
|
233
|
-
1,1,1,1,0
|
|
234
|
-
1,1,1,0,0
|
|
235
|
-
1,0,1,1,0
|
|
236
|
-
1,1,1,1,1
|
|
237
|
-
1,1,1,0,0
|
|
238
|
-
1,1,1,1,0
|
|
239
|
-
1,1,1,1,0
|
|
240
|
-
1,1,1,1,0
|
|
241
|
-
1,1,1,1,0
|
|
242
|
-
1,1,1,0,0
|
|
243
|
-
1,1,1,0,0
|
|
244
|
-
1,1,1,1,0
|
|
245
|
-
1,1,1,1,0
|
|
246
|
-
1,1,1,1,1
|
|
247
|
-
1,1,1,0,0
|
|
248
|
-
1,1,1,1,0
|
|
249
|
-
1,1,1,1,1
|
|
250
|
-
1,1,1,0,0
|
|
251
|
-
1,1,1,0,0
|
|
252
|
-
1,1,1,0,0
|
|
253
|
-
1,1,1,0,0
|
|
254
|
-
1,1,1,0,0
|
|
255
|
-
1,1,1,0,1
|
|
256
|
-
1,0,1,1,0
|
|
257
|
-
1,1,1,0,0
|
|
258
|
-
1,1,1,1,1
|
|
259
|
-
1,1,1,0,0
|
|
260
|
-
1,1,1,0,0
|
|
261
|
-
1,1,1,0,0
|
|
262
|
-
1,1,1,0,0
|
|
263
|
-
1,1,1,0,1
|
|
264
|
-
1,1,1,1,1
|
|
265
|
-
0,1,1,0,1
|
|
266
|
-
1,1,1,0,1
|
|
267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
1,1,1,0,0
|
|
319
|
-
1,1,1,0,0
|
|
320
|
-
1,0,1,0,0
|
|
321
|
-
1,1,1,0,0
|
|
322
|
-
1,1,1,0,0
|
|
323
|
-
1,1,1,0,0
|
|
324
|
-
1,1,1,0,0
|
|
325
|
-
1,1,1,0,0
|
|
326
|
-
1,1,1,0,0
|
|
327
|
-
1,1,1,1,0
|
|
328
|
-
0,1,1,0,0
|
|
329
|
-
1,0,1,1,0
|
|
330
|
-
1,1,1,0,0
|
|
331
|
-
1,0,1,0,0
|
|
332
|
-
0,0,1,0,0
|
|
333
|
-
0,0,1,0,0
|
|
334
|
-
0,1,0,0,0
|
|
335
|
-
0,1,0,0,0
|
|
336
|
-
0,1,0,0,0
|
|
337
|
-
1,0,0,0,0
|
|
338
|
-
1,0,0,0,0
|
|
339
|
-
0,0,0,0,0
|
|
340
|
-
0,0,0,0,0
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cells": [
|
|
3
|
-
{
|
|
4
|
-
"cell_type": "markdown",
|
|
5
|
-
"metadata": {
|
|
6
|
-
"id": "cw9gSDCONN4s"
|
|
7
|
-
},
|
|
8
|
-
"source": [
|
|
9
|
-
"# Testing the quasi-order generation on the PISA dataset, comparing to the KST library by Milan Segedinac"
|
|
10
|
-
]
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"cell_type": "markdown",
|
|
14
|
-
"metadata": {
|
|
15
|
-
"id": "gH1gF08aNy22"
|
|
16
|
-
},
|
|
17
|
-
"source": [
|
|
18
|
-
"1. Importing both libraries and requirements"
|
|
19
|
-
]
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"cell_type": "code",
|
|
23
|
-
"execution_count": null,
|
|
24
|
-
"metadata": {
|
|
25
|
-
"colab": {
|
|
26
|
-
"base_uri": "https://localhost:8080/"
|
|
27
|
-
},
|
|
28
|
-
"id": "bvA-pXFUN36a",
|
|
29
|
-
"outputId": "fefbb9ca-5eb1-41ec-da36-fc31f7de1093"
|
|
30
|
-
},
|
|
31
|
-
"outputs": [
|
|
32
|
-
{
|
|
33
|
-
"name": "stdout",
|
|
34
|
-
"output_type": "stream",
|
|
35
|
-
"text": [
|
|
36
|
-
"fatal: destination path 'iita_python' already exists and is not an empty directory.\n",
|
|
37
|
-
"fatal: destination path 'kst' already exists and is not an empty directory.\n",
|
|
38
|
-
"Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (2.0.2)\n",
|
|
39
|
-
"Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (2.2.2)\n",
|
|
40
|
-
"Requirement already satisfied: numpy>=1.26.0 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.0.2)\n",
|
|
41
|
-
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas) (2.9.0.post0)\n",
|
|
42
|
-
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n",
|
|
43
|
-
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas) (2025.2)\n",
|
|
44
|
-
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n"
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
"source": [
|
|
49
|
-
"!git clone https://github.com/Alexe1900/iita_python.git\n",
|
|
50
|
-
"!git clone https://github.com/milansegedinac/kst.git\n",
|
|
51
|
-
"!pip install numpy\n",
|
|
52
|
-
"!pip install pandas\n",
|
|
53
|
-
"import sys\n",
|
|
54
|
-
"sys.path.append(\"/content/iita_python\")\n",
|
|
55
|
-
"sys.path.append(\"/content/kst\")\n",
|
|
56
|
-
"import numpy as np\n",
|
|
57
|
-
"import pandas as pd\n",
|
|
58
|
-
"import iita_python as iita\n",
|
|
59
|
-
"import learning_spaces.kst as kst"
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"cell_type": "markdown",
|
|
64
|
-
"metadata": {
|
|
65
|
-
"id": "CwlVMK3MO3QJ"
|
|
66
|
-
},
|
|
67
|
-
"source": [
|
|
68
|
-
"2. Importing the dataset"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"cell_type": "code",
|
|
73
|
-
"execution_count": 3,
|
|
74
|
-
"metadata": {
|
|
75
|
-
"colab": {
|
|
76
|
-
"base_uri": "https://localhost:8080/"
|
|
77
|
-
},
|
|
78
|
-
"id": "FvSAv-4cOWQp",
|
|
79
|
-
"outputId": "4d1adf29-3d0c-40cf-d79d-9a8df3d9f945"
|
|
80
|
-
},
|
|
81
|
-
"outputs": [
|
|
82
|
-
{
|
|
83
|
-
"name": "stdout",
|
|
84
|
-
"output_type": "stream",
|
|
85
|
-
"text": [
|
|
86
|
-
"Data imported successfully ✅\n"
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
"source": [
|
|
91
|
-
"from iita_python.utils import read_rp\n",
|
|
92
|
-
"\n",
|
|
93
|
-
"data_raw = read_rp(\"iita_python/test_ipynbs/pisa.csv\")\n",
|
|
94
|
-
"assert not data_raw.empty\n",
|
|
95
|
-
"print(\"Data imported successfully ✅\")"
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"cell_type": "markdown",
|
|
100
|
-
"metadata": {
|
|
101
|
-
"id": "UVRNzocZTCZC"
|
|
102
|
-
},
|
|
103
|
-
"source": [
|
|
104
|
-
"3. Counting the counterexamples"
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"cell_type": "code",
|
|
109
|
-
"execution_count": 6,
|
|
110
|
-
"metadata": {
|
|
111
|
-
"colab": {
|
|
112
|
-
"base_uri": "https://localhost:8080/"
|
|
113
|
-
},
|
|
114
|
-
"id": "lWysv1UsTGPf",
|
|
115
|
-
"outputId": "d24fc04a-e60d-45c6-ce95-c77f859df45e"
|
|
116
|
-
},
|
|
117
|
-
"outputs": [
|
|
118
|
-
{
|
|
119
|
-
"name": "stdout",
|
|
120
|
-
"output_type": "stream",
|
|
121
|
-
"text": [
|
|
122
|
-
"Counterexamples computed correctly ✅\n"
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
],
|
|
126
|
-
"source": [
|
|
127
|
-
"data = iita.Dataset(data_raw)\n",
|
|
128
|
-
"\n",
|
|
129
|
-
"correct_ce = kst.ob_counter(data_raw)\n",
|
|
130
|
-
"\n",
|
|
131
|
-
"try:\n",
|
|
132
|
-
" assert (correct_ce == data.counterexamples.to_numpy()).all()\n",
|
|
133
|
-
" print(\"Counterexamples computed correctly ✅\")\n",
|
|
134
|
-
"except AssertionError:\n",
|
|
135
|
-
" print(\"Counterexamples computed incorrectly ❌\")\n"
|
|
136
|
-
]
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
"cell_type": "markdown",
|
|
140
|
-
"metadata": {
|
|
141
|
-
"id": "H7X3tEf7bGdt"
|
|
142
|
-
},
|
|
143
|
-
"source": [
|
|
144
|
-
"4. Generating the quasi-orders"
|
|
145
|
-
]
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
"cell_type": "code",
|
|
149
|
-
"execution_count": null,
|
|
150
|
-
"metadata": {
|
|
151
|
-
"colab": {
|
|
152
|
-
"base_uri": "https://localhost:8080/"
|
|
153
|
-
},
|
|
154
|
-
"id": "Ywvri9o8bGA0",
|
|
155
|
-
"outputId": "438b2adf-3bb1-4784-cab7-ff32228d5eab"
|
|
156
|
-
},
|
|
157
|
-
"outputs": [
|
|
158
|
-
{
|
|
159
|
-
"name": "stdout",
|
|
160
|
-
"output_type": "stream",
|
|
161
|
-
"text": [
|
|
162
|
-
"Correct number of quasi-orders ✅\n",
|
|
163
|
-
"Quasi-order 0/13 correct ✅\n",
|
|
164
|
-
"Quasi-order 1/13 correct ✅\n",
|
|
165
|
-
"Quasi-order 2/13 correct ✅\n",
|
|
166
|
-
"Quasi-order 3/13 correct ✅\n",
|
|
167
|
-
"Quasi-order 4/13 correct ✅\n",
|
|
168
|
-
"Quasi-order 5/13 correct ✅\n",
|
|
169
|
-
"Quasi-order 6/13 correct ✅\n",
|
|
170
|
-
"Quasi-order 7/13 correct ✅\n",
|
|
171
|
-
"Quasi-order 8/13 correct ✅\n",
|
|
172
|
-
"Quasi-order 9/13 correct ✅\n",
|
|
173
|
-
"Quasi-order 10/13 correct ✅\n",
|
|
174
|
-
"Quasi-order 11/13 correct ✅\n",
|
|
175
|
-
"Quasi-order 12/13 correct ✅\n"
|
|
176
|
-
]
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
"source": [
|
|
180
|
-
"correct_qos = kst.ind_gen(correct_ce)\n",
|
|
181
|
-
"\n",
|
|
182
|
-
"unfolded_ce = iita.unfold_examples(data.counterexamples)\n",
|
|
183
|
-
"test_qos = iita.ind_gen(unfolded_ce, data.items)\n",
|
|
184
|
-
"test_qos = [sorted([(int(a), int(b)) for a, b in qo.get_edge_list()]) for qo in test_qos]\n",
|
|
185
|
-
"\n",
|
|
186
|
-
"try:\n",
|
|
187
|
-
" assert len(correct_qos) == len(test_qos)\n",
|
|
188
|
-
" print(f'Correct number of quasi-orders ✅')\n",
|
|
189
|
-
"except AssertionError:\n",
|
|
190
|
-
" print(f'Wrong number of quasi-orders ❌')\n",
|
|
191
|
-
" quit()\n",
|
|
192
|
-
"\n",
|
|
193
|
-
"for i, (corr_qo, test_qo) in enumerate(zip(correct_qos, test_qos)):\n",
|
|
194
|
-
" corr_qo = sorted(corr_qo)\n",
|
|
195
|
-
" try:\n",
|
|
196
|
-
" assert corr_qo == test_qo\n",
|
|
197
|
-
" print(f'Quasi-order {i}/{len(correct_qos)} correct ✅')\n",
|
|
198
|
-
" except AssertionError:\n",
|
|
199
|
-
" print(f'Quasi-order {i}/{len(correct_qos)} incorrect ❌')\n",
|
|
200
|
-
" print(f'Test: {test_qo}')\n",
|
|
201
|
-
" print(f'Correct: {corr_qo}')"
|
|
202
|
-
]
|
|
203
|
-
}
|
|
204
|
-
],
|
|
205
|
-
"metadata": {
|
|
206
|
-
"colab": {
|
|
207
|
-
"provenance": []
|
|
208
|
-
},
|
|
209
|
-
"kernelspec": {
|
|
210
|
-
"display_name": "Python 3",
|
|
211
|
-
"name": "python3"
|
|
212
|
-
},
|
|
213
|
-
"language_info": {
|
|
214
|
-
"name": "python"
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
"nbformat": 4,
|
|
218
|
-
"nbformat_minor": 0
|
|
219
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cells": [
|
|
3
|
-
{
|
|
4
|
-
"cell_type": "markdown",
|
|
5
|
-
"id": "c534cd3f",
|
|
6
|
-
"metadata": {
|
|
7
|
-
"id": "c534cd3f"
|
|
8
|
-
},
|
|
9
|
-
"source": [
|
|
10
|
-
"# Testing on PISA dataset with randomized missing data"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"cell_type": "markdown",
|
|
15
|
-
"source": [
|
|
16
|
-
"1. Importing package and dataset"
|
|
17
|
-
],
|
|
18
|
-
"metadata": {
|
|
19
|
-
"id": "1nLTjppYSRTe"
|
|
20
|
-
},
|
|
21
|
-
"id": "1nLTjppYSRTe"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"cell_type": "code",
|
|
25
|
-
"source": [
|
|
26
|
-
"!pip install iita_python\n",
|
|
27
|
-
"!git clone https://gist.github.com/717f0147675b0c8ed25e50d583c943bf.git\n",
|
|
28
|
-
"\n",
|
|
29
|
-
"import numpy as np\n",
|
|
30
|
-
"import iita_python as iita\n",
|
|
31
|
-
"import iita_python.fit_metrics as iita_fm\n",
|
|
32
|
-
"from iita_python.utils import read_rp\n",
|
|
33
|
-
"from random import randint\n",
|
|
34
|
-
"\n",
|
|
35
|
-
"data = read_rp('./717f0147675b0c8ed25e50d583c943bf/pisa.csv')"
|
|
36
|
-
],
|
|
37
|
-
"metadata": {
|
|
38
|
-
"id": "SlEiX6B1SSsU",
|
|
39
|
-
"outputId": "55bf001f-aba5-493c-a3a6-77da399684c0",
|
|
40
|
-
"colab": {
|
|
41
|
-
"base_uri": "https://localhost:8080/"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"id": "SlEiX6B1SSsU",
|
|
45
|
-
"execution_count": 8,
|
|
46
|
-
"outputs": [
|
|
47
|
-
{
|
|
48
|
-
"output_type": "stream",
|
|
49
|
-
"name": "stdout",
|
|
50
|
-
"text": [
|
|
51
|
-
"Requirement already satisfied: iita_python in /usr/local/lib/python3.12/dist-packages (0.0.post42)\n",
|
|
52
|
-
"Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (from iita_python) (2.0.2)\n",
|
|
53
|
-
"Requirement already satisfied: pandas in /usr/local/lib/python3.12/dist-packages (from iita_python) (2.2.2)\n",
|
|
54
|
-
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas->iita_python) (2.9.0.post0)\n",
|
|
55
|
-
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas->iita_python) (2025.2)\n",
|
|
56
|
-
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas->iita_python) (2025.2)\n",
|
|
57
|
-
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas->iita_python) (1.17.0)\n",
|
|
58
|
-
"fatal: destination path '717f0147675b0c8ed25e50d583c943bf' already exists and is not an empty directory.\n"
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"cell_type": "markdown",
|
|
65
|
-
"source": [
|
|
66
|
-
"2. Testing function"
|
|
67
|
-
],
|
|
68
|
-
"metadata": {
|
|
69
|
-
"id": "jlvoh1yOata0"
|
|
70
|
-
},
|
|
71
|
-
"id": "jlvoh1yOata0"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"cell_type": "code",
|
|
75
|
-
"source": [
|
|
76
|
-
"def test(metric):\n",
|
|
77
|
-
" correct = True\n",
|
|
78
|
-
" correct_qo = None\n",
|
|
79
|
-
" correct_count = 0\n",
|
|
80
|
-
"\n",
|
|
81
|
-
" while (correct and correct_count < data.shape[0]*data.shape[1]):\n",
|
|
82
|
-
" print(f'doing {correct_count}')\n",
|
|
83
|
-
" test_dataset = iita.Dataset(data)\n",
|
|
84
|
-
" unfolded_ce = iita.unfold_examples(test_dataset.ce)\n",
|
|
85
|
-
" qos = iita.ind_gen(unfolded_ce, test_dataset.items)\n",
|
|
86
|
-
"\n",
|
|
87
|
-
" best_qo_id = -1\n",
|
|
88
|
-
" best_qo_diff = float('inf')\n",
|
|
89
|
-
" for i, qo in enumerate(qos):\n",
|
|
90
|
-
" qo_diff = metric(test_dataset, qo)\n",
|
|
91
|
-
" if (qo_diff < best_qo_diff):\n",
|
|
92
|
-
" best_qo_diff = qo_diff\n",
|
|
93
|
-
" best_qo_id = i\n",
|
|
94
|
-
"\n",
|
|
95
|
-
" best_qo = sorted([(int(a), int(b)) for a, b in qos[best_qo_id].get_edge_list()])\n",
|
|
96
|
-
" if (correct_qo is None):\n",
|
|
97
|
-
" correct_count += 1\n",
|
|
98
|
-
" correct_qo = best_qo\n",
|
|
99
|
-
" elif (best_qo != correct_qo):\n",
|
|
100
|
-
" correct = False\n",
|
|
101
|
-
" else:\n",
|
|
102
|
-
" correct_count += 1\n",
|
|
103
|
-
"\n",
|
|
104
|
-
" while (True):\n",
|
|
105
|
-
" a = randint(0, test_dataset.items - 1)\n",
|
|
106
|
-
" b = randint(0, test_dataset.subjects - 1)\n",
|
|
107
|
-
" if (not np.isnan(data[a][b])):\n",
|
|
108
|
-
" break;\n",
|
|
109
|
-
" data.loc[b, a] = np.nan\n",
|
|
110
|
-
"\n",
|
|
111
|
-
" return correct_count"
|
|
112
|
-
],
|
|
113
|
-
"metadata": {
|
|
114
|
-
"id": "ok9yLOnsTOU7"
|
|
115
|
-
},
|
|
116
|
-
"id": "ok9yLOnsTOU7",
|
|
117
|
-
"execution_count": 21,
|
|
118
|
-
"outputs": []
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
"cell_type": "code",
|
|
122
|
-
"source": [
|
|
123
|
-
"res = test(iita_fm.orig_iita_fit)"
|
|
124
|
-
],
|
|
125
|
-
"metadata": {
|
|
126
|
-
"id": "giLvbXdtX4uc"
|
|
127
|
-
},
|
|
128
|
-
"id": "giLvbXdtX4uc",
|
|
129
|
-
"execution_count": null,
|
|
130
|
-
"outputs": []
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
"cell_type": "code",
|
|
134
|
-
"source": [
|
|
135
|
-
"res"
|
|
136
|
-
],
|
|
137
|
-
"metadata": {
|
|
138
|
-
"id": "N2K347pebF9u",
|
|
139
|
-
"outputId": "b603f637-7b16-4161-eb18-4cf5ea12d989",
|
|
140
|
-
"colab": {
|
|
141
|
-
"base_uri": "https://localhost:8080/"
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
"id": "N2K347pebF9u",
|
|
145
|
-
"execution_count": 23,
|
|
146
|
-
"outputs": [
|
|
147
|
-
{
|
|
148
|
-
"output_type": "execute_result",
|
|
149
|
-
"data": {
|
|
150
|
-
"text/plain": [
|
|
151
|
-
"525"
|
|
152
|
-
]
|
|
153
|
-
},
|
|
154
|
-
"metadata": {},
|
|
155
|
-
"execution_count": 23
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
],
|
|
160
|
-
"metadata": {
|
|
161
|
-
"kernelspec": {
|
|
162
|
-
"display_name": "iita",
|
|
163
|
-
"language": "python",
|
|
164
|
-
"name": "python3"
|
|
165
|
-
},
|
|
166
|
-
"language_info": {
|
|
167
|
-
"name": "python",
|
|
168
|
-
"version": "3.12.11"
|
|
169
|
-
},
|
|
170
|
-
"colab": {
|
|
171
|
-
"provenance": []
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
"nbformat": 4,
|
|
175
|
-
"nbformat_minor": 5
|
|
176
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|