Search in sources :

Example 21 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class BeliefTableTest method testEternalBeliefRanking.

@Test
public void testEternalBeliefRanking() {
    Param.DEBUG = true;
    int cap = 10;
    NAR n = NARS.shell();
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    b.believe(1.0f, 0.5f);
    b.print();
    BeliefTable beliefs = b.concept().beliefs();
    assertEquals(0.5, beliefs.match(ETERNAL, null, n).conf(), 0.001);
    Truth bt = n.beliefTruth(b, n.time());
    assertNotNull(bt);
    assertEquals(0.5, bt.conf(), 0.001);
    assertEquals(1, beliefs.size());
    b.believe(1.0f, 0.5f);
    n.run();
    b.print();
    assertEquals(3, /* revision */
    beliefs.size());
    assertEquals(0.669, beliefs.match(ETERNAL, null, n).conf(), 0.01);
    b.believe(1.0f, 0.5f);
    n.run();
    b.print();
    assertEquals(5, beliefs.size());
    @NotNull BeliefTable bb = beliefs;
    assertEquals(0.75, bb.match(ETERNAL, null, n).conf(), 0.001);
    assertEquals(0.75, n.beliefTruth(b, n.time()).conf(), 0.01);
    b.believe(1.0f, 0.5f);
    n.run();
    b.print();
    assertEquals(0.79, beliefs.match(ETERNAL, null, n).conf(), 0.02);
    assertEquals(6, beliefs.size());
}
Also used : DynamicTruthBeliefTable(nars.concept.dynamic.DynamicTruthBeliefTable) BeliefTable(nars.table.BeliefTable) BeliefAnalysis(nars.test.analyze.BeliefAnalysis) NotNull(org.jetbrains.annotations.NotNull) TestNAR(nars.test.TestNAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 22 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class RevectionTest method testPolation1.

@Test
public void testPolation1() throws Narsese.NarseseException {
    int dur = 1;
    Task a = t(1f, 0.9f, 3).apply(n);
    Task b = t(0f, 0.9f, 6).apply(n);
    for (int i = 0; i < 10; i++) {
        System.out.println(i + " " + new TruthPolation((long) i, (long) i, dur, Lists.newArrayList(a, b)).truth((Task) null));
    }
    System.out.println();
    Truth ab2 = new TruthPolation((long) 3, (long) 3, dur, Lists.newArrayList(a, b)).truth((Task) null);
    assertTrue(ab2.conf() >= 0.5f);
    Truth abneg1 = new TruthPolation((long) 3, (long) 3, dur, Lists.newArrayList(a, b)).truth((Task) null);
    assertTrue(abneg1.freq() > 0.6f);
    assertTrue(abneg1.conf() >= 0.5f);
    Truth ab5 = new TruthPolation((long) 6, (long) 6, dur, Lists.newArrayList(a, b)).truth((Task) null);
    assertTrue(ab5.freq() < 0.35f);
    assertTrue(ab5.conf() >= 0.5f);
}
Also used : Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 23 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class RevectionTest method print.

// public static void _main(String[] args) {
// TruthPolation p = new TruthPolation(4,
// 0f);
// //0.1f);
// 
// List<Task> l = Global.newArrayList();
// 
// //NAR n = new Default();
// l.add( new TaskBuilder("a:b", BELIEF, new DefaultTruth(0f, 0.5f) ).occurr(0).setCreationTime(0) );
// l.add( new TaskBuilder("a:b", BELIEF, new DefaultTruth(1f, 0.5f) ).occurr(5).setCreationTime(0) );
// l.add( new TaskBuilder("a:b", BELIEF, new DefaultTruth(0f, 0.75f) ).occurr(10).setCreationTime(0) );
// print(p, l, -5, 15);
// 
// 
// }
public static void print(@NotNull List<Task> l, int start, int end) {
    // interpolation (revision) and extrapolation (projection)
    System.out.println("INPUT");
    for (Task t : l) {
        System.out.println(t);
    }
    System.out.println();
    System.out.println("TRUTHPOLATION");
    for (long d = start; d < end; d++) {
        Truth a1 = new TruthPolation(d, d, 1, l).truth((Task) null);
        System.out.println(d + ": " + a1);
    }
}
Also used : Truth(nars.truth.Truth)

Example 24 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class RuleInductionTest method test1.

@Test
public void test1() {
    int dur = 1;
    int loops = 10;
    int period = 2;
    int dutyPeriod = 1;
    NAR n = NARS.tmp();
    n.termVolumeMax.set(3);
    // n.log();
    // dense proressing
    Deriver.derivers(n).forEach(d -> d.conceptsPerIteration.set(64));
    n.time.dur(dur);
    Term aConjB = $$("(a &&+" + dutyPeriod + " b)");
    float lastAConjB_exp = 0;
    PairedStatsAccumulator aConjB_exp = new PairedStatsAccumulator();
    for (int i = 0; i < loops; i++) {
        // n.clear(); //distraction clear
        n.believe("a", Tense.Present, 1, 0.9f);
        if (i > 0) {
        // TODO test that the newest tasklink inserted into concept 'a' is the, or nearly the strongest
        // n.concept("a").tasklinks().print();
        }
        n.run(dutyPeriod);
        n.believe("b", Tense.Present, 1, 0.9f);
        // delay
        n.run(period - dutyPeriod);
        long now = n.time();
        System.out.println("\n" + now);
        Truth aConjB_truth = n.belief(aConjB, now).truth(now, n.dur());
        System.out.println(aConjB_truth);
        n.conceptualize(aConjB).beliefs().print();
        float exp = aConjB_truth.expectation();
        if (!(exp >= lastAConjB_exp)) {
            // for debug
            Task tt = n.belief(aConjB, now);
        }
        // assertTrue(exp > lastAConjB_exp); //increasing
        aConjB_exp.add(now, exp);
        lastAConjB_exp = exp;
    }
    System.out.println(aConjB_exp.yStats());
    System.out.println("slope=" + aConjB_exp.leastSquaresFit().slope());
    // rising confidence
    assertTrue(aConjB_exp.leastSquaresFit().slope() > 0);
}
Also used : Task(nars.Task) Term(nars.term.Term) PairedStatsAccumulator(com.google.common.math.PairedStatsAccumulator) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 25 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class ImplicationTest method testGoal.

@Test
public void testGoal() {
    // Z, X==>Y
    StringBuilder o = new StringBuilder();
    for (boolean sp : B) {
        Term z = sp ? x : y;
        for (boolean zz : B) {
            for (boolean xx : B) {
                for (boolean yy : B) {
                    NAR n = NARS.tmp();
                    Term cond = z.negIf(!zz);
                    Term impl = IMPL.the(x.negIf(!xx), y.negIf(!yy));
                    n.believe(impl);
                    n.goal(cond);
                    n.run(64);
                    Term nz = sp ? y : x;
                    @Nullable Truth nzt = n.goalTruth(nz, ETERNAL);
                    o.append(cond + "! " + impl + ". " + nz + "=" + nzt + "\n");
                }
            }
        }
    }
    String oo = o.toString();
    System.out.println(oo);
    // strong
    assertContains(oo, "y! (x==>y). x=%1.0;.81%");
    assertContains(oo, "y! ((--,x)==>y). x=%0.0;.81%");
    assertContains(oo, "(--,y)! (--,(x==>y)). x=%1.0;.81%");
    assertContains(oo, "(--,y)! (--,((--,x)==>y)). x=%0.0;.81%");
    // weak
    assertContains(oo, "x! (x==>y). y=%1.0;.45%");
    assertContains(oo, "x! (--,(x==>y)). y=%0.0;.45%");
// ...
}
Also used : Term(nars.term.Term) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Aggregations

Truth (nars.truth.Truth)65 Term (nars.term.Term)31 Test (org.junit.jupiter.api.Test)22 Nullable (org.jetbrains.annotations.Nullable)20 NAR (nars.NAR)18 Task (nars.Task)14 BeliefTable (nars.table.BeliefTable)13 Concept (nars.concept.Concept)9 NALTask (nars.task.NALTask)9 TaskConcept (nars.concept.TaskConcept)7 PreciseTruth (nars.truth.PreciseTruth)7 NotNull (org.jetbrains.annotations.NotNull)7 FasterList (jcog.list.FasterList)6 ITask (nars.task.ITask)6 Tense (nars.time.Tense)6 Util (jcog.Util)5 BELIEF (nars.Op.BELIEF)5 Consumer (java.util.function.Consumer)4 Predicate (java.util.function.Predicate)4 Param (nars.Param)4