Search in sources :

Example 11 with BeliefTable

use of nars.table.BeliefTable in project narchy by automenta.

the class TruthletTaskTest method test_LinearTruthlet_And_SustainTruthlet.

@Test
public void test_LinearTruthlet_And_SustainTruthlet() {
    float conf = 0.9f;
    RangeTruthlet s = Truthlet.slope(0, 1f, 3, 0f, c2w(conf));
    for (Truthlet t : new Truthlet[] { s, new SustainTruthlet(s, 1) }) {
        NAR n = NARS.shell();
        Term x = $.the("x");
        System.out.println(t);
        n.input(new TruthletTask(x, BELIEF, t, n));
        BeliefTable xb = n.truths(x, BELIEF);
        for (int i = -3; i < 7; i++) {
            Truth ti = xb.truth(i, n);
            if (i < 0 || i > 3) {
                if (t instanceof SustainTruthlet) {
                    // fade out
                    assertTrue(ti.conf() < 0.9f);
                } else {
                    assertNull(ti);
                }
            } else {
                assertEquals(0.9f, ti.conf());
                float f = ti.freq();
                switch(i) {
                    case 0:
                        assertEquals(1f, f, 0.01f);
                        break;
                    case 1:
                        assertEquals(0.666f, f, 0.01f);
                        break;
                    case 2:
                        assertEquals(0.333f, f, 0.01f);
                        break;
                    case 3:
                        assertEquals(0f, f, 0.01f);
                        break;
                }
            }
            System.out.println(i + ": " + ti);
        }
    }
}
Also used : BeliefTable(nars.table.BeliefTable) Term(nars.term.Term) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 12 with BeliefTable

use of nars.table.BeliefTable in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToBC_AB_only.

@Test
public void testEternal_A_NegBelief_NegToBC_AB_only() {
    NAR n = NARS.tmp(6);
    n.termVolumeMax.set(16);
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aa = n.concept(a).beliefs();
    BeliefTable bb = n.concept(b).beliefs();
    aa.print();
    // bb.print();
    bb.forEachTask(x -> System.out.println(x.proof()));
    Truth bBelief = bb.truth(ETERNAL, n);
    assertEquals("%1.0;.81%", bBelief.toString());
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 13 with BeliefTable

use of nars.table.BeliefTable in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToB_NegToC.

@Test
public void testEternal_A_NegBelief_NegToB_NegToC() {
    NAR n = NARS.tmp();
    n.log();
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b).neg());
    n.believe(IMPL.the(b.neg(), c));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aBeliefs = n.concept(a).beliefs();
    aBeliefs.print();
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = n.concept(b).beliefs().truth(ETERNAL, n);
    Truth cBelief = n.concept(c).beliefs().truth(ETERNAL, n);
    assertEquals("%0.0;.81%", bBelief.toString());
    assertEquals("%1.0;.73%", cBelief.toString());
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 14 with BeliefTable

use of nars.table.BeliefTable in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_ToBC.

@Test
public void testEternal_A_NegBelief_ToBC() {
    NAR n = NARS.tmp();
    Param.DEBUG = true;
    n.believe(IMPL.the(a, b));
    n.believe(IMPL.the(b, c));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aBeliefs = n.concept(a).beliefs();
    // Truth aBelief = aBeliefs.truth(ETERNAL, n);
    // a belief state should not exceed the input (default confidence) and freq remain stable
    // additional beliefs are not helpful
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = n.concept(b).beliefs().truth(ETERNAL, n);
    // NOTHING
    assertNull(bBelief);
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 15 with BeliefTable

use of nars.table.BeliefTable in project narchy by automenta.

the class BeliefTableChart method update.

@Override
public void update() {
    long now = this.now = nar.time();
    int dur = /*this.dur = */
    nar.dur();
    cc = (TaskConcept) nar.concept(term);
    long minT, maxT;
    if (range != null) {
        minT = range[0];
        maxT = range[1];
    } else {
        minT = Long.MIN_VALUE;
        maxT = Long.MAX_VALUE;
    }
    if (cc != null) {
        cp = 1f;
        /*nar.pri(cc);*/
        long nowEnd = now + dur / 2;
        long nowStart = now - dur / 2;
        BeliefTable ccb = cc.beliefs();
        this.beliefs.set(ccb, now, dur, nar, minT, maxT);
        this.beliefs.current = ccb.truth(nowStart, nowEnd, nar);
        BeliefTable ccg = cc.goals();
        this.goals.set(ccg, now, dur, nar, minT, maxT);
        this.goals.current = ccg.truth(nowStart, nowEnd, nar);
        if (projections > 0 && minT != maxT) {
            beliefProj.project(cc, true, minT, maxT, dur, projections, nar);
            goalProj.project(cc, false, minT, maxT, dur, projections, nar);
        }
    } else {
        cp = 0;
        beliefs.clear();
        beliefs.current = null;
        goals.clear();
        goals.current = null;
        beliefProj.clear();
        goalProj.clear();
    }
}
Also used : BeliefTable(nars.table.BeliefTable)

Aggregations

BeliefTable (nars.table.BeliefTable)17 Truth (nars.truth.Truth)12 Test (org.junit.jupiter.api.Test)12 NAR (nars.NAR)10 Term (nars.term.Term)5 TestNAR (nars.test.TestNAR)3 NotNull (org.jetbrains.annotations.NotNull)3 Concept (nars.concept.Concept)2 TaskConcept (nars.concept.TaskConcept)2 DynamicTruthBeliefTable (nars.concept.dynamic.DynamicTruthBeliefTable)2 BeliefAnalysis (nars.test.analyze.BeliefAnalysis)2 Collectors.toList (java.util.stream.Collectors.toList)1 Texts.n4 (jcog.Texts.n4)1 MultiStatistics (jcog.math.MultiStatistics)1 CSVOutput (jcog.meter.event.CSVOutput)1 nars (nars)1 Op (nars.Op)1 BELIEF (nars.Op.BELIEF)1 Task (nars.Task)1 RTreeBeliefTable (nars.table.RTreeBeliefTable)1