Exemplo n.º 1
0
 def get_pc_vec(self):
     pc_vec = []
     conds = truthtable(len(self.parents) + len(self.children))
     for cond in conds:
         cond_p_prob = self.p_vec[bool_list_to_int(
             cond[:len(self.parents)])] if any(self.p_vec) else 1.
         cond_c_prob = self.c_vec[bool_list_to_int(
             cond[len(self.parents):])] if any(self.c_vec) else 1.
         print(self.p_vec, self.c_vec)
         print(cond, cond_p_prob, cond_c_prob)
         pc_vec.append(cond_p_prob * cond_c_prob)
     return pc_vec
Exemplo n.º 2
0
 def declare_c_probability(self, probability, cond):
     """
     Function of link value declaration
     Inputs :
     - probability : float that enphasizes the probability that the student knows self Skill knowing cond
     - cond : dict with the form {'skill_id of a parent': True or False, ...}
     """
     assert cond.keys() == [
         kc.id for kc in self.linked_knowledge_components
     ], "Error: some parents are lacking"
     index = bool_list_to_int(
         [cond[kc.id] for kc in self.linked_knowledge_components])
     self.probability_vector[index] = probability
Exemplo n.º 3
0
 def set_children_conditioned_probability_vector(self,
                                                 vec=None,
                                                 step_by_step=False):
     """
     Set the conditional probability vector of KnowledgeComponent given the mastering of its children.
     :param vec: the conditional probability vector knowing the states of children given by converting the index of
     the probability vector in binary (e.g. for B, C children of A, vec is 4 length : 1st index corresponds to
     B is False, C is False ; 3rd index is B True, C False)
     :param step_by_step: if the form of linked_knowledge_component is unknown, it is possible to set conditional
     probabilities value by value.
     :return: None, only changes the value of self.probability_vector
     """
     if not step_by_step:
         assert len(vec) == 2**len(self.linked_knowledge_components), "Length of the probability vector " \
                                                                      "should be 2^n."
         self.probability_vector = vec
     else:
         combinations = truthtable(len(self.linked_knowledge_components))
         for comb in combinations:
             self.probability_vector[bool_list_to_int(comb)] = input(
                 f"Probability  {self.knowledge_component.name} knowing "
                 f"{[child.name for child in self.linked_knowledge_components]} value {comb} is :"
             )