예제 #1
0
def __calculate_min_prob_rule_cell_probability(default_value, cell_probability: ProbabilityArrayCell,
                                               parent_cell_1_probability: ProbabilityArrayCell,
                                               parent_cell_2_probability: ProbabilityArrayCell,
                                               rule: sRule):
    if cell_probability == default_value:
        cell_probability = ProbabilityArrayCell()
        cell_probability.item_1 = min(min(rule.probability * parent_cell_1_probability.item_1),
                                      parent_cell_2_probability.item_1)

        cell_probability.item_2 = rule.probability * \
                                  parent_cell_1_probability.item_2 * \
                                  parent_cell_2_probability.item_2
    else:
        cell_probability.item_1 = max(cell_probability.item_1,
                                      min(min(rule.probability), parent_cell_1_probability.item_1,
                                          parent_cell_2_probability.item_1))
        cell_probability.item_2 = cell_probability.item_2 + rule.probability * \
                                                            parent_cell_1_probability.item_2 * \
                                                            parent_cell_2_probability.item_2
    return cell_probability
예제 #2
0
def __calculate_viterbi_rule_cell_probability(default_value, cell_probability: ProbabilityArrayCell,
                                              parent_cell_1_probability: ProbabilityArrayCell,
                                              parent_cell_2_probability: ProbabilityArrayCell,
                                              rule: sRule):
    if cell_probability == default_value:
        cell_probability = ProbabilityArrayCell()
        cell_probability.item_1 = math.log10(rule.probability) + \
                                  parent_cell_1_probability.item_1 * parent_cell_2_probability.item_1

        cell_probability.item_2 = (rule.probability *
                                   parent_cell_1_probability.item_2 *
                                   parent_cell_2_probability.item_2)

    else:
        cell_probability.item_1 = max(cell_probability.item_1, math.log10(parent_cell_1_probability.item_1 +
                                                                          parent_cell_2_probability.item_1))

        cell_probability.item_2 = cell_probability.item_2 + (rule.probability *
                                                             parent_cell_1_probability.item_2 *
                                                             parent_cell_2_probability.item_2)
    return cell_probability
예제 #3
0
def __calculate_baum_welch_rule_cell_probability(default_value, cell_probability: ProbabilityArrayCell,
                                                 parent_cell_1_probability: ProbabilityArrayCell,
                                                 parent_cell_2_probability: ProbabilityArrayCell,
                                                 rule: sRule) -> ProbabilityArrayCell:
    if cell_probability == default_value:
        cell_probability = ProbabilityArrayCell()
        cell_probability.item_1 = rule.probability * \
                                  parent_cell_1_probability.item_1 * \
                                  parent_cell_2_probability.item_1
        cell_probability.item_2 = rule.probability * \
                                  parent_cell_1_probability.item_2 * \
                                  parent_cell_2_probability.item_2
    else:
        cell_probability.item_1 = cell_probability.item_1 + \
                                  (rule.probability *
                                   parent_cell_1_probability.item_1 *
                                   parent_cell_2_probability.item_1)
        cell_probability.item_2 = cell_probability.item_2 + \
                                  (rule.probability *
                                   parent_cell_1_probability.item_2 *
                                   parent_cell_2_probability.item_2)
    return cell_probability