def setUp(self): # initialize the data n = 10000 self.alpha = 1.5 self.beta = -2.0 theta_vec = np.random.normal(loc=0.0, scale=1.0, size=n) y1 = [] y0 = [] for i in range(n): # generate the two parameter likelihood prob = tools.irt_fnc(theta_vec[i], self.beta, self.alpha) # generate the response sequence if prob >= np.random.uniform(): y1.append(1.0) y0.append(0.0) else: y1.append(0.0) y0.append(1.0) # the response format follows the solver API response_data = [y1, y0] # initialize optimizer self.solver = optimizer.irt_2PL_Optimizer() self.solver.load_res_data(response_data) self.solver.set_theta(theta_vec) self.solver.set_c(0)
def setUp(self): # initialize the data n = 1000 self.theta = 1.5 self.alpha_vec = np.random.random(n) + 1 self.beta_vec = np.random.normal(loc=0.0, scale=2.0, size=n) self.c_vec = np.zeros(n) y1 = [] y0 = [] for i in range(n): # generate the two parameter likelihood prob = tools.irt_fnc(self.theta, self.beta_vec[i], self.alpha_vec[i]) # generate the response sequence if prob >= np.random.uniform(): y1.append(1.0) y0.append(0.0) else: y1.append(0.0) y0.append(1.0) # the response format follows the solver API response_data = [y1, y0] # initialize optimizer self.solver = optimizer.irt_factor_optimizer() self.solver.load_res_data(response_data) self.solver.set_item_parameter(self.alpha_vec, self.beta_vec, self.c_vec) self.solver.set_bounds([(-6, 6)])
def test_irt_fnc(self): # make sure the shuffled sequence does not lose any elements prob = tools.irt_fnc(0.0, 0.0, 1.0) self.assertEqual(prob, 0.5) # alpha should play no role prob = tools.irt_fnc(0.0, 0.0, 2.0) self.assertEqual(prob, 0.5) # higher theta should have higher prob prob = tools.irt_fnc(1.0, 0.0, 1.0) self.assertEqual(prob, 1.0 / (1.0 + math.exp(-1.0))) # cancel out by higher beta prob = tools.irt_fnc(1.0, -1.0, 1.0) self.assertEqual(prob, 0.5) # test for c as limit situation prob = tools.irt_fnc(-99, 0.0, 1.0, 0.25) self.assertTrue(abs(prob - 0.25) < 1e-5) prob = tools.irt_fnc(99, 0.0, 1.0, 0.25) self.assertTrue(abs(prob - 1.0) < 1e-5)