Skip to content

Commit

Permalink
add Dopt and MKLI strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnyt committed Mar 9, 2021
1 parent dcc4bc1 commit 52117ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CAT/model/IRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import torch.utils.data as data
from math import exp as exp
from sklearn.metrics import roc_auc_score
from scipy import integrate

from CAT.model.abstract_model import AbstractModel
from CAT.dataset import AdapTestDataset, TrainDataset, Dataset
Expand Down Expand Up @@ -217,6 +218,8 @@ def kli(x):
Args:
x: theta of student sid
"""
if type(x) == float:
x = np.array([x])
pred = np.matmul(alpha.T, x) + beta
pred = 1 / (1 + np.exp(-pred))
q_estimate = 1 - pred_estimate
Expand All @@ -225,6 +228,9 @@ def kli(x):
q_estimate * np.log((q_estimate / q))
c = 3
boundaries = [[theta[i] - c / np.sqrt(n), theta[i] + c / np.sqrt(n)] for i in range(dim)]
if len(boundaries) == 1:
v, err = integrate.quad(kli, boundaries[0][0], boundaries[0][1])
return v
integ = vegas.Integrator(boundaries)
result = integ(kli, nitn=10, neval=1000)
return result.mean
Expand Down
13 changes: 11 additions & 2 deletions CAT/strategy/KLI_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self):

@property
def name(self):
return 'KL Information Strategy'
return 'Kullback-Leibler Information Strategy'

def adaptest_select(self, model: AbstractModel, adaptest_data: AdapTestDataset):
assert hasattr(model, 'get_kli'), \
Expand All @@ -25,4 +25,13 @@ def adaptest_select(self, model: AbstractModel, adaptest_data: AdapTestDataset):
untested_kli = [model.get_kli(sid, qid, n) for qid in untested_questions]
j = np.argmax(untested_kli)
selection[sid] = untested_questions[j]
return selection
return selection

class MKLIStrategy(KLIStrategy):

def __init__(self):
super().__init__()

@property
def name(self):
return 'Multivariate Kullback-Leibler Information Strategy'
10 changes: 9 additions & 1 deletion CAT/strategy/MFI_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ def adaptest_select(self, model: AbstractModel, adaptest_data: AdapTestDataset):
j = np.argmax(untested_dets)
selection[sid] = untested_questions[j]
self.I[sid] += untested_fisher[j]
return selection
return selection

class DoptStrategy(MFIStrategy):
def __init__(self):
super().__init__()

@property
def name(self):
return 'D-Optimality Strategy'
2 changes: 2 additions & 0 deletions CAT/strategy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .abstract_strategy import AbstractStrategy
from .random_strategy import RandomStrategy
from .MFI_strategy import MFIStrategy
from .MFI_strategy import DoptStrategy
from .KLI_strategy import KLIStrategy
from .KLI_strategy import MKLIStrategy
from .MAAT_strategy import MAATStrategy

0 comments on commit 52117ef

Please sign in to comment.