-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
78 lines (59 loc) · 2.13 KB
/
Copy pathmodels.py
File metadata and controls
78 lines (59 loc) · 2.13 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
"""Overall background for the simulation:
Classes for representing items, students, simulation scenarios.
Functions for generating simulated answers."""
import math
import random
import numpy as np
from dataclasses import dataclass
def logistic(x):
return 1 / (1 + math.exp(-x))
def get_logistic_answer(skill, difficulty):
prob = logistic(skill - difficulty)
return int(random.random() < prob)
def get_answer_sequences(scenario, skill, count, limit):
items = Items(scenario)
answer_seqs = []
for _ in range(count):
items.shuffle()
answer_seqs.append(
Student(skill, scenario.student_learnrate).
get_answer_sequence(items, limit)
)
return answer_seqs
class Student:
def __init__(self, init_skill, learning_rate=0):
self.init_skill = init_skill
self.skill = init_skill
self.learning_rate = learning_rate
def __str__(self):
return f"Student {self.init_skill:.2f}, {self.learning_rate:.3f}"
def get_answer(self, items, i):
prob = items.get_answer_prob(i, self.skill)
self.skill += self.learning_rate
return int(random.random() < prob)
def get_answer_sequence(self, items, length=100):
return [self.get_answer(items, i) for i in range(length)]
class Items:
def __init__(self, scenario):
self.size = scenario.items_count
self.difficulties = list(np.random.normal(loc=scenario.difficulty_mean,
scale=scenario.difficulty_std,
size=self.size))
self.guess_chance = scenario.guess_chance
def shuffle(self):
random.shuffle(self.difficulties)
def get_answer_prob(self, i, skill):
return self.guess_chance + \
(1 - self.guess_chance) * \
logistic(skill - self.difficulties[i % self.size])
@dataclass
class Scenario:
name: str
desc: str
guess_chance: float
time_intensity: float
difficulty_mean: float = 0
difficulty_std: float = 1
student_std: float = 1
student_learnrate: float = 0
items_count: int = 300