def gen_items(space, covariate): # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) # Create the items for i in range(N_ITEMS): # First we create an IRT model container for our item # We have to specify which dimensions to be used with the "dims" array # (in this case, we use both of the dimensions of the space) model = gobject.new(oscats.ModelL2p, space=space, dims=dims, covariates=covariate) # Then, set the parameters. Here there are 4: # Discrimination on two dimensions, difficulty, and covariate coef. model.set_param_by_name("Diff", oscats.oscats_rnd_normal(sqrt(3))) model.set_param_by_name("Discr.Cont.1", oscats.oscats_rnd_uniform_range(0, 1)) model.set_param_by_name("Discr.Cont.2", oscats.oscats_rnd_uniform_range(0, 2)) model.set_param_by_name(COVARIATE_NAME, oscats.oscats_rnd_uniform_range(0.5, 1.5)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def gen_items(space, covariate) : # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) # Create the items for i in range(N_ITEMS) : # First we create an IRT model container for our item # We have to specify which dimensions to be used with the "dims" array # (in this case, we use both of the dimensions of the space) model = gobject.new(oscats.ModelL2p, space=space, dims=dims, covariates=covariate) # Then, set the parameters. Here there are 4: # Discrimination on two dimensions, difficulty, and covariate coef. model.set_param_by_name("Diff", oscats.oscats_rnd_normal(sqrt(3))) model.set_param_by_name("Discr.Cont.1", oscats.oscats_rnd_uniform_range(0, 1)) model.set_param_by_name("Discr.Cont.2", oscats.oscats_rnd_uniform_range(0, 2)) model.set_param_by_name(COVARIATE_NAME, oscats.oscats_rnd_uniform_range(0.5, 1.5)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def gen_examinees(space): dim = space.get_dim_by_name("Cont.1") ret = [] for i in range(N_EXAMINEES): theta = oscats.Point(space=space) theta.set_cont(dim, oscats.oscats_rnd_normal(1)) e = oscats.Examinee() e.set_sim_theta(theta) ret.append(e) return ret
def gen_examinees(space) : dim = space.get_dim_by_name("Cont.1") ret = [] for i in range(N_EXAMINEES) : # Latent IRT ability parameter. This is a one-dimensional test. theta = oscats.Point(space=space) # Sample the ability from N(0,1) distribution theta.set_cont(dim, oscats.oscats_rnd_normal(1)) # Create a new examinee e = gobject.new(oscats.Examinee) # Set the examinee's true (simulated) ability e.set_sim_theta(theta) ret.append(e) return ret
def gen_examinees(space): dim = space.get_dim_by_name("Cont.1") ret = [] for i in range(N_EXAMINEES): # Latent IRT ability parameter. This is a one-dimensional test. theta = oscats.Point(space=space) # Sample the ability from N(0,1) distribution theta.set_cont(dim, oscats.oscats_rnd_normal(1)) # Create a new examinee e = gobject.new(oscats.Examinee) # Set the examinee's true (simulated) ability e.set_sim_theta(theta) ret.append(e) return ret
def gen_items(space) : # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) for i in range(N_ITEMS) : # First we create an IRT model container for our item # Defaults to unidimensional, using the first dimension of space model = gobject.new(oscats.ModelL1p, space=space) # Then, set the parameters. Here there is only one, the difficulty (b). model.set_param_by_index(0, oscats.oscats_rnd_normal(1)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def gen_items(space): # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) for i in range(N_ITEMS): # First we create an IRT model container for our item # Defaults to unidimensional, using the first dimension of space model = gobject.new(oscats.ModelL1p, space=space) # Then, set the parameters. Here there is only one, the difficulty (b). model.set_param_by_index(0, oscats.oscats_rnd_normal(1)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
"\t".join([ "%s.theta\t%s.alpha" for name in test_names]) + "\n") for e in examinees : tmp = e.get_theta_by_name("trueTheta") dim = contSpace.get_dim_by_name("Cont.1") out.write("%s\t%g\t" % (e.get_property("id"), tmp.get_cont(dim))) tmp = e.get_theta_by_name("trueAlpha") dim = binSpace.get_dim_by_name("Bin.1") for k in range(N_ATTR) : if tmp.get_bin(dim) : out.write("1") else : out.write("0") dim += 1 # Choose initial theta and alpha for this examinee # We'll use the same initial abilities for all four tests dim = contSpace.get_dim_by_name("Cont.1") initTheta.set_cont(dim, oscats.oscats_rnd_normal(sqrt(0.05))-0.37) dim = binSpace.get_dim_by_name("Bin.1") for k in range(N_ATTR) : initAlpha.set_bin(dim, oscats.oscats_rnd_uniform() < 0.5) ; dim += 1 # Initialize ability estimates for this examinee e.set_theta_by_name("estTheta", oscats.Point(space=contSpace)) e.set_theta_by_name("estAlpha", oscats.Point(space=binSpace)) for test in tests : # Reset initial latent ability for this test e.get_theta_by_name("estTheta").copy(initTheta) e.get_theta_by_name("estAlpha").copy(initAlpha) # Do the administration! test.administer(e)
# Here, we'll just use one object over again for each administration. e = oscats.Examinee(covariates=covariate) sim_theta = oscats.Point(space=space) est_theta = oscats.Point(space=space) e.set_sim_theta(sim_theta) e.set_est_theta(est_theta) print "Administering." for I in range(len(grid)) : sim_theta.set_cont(dims[0], grid[I]) for J in range(len(grid)) : stdout.write("\rAt grid point (%g, %g) ...\n" % (grid[I], grid[J])) sim_theta.set_cont(dims[1], grid[J]) for i in range(N_EXAMINEES) : # "covariate" is the same OscatsCovariates object used by "e" covariate.set_by_name(COVARIATE_NAME, oscats.oscats_rnd_normal(1)) stdout.write("\r%d" % i) ; stdout.flush() for j in range(len(tests)) : # Reset initial theta: Random start ~ N_2(0, I_2) est_theta.set_cont(dims[0], oscats.oscats_rnd_normal(1)) est_theta.set_cont(dims[1], oscats.oscats_rnd_normal(1)) # Administer the test tests[j].administer(e) # Calculate error (Euclidean distance between sim/est theta) err_sums[j][I*len(grid)+J] += distance(sim_theta, est_theta); # Report results out = open("ex02-results.txt", "w") out.write("D1\tD2\t" + "\t".join(test_names) + "\n") for I in range(len(grid)) : for J in range(len(grid)) :
# Here, we'll just use one object over again for each administration. e = oscats.Examinee(covariates=covariate) sim_theta = oscats.Point(space=space) est_theta = oscats.Point(space=space) e.set_sim_theta(sim_theta) e.set_est_theta(est_theta) print "Administering." for I in range(len(grid)): sim_theta.set_cont(dims[0], grid[I]) for J in range(len(grid)): stdout.write("\rAt grid point (%g, %g) ...\n" % (grid[I], grid[J])) sim_theta.set_cont(dims[1], grid[J]) for i in range(N_EXAMINEES): # "covariate" is the same OscatsCovariates object used by "e" covariate.set_by_name(COVARIATE_NAME, oscats.oscats_rnd_normal(1)) stdout.write("\r%d" % i) stdout.flush() for j in range(len(tests)): # Reset initial theta: Random start ~ N_2(0, I_2) est_theta.set_cont(dims[0], oscats.oscats_rnd_normal(1)) est_theta.set_cont(dims[1], oscats.oscats_rnd_normal(1)) # Administer the test tests[j].administer(e) # Calculate error (Euclidean distance between sim/est theta) err_sums[j][I * len(grid) + J] += distance( sim_theta, est_theta) # Report results out = open("ex02-results.txt", "w") out.write("D1\tD2\t" + "\t".join(test_names) + "\n")
"\t".join(["%s.theta\t%s.alpha" for name in test_names]) + "\n") for e in examinees: tmp = e.get_theta_by_name("trueTheta") dim = contSpace.get_dim_by_name("Cont.1") out.write("%s\t%g\t" % (e.get_property("id"), tmp.get_cont(dim))) tmp = e.get_theta_by_name("trueAlpha") dim = binSpace.get_dim_by_name("Bin.1") for k in range(N_ATTR): if tmp.get_bin(dim): out.write("1") else: out.write("0") dim += 1 # Choose initial theta and alpha for this examinee # We'll use the same initial abilities for all four tests dim = contSpace.get_dim_by_name("Cont.1") initTheta.set_cont(dim, oscats.oscats_rnd_normal(sqrt(0.05)) - 0.37) dim = binSpace.get_dim_by_name("Bin.1") for k in range(N_ATTR): initAlpha.set_bin(dim, oscats.oscats_rnd_uniform() < 0.5) dim += 1 # Initialize ability estimates for this examinee e.set_theta_by_name("estTheta", oscats.Point(space=contSpace)) e.set_theta_by_name("estAlpha", oscats.Point(space=binSpace)) for test in tests: # Reset initial latent ability for this test e.get_theta_by_name("estTheta").copy(initTheta) e.get_theta_by_name("estAlpha").copy(initAlpha)