def test_dep_empirical_distrib_continuous(self):
        bn = BNetwork()
        builder = CategoricalTableBuilder("var1")
        builder.add_row(ValueFactory.create("one"), 0.7)
        builder.add_row(ValueFactory.create("two"), 0.3)
        var1 = ChanceNode("var1", builder.build())
        bn.add_node(var1)

        continuous = ContinuousDistribution("var2",
                                            UniformDensityFunction(-1.0, 3.0))
        continuous2 = ContinuousDistribution(
            "var2", GaussianDensityFunction(3.0, 10.0))

        table = ConditionalTable("var2")
        table.add_distrib(Assignment("var1", "one"), continuous)
        table.add_distrib(Assignment("var1", "two"), continuous2)
        var2 = ChanceNode("var2", table)
        var2.add_input_node(var1)
        bn.add_node(var2)

        inference = InferenceChecks()
        inference.check_cdf(bn, "var2", -1.5, 0.021)
        inference.check_cdf(bn, "var2", 0., 0.22)
        inference.check_cdf(bn, "var2", 2., 0.632)
        inference.check_cdf(bn, "var2", 8., 0.98)
class TestDialogueState:
    domain_file = "test/data/domain1.xml"

    domain = XMLDomainReader.extract_domain(domain_file)
    inference = InferenceChecks()

    def test_state_copy(self):
        system = DialogueSystem(TestDialogueState.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False

        system.get_settings().show_gui = False
        system.start_system()

        initial_state = copy(system.get_state())

        rule_id = ""
        for id in system.get_state().get_node("u_u2").get_output_node_ids():
            if str(system.get_content(id)).find("+=HowAreYou") != -1:
                rule_id = id

        TestDialogueState.inference.check_prob(
            initial_state, rule_id, Effect.parse_effect("a_u2+=HowAreYou"),
            0.9)
        TestDialogueState.inference.check_prob(initial_state, rule_id,
                                               Effect.parse_effect("Void"),
                                               0.1)

        TestDialogueState.inference.check_prob(initial_state, "a_u2",
                                               "[HowAreYou]", 0.2)
        TestDialogueState.inference.check_prob(initial_state, "a_u2",
                                               "[Greet, HowAreYou]", 0.7)
        TestDialogueState.inference.check_prob(initial_state, "a_u2", "[]",
                                               0.1)

        StatePruner.enable_reduction = True

    def test_state_copy2(self):
        InferenceChecks.exact_threshold = 0.08

        system = DialogueSystem(TestDialogueState.domain)
        system.get_settings().show_gui = False
        system.detach_module(ForwardPlanner)
        system.start_system()

        initial_state = copy(system.get_state())

        TestDialogueState.inference.check_prob(initial_state, "a_u2",
                                               "[HowAreYou]", 0.2)
        TestDialogueState.inference.check_prob(initial_state, "a_u2",
                                               "[Greet, HowAreYou]", 0.7)
        TestDialogueState.inference.check_prob(initial_state, "a_u2", "[]",
                                               0.1)
Beispiel #3
0
    def test_1(self):
        domain = XMLDomainReader.extract_domain(TestRule3.test1_domain_file)
        inference = InferenceChecks()
        inference.exact_threshold = 0.06
        system = DialogueSystem(domain)
        system.get_settings().show_gui = False
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.start_system()

        inference.check_prob(system.get_state(), "found", "A", 0.7)

        inference.check_prob(system.get_state(), "found2", "D", 0.3)
        inference.check_prob(system.get_state(), "found2", "C", 0.5)

        StatePruner.enable_reduction = True
Beispiel #4
0
    def test_2(self):
        inference = InferenceChecks()

        domain = XMLDomainReader.extract_domain(TestRule3.test2_domain_file)
        system = DialogueSystem(domain)
        system.get_settings().show_gui = False

        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.start_system()

        inference.check_prob(system.get_state(), "graspable(obj1)", "True", 0.81)

        inference.check_prob(system.get_state(), "graspable(obj2)", "True", 0.16)
        inference.check_util(system.get_state(), "a_m'", "grasp(obj1)", 0.592)

        StatePruner.enable_reduction = True
    def test_network(self):
        inference = InferenceChecks()
        inference.include_naive(True)

        bn = NetworkExamples.construct_basic_network2()

        query_vars_powerset = self.generate_powerset(bn.get_chance_node_ids())
        evidence_powerset = self.generate_evidence_powerset(bn)

        nb_errors = 0

        for query_vars in query_vars_powerset:
            if len(query_vars) != 0:
                for evidence in evidence_powerset:
                    if Random().random(
                    ) < TestInferenceLargeScale.percent_comparisions / 100.0:
                        try:
                            inference.check_prob(bn, query_vars, evidence)
                        except:
                            nb_errors += 1
                            if nb_errors > 2:
                                assert False, "more than 2 sampling errors"

        inference.show_performance()
Beispiel #6
0
class TestPlanning:
    domain_file = "test/data/domain3.xml"
    domain_file2 = "test/data/basicplanning.xml"
    domain_file3 = "test/data/planning2.xml"
    settings_file = "test/data/settings_test2.xml"

    inference = InferenceChecks()
    domain = XMLDomainReader.extract_domain(domain_file)
    domain2 = XMLDomainReader.extract_domain(domain_file2)
    domain3 = XMLDomainReader.extract_domain(domain_file3)

    def test_planning(self):
        system = DialogueSystem(TestPlanning.domain)

        system.get_settings().show_gui = False

        system.start_system()
        assert len(system.get_state().get_nodes()) == 3
        assert len(system.get_state().get_chance_nodes()) == 3
        assert len(system.get_state().get_evidence().get_variables()) == 0
        TestPlanning.inference.check_prob(system.get_state(), "a_m3", "Do",
                                          1.0)
        TestPlanning.inference.check_prob(system.get_state(), "obj(a_m3)", "A",
                                          1.0)

    def test_planning2(self):
        system = DialogueSystem(TestPlanning.domain2)

        system.get_settings().show_gui = False

        system.start_system()
        assert len(system.get_state().get_node_ids()) == 2
        assert not system.get_state().has_chance_node("a_m")

    def test_planning3(self):
        system = DialogueSystem(TestPlanning.domain2)

        system.get_settings().show_gui = False

        system.get_settings().horizon = 2
        system.start_system()
        TestPlanning.inference.check_prob(system.get_state(), "a_m",
                                          "AskRepeat", 1.0)

    def test_planning4(self):
        system = DialogueSystem(TestPlanning.domain3)

        system.get_settings().show_gui = False

        system.get_settings().horizon = 3
        system.start_system()

        t1 = CategoricalTableBuilder("a_u")
        t1.add_row("Ask(Coffee)", 0.95)
        t1.add_row("Ask(Tea)", 0.02)
        system.add_content(t1.build())
        TestPlanning.inference.check_prob(system.get_state(), "a_m",
                                          "Do(Coffee)", 1.0)

    def test_planning5(self):
        system = DialogueSystem(TestPlanning.domain3)

        system.get_settings().show_gui = False

        system.get_settings().horizon = 3
        system.start_system()

        t1 = CategoricalTableBuilder("a_u")
        t1.add_row("Ask(Coffee)", 0.3)
        t1.add_row("Ask(Tea)", 0.3)
        system.add_content(t1.build())

        TestPlanning.inference.check_prob(system.get_state(), "a_m",
                                          "AskRepeat", 1.0)
Beispiel #7
0
class TestPruning:
    domainFile = "test/data/domain1.xml"

    domain = XMLDomainReader.extract_domain(domainFile)
    inference = InferenceChecks()
    InferenceChecks.exact_threshold = 0.1
    InferenceChecks.sampling_threshold = 0.1
    system = DialogueSystem(domain)
    system.get_settings().show_gui = False

    system.start_system()

    def test_pruning0(self):
        assert len(TestPruning.system.get_state().get_node_ids()) == 15
        assert len(TestPruning.system.get_state().get_evidence().get_variables()) == 0

    def test_pruning1(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u", "Greeting", 0.8)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u", "None", 0.2)

    def test_pruning2(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "i_u", "Inform", 0.7 * 0.8)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "i_u", "None", 1 - 0.7 * 0.8)

    def test_pruning3(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "direction", "straight", 0.79)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "direction", "left", 0.20)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "direction", "right", 0.01)

    def test_pruning4(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have var1=value2", 0.3)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have localvar=value1", 0.2)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have localvar=value3", 0.31)

    def test_pruning5(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o2", "here is value1", 0.35)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o2", "and value2 is over there", 0.07)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o2", "value3, finally", 0.28)

    def test_pruning6(self):
        initial_state = copy(TestPruning.system.get_state())

        builder = CategoricalTableBuilder("var1")
        builder.add_row("value2", 0.9)
        TestPruning.system.get_state().add_to_state(builder.build())

        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have var1=value2", 0.3)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have localvar=value1", 0.2)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "o", "and we have localvar=value3", 0.31)

        TestPruning.system.get_state().reset(initial_state)

    def test_pruning7(self):
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u2", "[Greet, HowAreYou]", 0.7)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u2", "none", 0.1)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u2", "[HowAreYou]", 0.2)

    def test_pruning8(self):
        initial_state = copy(TestPruning.system.get_state())

        created_nodes = SortedSet()
        for node_id in TestPruning.system.get_state().get_node_ids():
            if node_id.find("a_u3^") != -1:
                created_nodes.add(node_id)

        assert len(created_nodes) == 2

        values = TestPruning.system.get_state().get_node(created_nodes[0] + "").get_values()
        if ValueFactory.create("Greet") in values:
            greet_node = created_nodes[0]  # created_nodes.first()
            howareyou_node = created_nodes[-1]  # created_nodes.last()
        else:
            greet_node = created_nodes[-1]  # created_nodes.last()
            howareyou_node = created_nodes[0]  # created_nodes.first()

        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u3", "[" + howareyou_node + "," + greet_node + "]", 0.7)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u3", "none", 0.1)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), "a_u3", "[" + howareyou_node + "]", 0.2)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), greet_node + "", "Greet", 0.7)
        TestPruning.inference.check_prob(TestPruning.system.get_state(), howareyou_node + "", "HowAreYou", 0.9)

        TestPruning.system.get_state().reset(initial_state)
Beispiel #8
0
class TestParameters:
    domain_file = "test/data/testwithparams.xml"
    domain_file2 = "test/data/testwithparams2.xml"
    param_file = "test/data/params.xml"

    params = XMLStateReader.extract_bayesian_network(param_file, "parameters")

    domain1 = XMLDomainReader.extract_domain(domain_file)
    domain1.set_parameters(params)

    domain2 = XMLDomainReader.extract_domain(domain_file2)
    domain2.set_parameters(params)

    inference = InferenceChecks()

    def test_param_1(self):
        InferenceChecks.exact_threshold = 0.1

        system = DialogueSystem(TestParameters.domain1)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False
        assert system.get_state().has_chance_node("theta_1")
        TestParameters.inference.check_cdf(system.get_state(), "theta_1", 0.5, 0.5)
        TestParameters.inference.check_cdf(system.get_state(), "theta_1", 5., 0.99)

        TestParameters.inference.check_cdf(system.get_state(), "theta_2", 1., 0.07)
        TestParameters.inference.check_cdf(system.get_state(), "theta_2", 2., 0.5)

        system.start_system()
        system.add_content("u_u", "hello there")
        utils = ((SamplingAlgorithm()).query_util(system.get_state(), "u_m'"))
        assert utils.get_util(Assignment("u_m'", "yeah yeah talk to my hand")) > 0
        assert utils.get_util(Assignment("u_m'", "so interesting!")) > 1.7
        assert utils.get_util(Assignment("u_m'", "yeah yeah talk to my hand")) < utils.get_util(Assignment("u_m'", "so interesting!"))
        assert len(system.get_state().get_node_ids()) == 11

    def test_param_2(self):
        InferenceChecks.exact_threshold = 0.1

        system = DialogueSystem(TestParameters.domain1)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False

        assert system.get_state().has_chance_node("theta_3")
        TestParameters.inference.check_cdf(system.get_state(), "theta_3", 0.6, 0.0)
        TestParameters.inference.check_cdf(system.get_state(), "theta_3", 0.8, 0.5)
        TestParameters.inference.check_cdf(system.get_state(), "theta_3", 0.95, 1.0)

        system.start_system()
        system.add_content("u_u", "brilliant")
        distrib = system.get_content("a_u")

        assert distrib.get_prob("approval") == pytest.approx(0.8, abs=0.05)

    def test_param_3(self):
        system = DialogueSystem(TestParameters.domain1)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False
        system.start_system()

        rules = TestParameters.domain1.get_models()[0].get_rules()
        outputs = rules[1].get_output(Assignment("u_u", "no no"))
        o = Effect(BasicEffect("a_u", "disapproval"))
        assert isinstance(outputs.get_parameter(o), SingleParameter)
        input = Assignment("theta_4", ValueFactory.create("[0.36, 0.64]"))
        assert outputs.get_parameter(o).get_value(input) == pytest.approx(0.64, abs=0.01)

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "no no")
        assert system.get_state().query_prob("theta_4").to_continuous().get_function().get_mean()[0] == pytest.approx(0.36, abs=0.1)

        assert system.get_content("a_u").get_prob("disapproval") == pytest.approx(0.64, abs=0.1)

    def test_param_4(self):
        system = DialogueSystem(TestParameters.domain1)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False
        system.start_system()

        rules = TestParameters.domain1.get_models()[1].get_rules()
        outputs = rules[0].get_output(Assignment("u_u", "my name is"))
        o = Effect(BasicEffect("u_u^p", "Pierre"))
        assert isinstance(outputs.get_parameter(o), SingleParameter)
        input = Assignment("theta_5", ValueFactory.create("[0.36, 0.24, 0.40]"))
        assert outputs.get_parameter(o).get_value(input) == pytest.approx(0.36, abs=0.01)

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "my name is")

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "Pierre")

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "my name is")

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "Pierre")

        assert system.get_state().query_prob("theta_5").to_continuous().get_function().get_mean()[0] == pytest.approx(0.3, abs=0.12)

    def test_param_5(self):
        system = DialogueSystem(TestParameters.domain2)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False
        system.start_system()

        rules = TestParameters.domain2.get_models()[0].get_rules()
        outputs = rules[0].get_output(Assignment("u_u", "brilliant"))
        o = Effect(BasicEffect("a_u", "approval"))
        assert isinstance(outputs.get_parameter(o), ComplexParameter)
        input = Assignment([Assignment("theta_6", 2.1), Assignment("theta_7", 1.3)])
        assert outputs.get_parameter(o).get_value(input) == pytest.approx(0.74, abs=0.01)

        system.get_state().remove_nodes(system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(system.get_state().get_utility_node_ids())
        system.add_content("u_u", "brilliant")

        assert system.get_state().query_prob("theta_6").to_continuous().get_function().get_mean()[0] == pytest.approx(1.0, abs=0.08)

        assert system.get_content("a_u").get_prob("approval") == pytest.approx(0.63, abs=0.08)
        assert system.get_content("a_u").get_prob("irony") == pytest.approx(0.3, abs=0.08)

    def test_param_6(self):
        system = DialogueSystem(XMLDomainReader.extract_domain("test/data/testparams3.xml"))
        system.get_settings().show_gui = False
        system.start_system()
        table = system.get_content("b").to_discrete()
        assert len(table) == 6
        assert table.get_prob("something else") == pytest.approx(0.45, abs=0.05)
        assert table.get_prob("value: first with type 1") == pytest.approx(0.175, abs=0.05)
        assert table.get_prob("value: second with type 2") == pytest.approx(0.05, abs=0.05)
Beispiel #9
0
class TestRule2:
    domain_file = "test/data/domain2.xml"
    domain_file2 = "test/data/domain3.xml"
    domain_file3 = "test/data/domain4.xml"
    domain_file4 = "test/data/thesistest2.xml"

    domain = XMLDomainReader.extract_domain(domain_file)
    inference = InferenceChecks()

    def test_1(self):
        system = DialogueSystem(TestRule2.domain)
        eq_factor = EquivalenceDistribution.none_prob
        EquivalenceDistribution.none_prob = 0.1
        old_prune_threshold = StatePruner.value_pruning_threshold
        StatePruner.value_pruning_threshold = 0.0

        system.get_settings().show_gui = False
        system.detach_module(ForwardPlanner)
        system.start_system()

        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "Ask(A)",
                                       0.63)
        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "Ask(B)",
                                       0.27)
        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "None",
                                       0.1)

        builder = CategoricalTableBuilder("a_u")
        builder.add_row("Ask(B)", 0.8)
        builder.add_row("None", 0.2)

        system.get_state().remove_nodes(
            system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(
            system.get_state().get_utility_node_ids())

        system.add_content(builder.build())

        TestRule2.inference.check_prob(system.get_state(), "i_u", "Want(A)",
                                       0.090)
        TestRule2.inference.check_prob(system.get_state(), "i_u", "Want(B)",
                                       0.91)

        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "Ask(B)",
                                       0.91 * 0.9)
        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "Ask(A)",
                                       0.09 * 0.9)
        TestRule2.inference.check_prob(system.get_state(), "a_u^p", "None",
                                       0.1)

        TestRule2.inference.check_prob(system.get_state(), "a_u", "Ask(B)",
                                       0.918)
        TestRule2.inference.check_prob(system.get_state(), "a_u", "None",
                                       0.081)

        EquivalenceDistribution.none_prob = eq_factor
        StatePruner.value_pruning_threshold = old_prune_threshold

    def test_2(self):
        system = DialogueSystem(TestRule2.domain)
        system.get_settings().show_gui = False
        system.detach_module(ForwardPlanner)
        eq_factor = EquivalenceDistribution.none_prob
        EquivalenceDistribution.none_prob = 0.1
        old_prune_threshold = StatePruner.value_pruning_threshold
        StatePruner.value_pruning_threshold = 0.0
        system.start_system()

        TestRule2.inference.check_prob(system.get_state(), "u_u2^p", "Do A",
                                       0.216)
        TestRule2.inference.check_prob(system.get_state(), "u_u2^p",
                                       "Please do C", 0.027)
        TestRule2.inference.check_prob(system.get_state(), "u_u2^p",
                                       "Could you do B?", 0.054)
        TestRule2.inference.check_prob(system.get_state(), "u_u2^p",
                                       "Could you do A?", 0.162)
        TestRule2.inference.check_prob(system.get_state(), "u_u2^p", "none",
                                       0.19)

        builder = CategoricalTableBuilder("u_u2")
        builder.add_row("Please do B", 0.4)
        builder.add_row("Do B", 0.4)

        system.get_state().remove_nodes(
            system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(
            system.get_state().get_utility_node_ids())
        system.add_content(builder.build())

        TestRule2.inference.check_prob(system.get_state(), "i_u2", "Want(B)",
                                       0.654)
        TestRule2.inference.check_prob(system.get_state(), "i_u2", "Want(A)",
                                       0.1963)
        TestRule2.inference.check_prob(system.get_state(), "i_u2", "Want(C)",
                                       0.0327)
        TestRule2.inference.check_prob(system.get_state(), "i_u2", "none",
                                       0.1168)

        EquivalenceDistribution.none_prob = eq_factor
        StatePruner.value_pruning_threshold = old_prune_threshold

    def test_3(self):
        system = DialogueSystem(TestRule2.domain)
        system.get_settings().show_gui = False
        system.detach_module(ForwardPlanner)
        eq_factor = EquivalenceDistribution.none_prob
        EquivalenceDistribution.none_prob = 0.1
        old_prune_threshold = StatePruner.value_pruning_threshold
        StatePruner.value_pruning_threshold = 0.0
        system.start_system()

        TestRule2.inference.check_util(system.get_state(), "a_m'", "Do(A)",
                                       0.6)
        TestRule2.inference.check_util(system.get_state(), "a_m'", "Do(B)",
                                       -2.6)

        builder = CategoricalTableBuilder("a_u")
        builder.add_row("Ask(B)", 0.8)
        builder.add_row("None", 0.2)
        system.get_state().remove_nodes(
            system.get_state().get_action_node_ids())
        system.get_state().remove_nodes(
            system.get_state().get_utility_node_ids())
        system.add_content(builder.build())

        TestRule2.inference.check_util(system.get_state(), "a_m'", "Do(A)",
                                       -4.35)
        TestRule2.inference.check_util(system.get_state(), "a_m'", "Do(B)",
                                       2.357)

        EquivalenceDistribution.none_prob = eq_factor
        StatePruner.value_pruning_threshold = old_prune_threshold

    def test_4(self):
        domain2 = XMLDomainReader.extract_domain(TestRule2.domain_file2)
        system2 = DialogueSystem(domain2)
        system2.get_settings().show_gui = False
        system2.detach_module(ForwardPlanner)
        system2.start_system()

        TestRule2.inference.check_util(
            system2.get_state(), ["a_m3'", "obj(a_m3)'"],
            Assignment(
                [Assignment("a_m3'", "Do"),
                 Assignment("obj(a_m3)'", "A")]), 0.3)
        TestRule2.inference.check_util(
            system2.get_state(), ["a_m3'", "obj(a_m3)'"],
            Assignment(
                [Assignment("a_m3'", "Do"),
                 Assignment("obj(a_m3)'", "B")]), -1.7)
        TestRule2.inference.check_util(
            system2.get_state(), ["a_m3'", "obj(a_m3)'"],
            Assignment([
                Assignment("a_m3'", "SayHi"),
                Assignment("obj(a_m3)'", "None")
            ]), -0.9)

    def test_5(self):
        domain2 = XMLDomainReader.extract_domain(TestRule2.domain_file3)
        system2 = DialogueSystem(domain2)
        system2.detach_module(ForwardPlanner)
        system2.get_settings().show_gui = False
        system2.start_system()

        TestRule2.inference.check_util(
            system2.get_state(), ["a_ml'", "a_mg'", "a_md'"],
            Assignment([
                Assignment("a_ml'", "SayYes"),
                Assignment("a_mg'", "Nod"),
                Assignment("a_md'", "None")
            ]), 2.4)
        TestRule2.inference.check_util(
            system2.get_state(), ["a_ml'", "a_mg'", "a_md'"],
            Assignment([
                Assignment("a_ml'", "SayYes"),
                Assignment("a_mg'", "Nod"),
                Assignment("a_md'", "DanceAround")
            ]), -0.6)
        TestRule2.inference.check_util(
            system2.get_state(), ["a_ml'", "a_mg'", "a_md'"],
            Assignment([
                Assignment("a_ml'", "SayYes"),
                Assignment("a_mg'", "None"),
                Assignment("a_md'", "None")
            ]), 1.6)

    def test_6(self):
        domain2 = XMLDomainReader.extract_domain(TestRule2.domain_file4)
        system2 = DialogueSystem(domain2)
        system2.detach_module(ForwardPlanner)
        system2.get_settings().show_gui = False
        system2.start_system()
        TestRule2.inference.check_prob(system2.get_state(), "A",
                                       ValueFactory.create("[a1,a2]"), 1.0)
        TestRule2.inference.check_prob(system2.get_state(), "a_u",
                                       "Request(ball)", 0.5)
Beispiel #10
0
class TestRule1:
    domain = XMLDomainReader.extract_domain('test/data/domain1.xml')
    inference = InferenceChecks()

    def test_1(self):
        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "a_u", "Greeting",
                                       0.8)
        TestRule1.inference.check_prob(system.get_state(), "a_u", "None", 0.2)

        StatePruner.enable_reduction = True

    def test_2(self):
        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "i_u", "Inform",
                                       0.7 * 0.8)
        TestRule1.inference.check_prob(system.get_state(), "i_u", "None",
                                       1. - 0.7 * 0.8)

        StatePruner.enable_reduction = True

    def test_3(self):
        InferenceChecks.exact_threshold = 0.06

        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "direction",
                                       "straight", 0.79)
        TestRule1.inference.check_prob(system.get_state(), "direction", "left",
                                       0.20)
        TestRule1.inference.check_prob(system.get_state(), "direction",
                                       "right", 0.01)

        StatePruner.enable_reduction = True

    def test_4(self):
        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have var1=value2", 0.3)
        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have localvar=value1", 0.2)
        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have localvar=value3", 0.28)

        StatePruner.enable_reduction = True

    def test_5(self):
        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "o2",
                                       "here is value1", 0.35)
        TestRule1.inference.check_prob(system.get_state(), "o2",
                                       "and value2 is over there", 0.07)
        TestRule1.inference.check_prob(system.get_state(), "o2",
                                       "value3, finally", 0.28)

        StatePruner.enable_reduction = True

    def test_6(self):
        InferenceChecks.exact_threshold = 0.06

        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        system.get_settings().show_gui = False
        system.start_system()

        builder = CategoricalTableBuilder("var1")
        builder.add_row("value2", 0.9)
        system.add_content(builder.build())

        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have var1=value2", 0.9)
        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have localvar=value1", 0.05)
        TestRule1.inference.check_prob(system.get_state(), "o",
                                       "and we have localvar=value3", 0.04)

        StatePruner.enable_reduction = True

    def test_7(self):
        system = DialogueSystem(TestRule1.domain)
        system.detach_module(ForwardPlanner)
        StatePruner.enable_reduction = False
        system.get_settings().show_gui = False
        system.start_system()

        TestRule1.inference.check_prob(system.get_state(), "a_u2",
                                       "[Greet, HowAreYou]", 0.7)
        TestRule1.inference.check_prob(system.get_state(), "a_u2", "[]", 0.1)
        TestRule1.inference.check_prob(system.get_state(), "a_u2",
                                       "[HowAreYou]", 0.2)

        StatePruner.enable_reduction = True