def get_state_machine(): """Gets state transition probabilities for items.""" user_stats = get_global_rater_stats() state_transitions = ConditionalFreqDist() for user_data in user_stats: state_transitions.add_counts(user_data['state_machine']) return state_transitions
def __init__(self): ConditionalFreqDist.__init__(self) kanji_script = scripts.Script.Kanji i_stream = sopen(_edict_aligned_file, 'r') for line in i_stream: alignment = Alignment.from_line(line) for (g, p) in alignment: if scripts.contains_script(kanji_script, g): self[g].inc(scripts.to_hiragana(p)) i_stream.close() return
def __init__(self): # Loads up the frequency distribution for P(r*|k). self.normalized_freq_dist = ConditionalFreqDist.from_file( _reading_counts_file) # Load up the alternation probabilities P(r|r*). self.alternation_dist = self._load_alternation_dist( _reading_counts_map_file) # Build a mapping from (k, r) to r*. self.from_canonical_reading = self._build_alternation_map() # Build a frequency distribution for P(r|k). self.raw_freq_dist = raw_reading_model.RawReadingModel() self.reverse_mapping = self.get_reverse_mapping() return
def _calculated_item_change(response_data): """ Calculates how many items were forgotten and how many were learned. """ fs = ConditionalFreqDist() response_data = [(pid, pt, i, ic) for (i, (pid, pt, ic)) in enumerate(response_data)] response_data.sort() for (pivot_id, pivot_type), responses in groupby(response_data, lambda r: (r[0], r[1])): responses = list(responses) if len(responses) < 2: continue for i in xrange(len(responses) - 1): from_state = responses[i][-1] and 'k' or 'u' to_state = responses[i + 1][-1] and 'k' or 'u' fs[from_state].inc(to_state) return fs