Ejemplo n.º 1
0
    def apply_from_serde(join_tree):
        """
        Applies propagation to join tree from a deserialzed join tree.

        :param join_tree: Join tree.
        :return: Join tree (the same one passed in).
        """
        join_tree.listener = None
        join_tree.evidences = dict()

        PotentialInitializer.reinit(join_tree)
        Initializer.initialize(join_tree)
        Propagator.propagate(join_tree)

        join_tree.set_listener(InferenceController())

        return join_tree
Ejemplo n.º 2
0
    def reapply(join_tree, cpts):
        """
        Reapply propagation to join tree with new CPTs. The join tree structure is kept but the BBN node CPTs
        are updated. A new instance/copy of the join tree will be returned.

        :param join_tree: Join tree.
        :param cpts: Dictionary of new CPTs. Keys are id's of nodes and values are new CPTs.
        :return: Join tree.
        """
        jt = copy.deepcopy(join_tree)
        jt.update_bbn_cpts(cpts)
        jt.listener = None
        jt.evidences = dict()

        PotentialInitializer.reinit(jt)
        Initializer.initialize(jt)
        Propagator.propagate(jt)

        jt.set_listener(InferenceController())

        return jt