module special.student
#
Short summary#
module ensae_teaching_cs.special.student
Classes#
class |
truncated documentation |
---|---|
Class Student, it has: |
Static Methods#
staticmethod |
truncated documentation |
---|---|
Returns a student with random answers. |
Methods#
method |
truncated documentation |
---|---|
usual |
|
Returns a dictionary { (“q1”, “q2”): { (True, False): 1 } }. That means the student was True at question q1 and … |
|
Returns a names, mat. |
|
Returns a names, vect. |
Documentation#
- class ensae_teaching_cs.special.student.Student(qna)#
Bases :
object
Class Student, it has:
qna: dictionary {question: answer}
answer is a float in [0, 1], 0 means the student failed to answer, 1 means the student is right, in ]0, 1[, we don’t know for sure. (We are human!)
<<<
from ensae_teaching_cs.special.student import Student st = Student({'q1': 0.6, 'q2': 0.7, 'q3': 0.1}) print(st)
>>>
Student({'q1': 0.6, 'q2': 0.7, 'q3': 0.1})
- __init__(qna)#
- __repr__()#
usual
- count_anwers(threshold=0.5, counter=None)#
Returns a dictionary { (“q1”, “q2”): { (True, False): 1 } }. That means the student was True at question q1 and False at question q2. If counter is not None, this dictionary is added to the same dictionary computed with an other students.
{ (“q1”, “q2”): { (True, False): 1, (False, False): 2 } }
This means there were 3 students, 1 was right at q1 and wrong at q2, 2 were wrong at both questions.
- Paramètres:
threshold – threshold above which the answer is valid
counter – existing counter, added to these counts
- Renvoie:
new or updated counter
<<<
from ensae_teaching_cs.special.student import Student from pprint import pprint st1 = Student({'q1': 0.6, 'q2': 0.7, 'q3': 0.1}) st2 = Student({'q1': 0.6, 'q2': 0.2, 'q3': 0.1}) mat = st1.count_anwers() pprint(mat)
>>>
{('q1', 'q2'): {(True, True): 1}, ('q1', 'q3'): {(True, False): 1}, ('q2', 'q1'): {(True, True): 1}, ('q2', 'q3'): {(True, False): 1}, ('q3', 'q1'): {(False, True): 1}, ('q3', 'q2'): {(False, True): 1}}
- count_anwers_matrix(threshold=0.5, counter=None, names=None)#
Returns a names, mat.
names is dictionary {“q1”: row_index}
- mat is a matrix:
mat[0, q1_index, q2_index] is the number of times students were right at questions q1, q2
mat[1, q1_index, q2_index] is the number of times students were right at question q1 and wrong at question q2
mat[2, q1_index, q2_index] is the number of times students were wrong at question q1 and right at question q2
mat[3, q1_index, q2_index] is the number of times students were wring at both questions
- Paramètres:
threshold – threshold above which the answer is valid
counter – existing counter, added to these counts
names – mapping between rows and questions
- Renvoie:
names or names, new or updated counter
<<<
from ensae_teaching_cs.special.student import Student st1 = Student({'q1': 0.6, 'q2': 0.7, 'q3': 0.1}) st2 = Student({'q1': 0.6, 'q2': 0.2, 'q3': 0.1}) names, mat = st1.count_anwers_matrix() print(names) print(mat)
>>>
{'q1': 0, 'q2': 1, 'q3': 2} [[[1. 1. 0.] [1. 1. 0.] [0. 0. 0.]] [[0. 0. 1.] [0. 0. 1.] [0. 0. 0.]] [[0. 0. 0.] [0. 0. 0.] [1. 1. 0.]] [[0. 0. 0.] [0. 0. 0.] [0. 0. 1.]]]
The following code compares this method to the previous one.
<<<
from pyinstrument import Profiler from ensae_teaching_cs.special.student import Student students = [Student.random_student(80) for i in range(50)] profiler = Profiler() profiler.start() for n in range(10): mat2 = {} for st in students: st.count_anwers(counter=mat2) for n in range(10): mat3 = None names = None for st in students: names, mat3 = st.count_anwers_matrix(counter=mat3, names=names) profiler.stop() print(profiler.output_text())
>>>
_ ._ __/__ _ _ _ _ _/_ Recorded: 08:47:13 AM Samples: 12858 /_//_/// /_\ / //_// / //_'/ // Duration: 15.209 CPU time: 15.185 / _/ v4.3.0 Program: somewhere/workspace/ensae_teaching_cs/ensae_teaching_cs_UT_39_std/_venv/lib/python3.9/site-packages/pyquickhelper/helpgen/process_sphinx_cmd.py -j1 -v -T -b html -d build/doctrees source build/html 15.208 run_python_script_139849710068032 None:1 |- 14.586 count_anwers ensae_teaching_cs/special/student.py:37 | [4 frames hidden] ensae_teaching_cs, .. | 14.411 [self] `- 0.548 count_anwers_matrix ensae_teaching_cs/special/student.py:124 [5 frames hidden] ensae_teaching_cs, ..
- static random_student(n=100)#
Returns a student with random answers.
- Paramètres:
n – number of questions
- Renvoie:
Student
- to_matrix(names=None)#
Returns a names, vect.
names is dictionary {“q1”: row_index}
vect is a vector: mat[row_index] is the answer to question q1
- Paramètres:
names – mapping between rows and questions
- Renvoie:
names or names, new or updated counter
<<<
from ensae_teaching_cs.special.student import Student st = Student({'q1': 0.6, 'q2': 0.7, 'q3': 0.1}) names, mat = st.to_matrix() print(names) print(mat)
>>>
{'q1': 0, 'q2': 1, 'q3': 2} [0.6 0.7 0.1]