Search in sources :

Example 16 with Truth

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

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToBC.

@Test
public void testEternal_A_NegBelief_NegToBC() {
    NAR n = NARS.tmp(6);
    n.termVolumeMax.set(16);
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b));
    n.believe(IMPL.the(b, c));
    n.believe(a.neg());
    n.run(800);
    BeliefTable aa = n.concept(a).beliefs();
    BeliefTable bb = n.concept(b).beliefs();
    BeliefTable cc = n.concept(c).beliefs();
    aa.print();
    bb.print();
    // cc.print();
    cc.forEachTask(x -> System.out.println(x.proof()));
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = bb.truth(ETERNAL, n);
    Truth cBelief = cc.truth(ETERNAL, n);
    assertEquals("%1.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 17 with Truth

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

the class ImplicationNetworkTest method testEternal_A_PosGoal_ToBC.

@Test
public void testEternal_A_PosGoal_ToBC() {
    NAR n = NARS.tmp();
    Param.DEBUG = true;
    n.believe(IMPL.the(a, b));
    n.believe(IMPL.the(b, c));
    n.goal(a);
    n.run(100);
    BeliefTable aGoals = n.concept(a).goals();
    Truth aGoal = aGoals.truth(ETERNAL, n);
    // n.concept(a).print();
    // a belief state should not exceed the input (default confidence) and freq remain stable
    // additional beliefs are not helpful
    assertEquals(1, aGoals.size());
    BeliefTable bGoals = n.concept(b).goals();
    Truth bGoal = bGoals.truth(ETERNAL, n);
    n.concept(b).print();
    assertEquals(1, bGoals.size());
    // b should have less conf than a but higher than c
    // same freq among all
    BeliefTable cGoals = n.concept(c).goals();
    Truth cGoal = cGoals.truth(ETERNAL, n);
    n.concept(c).print();
    // assertEquals(1, cGoals.size());
    System.out.println("a: " + aGoal);
    System.out.println("b: " + bGoal);
    System.out.println("c: " + cGoal);
    assertEquals(aGoal.freq(), bGoal.freq(), n.freqResolution.floatValue());
    assertEquals(bGoal.freq(), cGoal.freq(), n.freqResolution.floatValue());
    assertTrue(aGoal.conf() - bGoal.conf() > n.confResolution.floatValue() * 2);
    assertTrue(bGoal.conf() - cGoal.conf() > n.confResolution.floatValue() * 2);
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 18 with Truth

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

the class NarseseTest method testTruth.

void testTruth(String t, float freq, float conf) throws Narsese.NarseseException {
    String s = "a:b. " + t;
    Truth truth = task(s).truth();
    assertEquals(freq, truth.freq(), 0.001);
    assertEquals(conf, truth.conf(), 0.001);
}
Also used : Truth(nars.truth.Truth)

Example 19 with Truth

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

the class RTreeBeliefTableTest method testAccuracy.

static void testAccuracy(int dur, int period, int end, int cap, LongToFloatFunction func) {
    NAR n = NARS.shell();
    n.time.dur(dur);
    Term term = $.p("x");
    // 1. populate
    // n.log();
    TaskConcept c = (TaskConcept) n.conceptualize(term);
    @NotNull BeliefTable cb = true ? c.beliefs() : c.goals();
    cb.setCapacity(0, cap);
    // int numTasks = 0;
    System.out.println("points:");
    long time;
    long start = n.time();
    while ((time = n.time()) < end) {
        float f = func.valueOf(time);
        System.out.print(time + "=" + f + "\t");
        n.input($.task(term, BELIEF, f, 0.9f).time(time).setPriThen(0.5f).apply(n));
        n.run(period);
        c.beliefs().print();
        System.out.println();
    // numTasks++;
    }
    System.out.println();
    System.out.println();
    MultiStatistics<Task> m = new MultiStatistics<Task>().classify("input", (t) -> t.isInput()).classify("derived", (t) -> t instanceof DerivedTask).value("pri", (t) -> t.pri()).value2D("truth", (t) -> new float[] { t.freq(), t.conf() }).value("freqErr", (t) -> Math.abs(((t.freq() - 0.5f) * 2f) - func.valueOf(t.mid()))).add(c.beliefs().streamTasks().collect(toList()));
    System.out.println();
    m.print();
    System.out.println();
    c.beliefs().print();
    // 2. validate and calculate error
    CSVOutput csv = new CSVOutput(System.out, "time", "actual", "approx");
    double errSum = 0;
    for (long i = start; i < end; i++) {
        float actual = func.valueOf(i);
        Truth actualTruth = n.beliefTruth(term, i);
        float approx, err;
        if (actualTruth != null) {
            approx = actualTruth.freq();
            err = Math.abs(approx - actual);
        } else {
            approx = Float.NaN;
            err = 1f;
        }
        errSum += err;
        csv.out(i, actual, approx);
    // System.out.println(n2(i) + "\t" + /*n2(err) + "\t" + */ n2(expected) + "\t" + n2(actual));
    }
    double avgErr = errSum / (end - start + 1);
    System.out.println();
    System.out.println(n4(avgErr) + " avg freq err per point");
    assertTrue(avgErr < 0.1f);
}
Also used : Texts.n4(jcog.Texts.n4) nars(nars) LongToFloatFunction(org.eclipse.collections.api.block.function.primitive.LongToFloatFunction) Test(org.junit.jupiter.api.Test) BeliefTable(nars.table.BeliefTable) Truth(nars.truth.Truth) Collectors.toList(java.util.stream.Collectors.toList) RTreeBeliefTable(nars.table.RTreeBeliefTable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CSVOutput(jcog.meter.event.CSVOutput) BELIEF(nars.Op.BELIEF) Termed(nars.term.Termed) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TaskConcept(nars.concept.TaskConcept) NotNull(org.jetbrains.annotations.NotNull) MultiStatistics(jcog.math.MultiStatistics) Term(nars.term.Term) TaskConcept(nars.concept.TaskConcept) MultiStatistics(jcog.math.MultiStatistics) Term(nars.term.Term) NotNull(org.jetbrains.annotations.NotNull) BeliefTable(nars.table.BeliefTable) RTreeBeliefTable(nars.table.RTreeBeliefTable) Truth(nars.truth.Truth) CSVOutput(jcog.meter.event.CSVOutput)

Example 20 with Truth

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

the class TruthletTaskTest method testImpulseTruthlet.

@Test
public void testImpulseTruthlet() {
    NAR n = NARS.shell();
    Term x = $.the("x");
    float conf = 0.9f;
    n.input(new TruthletTask(x, BELIEF, Truthlet.impulse(1, 2, 1f, 0f, c2w(conf)), n));
    BeliefTable xb = n.truths(x, BELIEF);
    for (int i = -1; i < 5; i++) {
        Truth ti = xb.truth(i, n);
        assertEquals((i <= 0 || i >= 3) ? 0 : 1, ti.freq());
        if (i >= 1 && i <= 2)
            assertEquals(conf, ti.conf());
        else
            assertTrue(conf > ti.conf());
        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)

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