Skip to content

Commit

Permalink
Modified code specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Hhhhhhand authored and nnnyt committed Oct 27, 2023
1 parent 90f8fb8 commit af7d596
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
41 changes: 25 additions & 16 deletions CAT/model/IRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,24 @@ def get_fisher(self, student_id, question_id, pred_all):
q = 1 - pred
fisher_info = (q*pred*(alpha * alpha.T)).numpy()
return fisher_info
def IRT_derivate(self,pred_all):

new_predictions = {}
for sid, qid_dict in pred_all.items():
new_predictions[sid] = {}
for qid, pred in qid_dict.items():
new_pred = pred * (1 - pred)
new_predictions[sid][qid] = new_pred


def bce_loss_derivative(self,pred, target):
""" get bce_loss_derivative
Args:
pred: float,
target: int,
Returns:
the derivative of bce_loss
"""
derivative = (pred - target) / (pred * (1 - pred))
return derivative

def get_BE_weights(self, pred_all):
"""
""" get BE matrix
Args:
pred_all: dict, the questions you want to sample and their probability
Returns:
predictions, dict[sid][qid]
the BE matrix weights
"""
d = 100
Pre_true={}
Expand Down Expand Up @@ -329,24 +331,32 @@ def get_BE_weights(self, pred_all):
return w_ij_matrix

def F_s_func(self,S_set,w_ij_matrix):
""" get F_s of the questions have been chosen
Args:
S_set:list , the questions have been chosen
w_ij_matrix: dict, the weight matrix
Returns:
the F_s of the chosen questions
"""
res = 0.0
for w_i in w_ij_matrix:
if(w_i not in S_set):
mx = float('-inf')
for j in S_set:
if w_ij_matrix[w_i][j] > mx:
mx = w_ij_matrix[w_i][j]
res +=mx

res +=mx
return res

def delta_q_S_t(self, question_id, pred_all,S_set,sampled_elements):
""" get BECAT Questions weights delta
Args:
student_id: int, student id
question_id: int, question id
pred_all:dict, the untest questions and their probability
S_set:dict, chosen questions
sampled_elements:nparray, sampled set from untest questions
Returns:
v: float, Each weight information
delta_q: float, delta_q of questions id
"""

Sp_set = list(S_set)
Expand All @@ -364,7 +374,6 @@ def delta_q_S_t(self, question_id, pred_all,S_set,sampled_elements):
F_sp =self.F_s_func(Sp_set,w_ij_matrix)
return F_sp - F_s


def expected_model_change(self, sid: int, qid: int, adaptest_data: AdapTestDataset, pred_all: dict):
""" get expected model change
Args:
Expand Down
8 changes: 2 additions & 6 deletions CAT/strategy/BECAT_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@ class BECATstrategy(AbstractStrategy):

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

@property
def name(self):
return 'BECAT Strategy'

def adaptest_select(self, model: AbstractModel, adaptest_data: AdapTestDataset,S_set):
"""
submodular computation
"""
assert hasattr(model, 'delta_q_S_t'), \
'the models must implement delta_q_S_t method'
assert hasattr(model, 'get_pred'), \
'the models must implement get_pred method for accelerating'
pred_all = model.get_pred(adaptest_data)

#reduced_pred_all = {**reduced_pred_all, **selected_questions_sample}
selection = {}
for sid in range(adaptest_data.num_students):
tmplen = (len(S_set[sid]))
untested_questions = np.array(list(adaptest_data.untested[sid]))
sampled_elements = np.random.choice(untested_questions, tmplen + 5)
untested_deltaq = [model.delta_q_S_t(qid, pred_all[sid],S_set[sid],sampled_elements) for qid in untested_questions]

j = np.argmax(untested_deltaq)
selection[sid] = untested_questions[j]
# Question bank Q
Expand Down

0 comments on commit af7d596

Please sign in to comment.