-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptSimus.py
More file actions
105 lines (90 loc) · 4.33 KB
/
Copy pathscriptSimus.py
File metadata and controls
105 lines (90 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import numpy as np
import matplotlib.pyplot as plt
#########################################
# #
# Simulations and Distances computation #
# #
#########################################
def mainSimulation(params):
(nbQuestionsPerStudent,nbStudents,nbStudentsPerGroup)=params
nbQuestions = np.arange(nbQuestionsPerStudent+1,nbStudents*nbQuestionsPerStudent,5)
meanPWDistances=np.zeros((len(nbQuestions),))
minmaxPWDistances=np.zeros((len(nbQuestions),2))
meanDistances=np.zeros((len(nbQuestions),))
minmaxDistances=np.zeros((len(nbQuestions),2))
cpt=0
for n in nbQuestions:
# Generate nbQuestions random partitions of the set {0,n}
randperm = np.zeros((nbQuestionsPerStudent,nbStudentsPerGroup))
for i in range(nbStudentsPerGroup):
randperm[:,i]=np.random.permutation(n)[0:nbQuestionsPerStudent]
# Compute all pairwise distances between partitions (edit distance)
distance=[]
unionOfIntersect=[]
for i in range(nbStudentsPerGroup):
for j in range(nbStudentsPerGroup):
if i<j:
unionOfIntersect.append(np.intersect1d(randperm[:,i],randperm[:,j]))
dist=len(np.intersect1d(randperm[:,i],randperm[:,j]))
distance.append(dist)
meanPWDistances[cpt]=np.mean(np.array(distance))
minmaxPWDistances[cpt,0]=np.min(np.array(distance))
minmaxPWDistances[cpt,1]=np.max(np.array(distance))
# Union of all questions => diff between individual questions and union
union=np.unique(randperm.flatten())
distance=[]
unionOfIntersect=np.unique(np.concatenate(unionOfIntersect))
for i in range(nbStudentsPerGroup):
dist=len(np.setdiff1d(randperm[:,i],unionOfIntersect))
distance.append(dist)
meanDistances[cpt]=np.mean(np.array(distance))
minmaxDistances[cpt,0]=np.min(np.array(distance))
minmaxDistances[cpt,1]=np.max(np.array(distance))
cpt=cpt+1
return (meanPWDistances,minmaxPWDistances,meanDistances,minmaxDistances,nbQuestions)
#################
# #
# Visualization #
# #
#################
def vizu(nbQuestions,meanPWDistances,minmaxPWDistances,meanDistances,minmaxDistances,params):
(nbQuestionsPerStudent,nbStudents,nbStudentsPerGroup)=params
plt.figure(figsize=(12,8))
plt.semilogx(nbQuestions,meanPWDistances,'k-')
plt.fill_between(nbQuestions,minmaxPWDistances[:,0],minmaxPWDistances[:,1])
plt.xlabel('Number of all the questions required for the exam')
plt.ylabel('Questions')
plt.legend(['Average','Min-Max for '+str(nbStudentsPerGroup)+' students per group'])
plt.title('Shared questions between two exam subjects with ' + str(nbQuestionsPerStudent) + ' questions')
plt.savefig("Figure1.png")
plt.show()
plt.figure(figsize=(12,8))
plt.semilogx(nbQuestions,nbQuestionsPerStudent-meanDistances,'k-')
plt.fill_between(nbQuestions,nbQuestionsPerStudent-minmaxDistances[:,0],nbQuestionsPerStudent-minmaxDistances[:,1])
plt.xlabel('Number of all the questions required for the exam')
plt.ylabel('Questions' )
plt.legend(['Average','Min-Max for '+str(nbStudentsPerGroup)+' students per group'])
plt.title('Questions among ' + str(nbQuestionsPerStudent) + ' shared in a group of '+str(nbStudentsPerGroup)+' students')
plt.savefig("Figure2.png")
plt.show()
plt.figure(figsize=(12,8))
plt.semilogx(nbQuestions,meanPWDistances,'r-')
plt.semilogx(nbQuestions,nbQuestionsPerStudent-meanDistances,'b-')
plt.legend(['Shared questions between two exam subjects','Questions shared in a group of '+str(nbStudentsPerGroup)+' students'])
plt.savefig("Figure3.png")
plt.show()
########
# #
# Main #
# #
########
if __name__ == '__main__':
print('Number of students: \n')
nbStudents=input()
print('\n Number of questions: \n')
nbQuestionsPerStudent=input()
print('\n Number of students per group')
nbStudentsPerGroup=input()
params=(int(nbQuestionsPerStudent),int(nbStudents),int(nbStudentsPerGroup))
(meanPWDistances,minmaxPWDistances,meanDistances,minmaxDistances,nbQuestions)=mainSimulation(params)
vizu(nbQuestions,meanPWDistances,minmaxPWDistances,meanDistances,minmaxDistances,params)