예제 #1
0
파일: test_utils.py 프로젝트: ntoxeg/rocca
def test_differential_entropy():
    """Test differential entropy."""

    setup()

    # A is almost sure, thus has minimum differential entropy
    A = ConceptNode("A", tv=createTruthValue(1, 1))
    A_de = differential_entropy(A)
    assert A_de == -float("inf")

    # B is nearly unsure, thus has low differential entropy
    B = ConceptNode("B", tv=createTruthValue(0, 0.1))
    B_de = differential_entropy(B)
    assert B_de == approx(-3.5, abs=0.1)

    # C is true half of the time, thus has maximum differential entropy
    C = ConceptNode("C", tv=createTruthValue(0.5, 1))
    C_de = differential_entropy(C)
    assert C_de == approx(0)

    # D is unknown, thus has maximum differential entropy
    D = ConceptNode("D", tv=createTruthValue(1, 0))
    D_de = differential_entropy(D)
    assert D_de == approx(0)

    # E is slightly more probable than average, thus has high
    # differential entropy
    E = ConceptNode("E", tv=createTruthValue(0.55, 0.03))
    E_de = differential_entropy(E)
    assert E_de == approx(-1.0, abs=0.1)

    # F is slightly more probable than average, but with high
    # confidence, thus has lower differential entropy than E.
    F = ConceptNode("F", tv=createTruthValue(0.55, 0.99))
    F_de = differential_entropy(F)
    assert F_de == approx(-5.0, abs=0.1)

    # Atoms with (stv 0.9 0.9) or (stv 0.1 0.9) below the (currently)
    # default threshold
    G = ConceptNode("G", tv=createTruthValue(0.99, 1e-3))
    G_de = differential_entropy(G)
    H = ConceptNode("H", tv=createTruthValue(0.01, 1e-3))
    H_de = differential_entropy(H)
    assert G_de == approx(H_de)
    assert G_de < -1e-1

    # Atoms with (stv 0.5 0.9) or (stv 0.9 0.01) below the (currently)
    # default threshold
    I = ConceptNode("I", tv=createTruthValue(0.5, 1e-3))
    I_de = differential_entropy(I)
    J = ConceptNode("J", tv=createTruthValue(0.99, 1e-4))
    J_de = differential_entropy(J)
    assert -1e-1 < I_de
    assert -1e-1 < J_de

    teardown()
예제 #2
0
파일: test_utils.py 프로젝트: ntoxeg/rocca
def test_get_uniq_atoms():
    P = PredicateNode("P")
    A = ConceptNode("A")
    B = ConceptNode("B")
    AB = ListLink(A, B)
    AA = ListLink(A, A)
    PAB = EvaluationLink(P, AB)
    PAA = EvaluationLink(P, AA)

    # Test all uniq atoms of PAB
    assert get_uniq_atoms(PAB) == {P, A, B, AB, PAB}

    # Test all uniq atoms of PAA
    assert get_uniq_atoms(PAA) == {P, A, AA, PAA}
예제 #3
0
파일: chase.py 프로젝트: ntoxeg/rocca
    def labeled_observation(self, space, obs, sbs=""):
        """Translate gym observation to Atomese

        There are 2 gym observations:

        Agent Position is 0 (left) or 1 (right)
        Pellet Positon is 0 (left), 1 (right) or 2 (none)

        Translated in Atomese as follows:

        Evaluation
          Predicate "Agent Position"
          AP

        where AP can be

        1. Concept "Left Square"
        2. Concept "Right Square"

        Evaluation
          Predicate "Pellet Position"
          PP

        where PP can be

        1. Concept "Left Square"
        2. Concept "Right Square"
        3. Concept "None"

        """

        to_atomese_position = {
            0: ConceptNode("Left Square"),
            1: ConceptNode("Right Square"),
            2: ConceptNode("None"),
        }
        ap = to_atomese_position[obs[0]]
        pp = to_atomese_position[obs[1]]
        return [
            EvaluationLink(PredicateNode("Agent Position"), ap),
            EvaluationLink(PredicateNode("Pellet Position"), pp),
        ]
예제 #4
0
 def send_simple_command(self, service):
     msg = {
         "type": "call_service",
         "domain": self.get_domain(),
         "service": service.name,
         "service_data": {
             "entity_id": self.entity_id
         }
     }
     self.queue_send.put(msg)
     return ConceptNode("wait #119 merge into master")
예제 #5
0
파일: test_utils.py 프로젝트: ntoxeg/rocca
def test_shannon_entropy():
    """Test Shannon entropy."""

    setup()

    # A is almost sure, thus has minimum Shannon entropy
    A = ConceptNode("A", tv=createTruthValue(1, 1))
    A_se = shannon_entropy(A)
    assert A_se == approx(0)

    # B is nearly unsure, thus has low Shannon entropy
    B = ConceptNode("B", tv=createTruthValue(0, 0.1))
    B_se = shannon_entropy(B)
    assert B_se == approx(0, abs=0.1)

    # C is true half of the time, thus has maximum Shannon entropy
    C = ConceptNode("C", tv=createTruthValue(0.5, 1))
    C_se = shannon_entropy(C)
    assert C_se == approx(1)

    # D is unknown, thus has maximum Shannon entropy
    D = ConceptNode("D", tv=createTruthValue(1, 0))
    D_se = shannon_entropy(D)
    assert D_se == approx(1)

    # E is highly probable, thus has mid range Shannon entropy
    E = ConceptNode("E", tv=createTruthValue(0.9, 0.5))
    E_se = shannon_entropy(E)
    assert E_se == approx(0.5, abs=0.1)

    # F is higly improbable and has a moderate confidence, thus has
    # Shannon entropy below 0.1
    F = ConceptNode("F", tv=createTruthValue(0, 1e-1))
    F_se = shannon_entropy(F)
    assert F_se < 0.1

    # G is higly improbable and has low confidence, thus has Shannon
    # entropy above 0.1
    G = ConceptNode("G", tv=createTruthValue(0, 1e-2))
    G_se = shannon_entropy(G)
    assert 0.1 < G_se

    # H is higly improbable and has very low confidence, thus has
    # Shannon entropy above 0.9
    H = ConceptNode("H", tv=createTruthValue(0, 1e-3))
    H_se = shannon_entropy(H)
    assert 0.9 < H_se

    teardown()
예제 #6
0
    def test_pass_value_via_atom(self):
        obj = TestObject("some object")
        container = ConceptNode("container")
        key = ConceptNode("key")
        container.set_value(key, PtrValue(obj))

        value = valueToPtrValue(container.get_value(key))

        ref = value.value()
        self.assertEqual(ref.name, "some object")
예제 #7
0
파일: event.py 프로젝트: singnet/coghome
 def get_type_cn(self):
     return ConceptNode(self.event_type)
예제 #8
0
파일: event.py 프로젝트: singnet/coghome
 def get_data_cn(self, key):
     return ConceptNode(self.data[key.name] if key.name in self.data else "None")
예제 #9
0
 def is_event_type_equal_cn(self, cn):
     return ConceptNode(str(cn.name == self.event_type))
예제 #10
0
 def is_data_equal_cn(self, key, cn):
     return ConceptNode(
         str((key.name in self.data) and cn.name == self.data[key.name]))
예제 #11
0
파일: entity.py 프로젝트: singnet/coghome
 def get_state_cn(self):
     return ConceptNode(self.state)
예제 #12
0
 def is_state_equal_cn(self, cn):
     return ConceptNode(str(self.state == cn.name))