# mixed.py: generate mixed sets of test data # Robyn A. McNamara November 2002 from random import * N = 4 # number of competencies population = 400 # student population K=3 # factors per question students = [] questions = [] def vmult(v, w): if len(v) != len(w): print "Error: vectors of different lengths" print "v =", v,"; w =", w return p = 0.0 # accumulates vector product for i in range(len(v)): p = p + float(v[i]) * float(w[i]) return p # generate student vectors for i in range(population): s = [] for j in range(N): p = gauss(0.5, 0.25) + 0.25 p = min(max(p,0),1) s.append(p) students.append(s) # generate question vectors for i in range(80): q = [0.0] * N for j in range(K): factor = randrange(N) q[factor] = q[factor] + 1.0 for j in range(N): q[j] = q[j] / float(K) questions.append(q) # work out student marks for s in students: for q in questions: p = vmult(s, q) mark = 0 for m in range(10): if random() > p: mark = mark + 1 print "%d\t" % mark, print print "=" * 75 for i in range(len(questions)): print "Q[%d] = " % i, questions[i]