From 52117ef237d61c143a19bfbd80cf4bc84338309e Mon Sep 17 00:00:00 2001 From: nnnyt <793313994@qq.com> Date: Tue, 9 Mar 2021 14:33:21 +0800 Subject: [PATCH] add Dopt and MKLI strategy --- CAT/model/IRT.py | 6 ++++++ CAT/strategy/KLI_strategy.py | 13 +++++++++++-- CAT/strategy/MFI_strategy.py | 10 +++++++++- CAT/strategy/__init__.py | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CAT/model/IRT.py b/CAT/model/IRT.py index 0018371..d2120e7 100644 --- a/CAT/model/IRT.py +++ b/CAT/model/IRT.py @@ -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 @@ -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 @@ -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 diff --git a/CAT/strategy/KLI_strategy.py b/CAT/strategy/KLI_strategy.py index 0a4d1b6..b379b7b 100644 --- a/CAT/strategy/KLI_strategy.py +++ b/CAT/strategy/KLI_strategy.py @@ -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'), \ @@ -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 \ No newline at end of file + return selection + +class MKLIStrategy(KLIStrategy): + + def __init__(self): + super().__init__() + + @property + def name(self): + return 'Multivariate Kullback-Leibler Information Strategy' \ No newline at end of file diff --git a/CAT/strategy/MFI_strategy.py b/CAT/strategy/MFI_strategy.py index 4af35dc..88f34ca 100644 --- a/CAT/strategy/MFI_strategy.py +++ b/CAT/strategy/MFI_strategy.py @@ -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 \ No newline at end of file + return selection + +class DoptStrategy(MFIStrategy): + def __init__(self): + super().__init__() + + @property + def name(self): + return 'D-Optimality Strategy' \ No newline at end of file diff --git a/CAT/strategy/__init__.py b/CAT/strategy/__init__.py index 3eeb5a2..e9ee9e3 100644 --- a/CAT/strategy/__init__.py +++ b/CAT/strategy/__init__.py @@ -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 \ No newline at end of file