Search in sources :

Example 6 with BeliefAnalysis

use of nars.test.analyze.BeliefAnalysis in project narchy by automenta.

the class RevisionTest method testTruthOscillation2.

@Test
public void testTruthOscillation2() {
    Param.DEBUG = true;
    int maxBeliefs = 16;
    NAR n = newNAR(maxBeliefs);
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    // assertEquals(0.0, (Double) b.energy().get(MemoryBudget.Budgeted.ActiveConceptPrioritySum), 0.001);
    int period = 8;
    int loops = 4;
    for (int i = 0; i < loops; i++) {
        b.believe(1.0f, 0.9f, Tense.Present);
        b.run(period);
        // b.printEnergy();
        b.believe(0.0f, 0.9f, Tense.Present);
        b.run(period);
        // b.printEnergy();
        b.print();
    }
    b.run(period);
    b.print();
// TODO test the belief table for something like the following:
/*
    Beliefs[@72] 16/16
    <a --> b>. %0.27;0.98% [1, 2, 3, 4, 6] [Revision]
    <a --> b>. %0.38;0.98% [1, 2, 3, 4, 6, 7] [Revision]
    <a --> b>. %0.38;0.98% [1, 2, 3, 4, 5, 6] [Revision]
    <a --> b>. %0.23;0.98% [1, 2, 3, 4, 6, 8] [Revision]
    <a --> b>. %0.35;0.97% [1, 2, 3, 4] [Revision]
    <a --> b>. %0.52;0.95% [1, 2, 3] [Revision]
    <a --> b>. 56+0 %0.00;0.90% [8] [Input]
    <a --> b>. 48+0 %1.00;0.90% [7] [Input]
    <a --> b>. 40+0 %0.00;0.90% [6] [Input]
    <a --> b>. 32+0 %1.00;0.90% [5] [Input]
    <a --> b>. 24+0 %0.00;0.90% [4] [Input]
    <a --> b>. 16+0 %1.00;0.90% [3] [Input]
    <a --> b>. 8+0 %0.00;0.90% [2] [Input]
    <a --> b>. 0+0 %1.00;0.90% [1] [Input]
    <a --> b>. %0.09;0.91% [1, 2] [Revision]
    <a --> b>. 28-20 %0.00;0.18% [1, 2, 3] [((%1, <%1 </> %2>, shift_occurrence_forward(%2, "=/>")), (%2, (<Analogy --> Truth>, <Strong --> Desire>, <ForAllSame --> Order>)))]
     */
// b.believe(1.0f, 0.9f, Tense.Present).run(offCycles)
// .believe(0.0f, 0.9f, Tense.Present);
/*for (int i = 0; i < 16; i++) {
        b.printEnergy();
        b.print();
        n.frame(1);
    }*/
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) Test(org.junit.jupiter.api.Test)

Example 7 with BeliefAnalysis

use of nars.test.analyze.BeliefAnalysis in project narchy by automenta.

the class RevisionTest method testRevisionBudgeting.

/**
 * test that budget is conserved during a revision between
 * the input tasks and the result
 */
@Test
public void testRevisionBudgeting() {
    NAR n = newNAR(6);
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    assertEquals(0, b.priSum(), 0.01f);
    b.believe(1.0f, 0.5f).run(1);
    Bag<?, TaskLink> tasklinks = b.concept().tasklinks();
    assertEquals(0.5f, b.beliefs().match(ETERNAL, null, n).truth().conf(), 0.01f);
    printTaskLinks(b);
    System.out.println("--------");
    float linksBeforeRevisionLink = tasklinks.priSum();
    b.believe(0.0f, 0.5f).run(1);
    // assertEquals(2, tasklinks.size());
    printTaskLinks(b);
    System.out.println("--------");
    // allow enough time for tasklinks bag to commit
    b.run(1);
    tasklinks.commit();
    printTaskLinks(b);
    System.out.println("--------");
    System.out.println("Beliefs: ");
    b.print();
    System.out.println("\tSum Priority: " + b.priSum());
    float beliefAfter2;
    assertEquals(1.0f, beliefAfter2 = b.priSum(), 0.1f);
    // assertEquals(linksBeforeRevisionLink, tasklinks.priSum(), 0.01f);
    // the revised task on top
    assertEquals(0.71f, b.beliefs().match(ETERNAL, null, n).truth().conf(), 0.06f);
    b.print();
    // revised:
    assertEquals(3, b.size(true));
    // 3 if a non-revised eternal task (which creates a revision) revised eternal task is also input/processed. 2 if it is not
    // assertEquals(3, tasklinks.size());
    // CONSERVED BELIEF BUDGET
    assertEquals(beliefAfter2, b.priSum(), 0.01f);
// tasklinks.commit();
// tasklinks.print();
// without tasklink balancing: 1.24 - 0.97
// with balancing: 1.10 - 0.97
// assertEquals( linksBeforeRevisionLink, tasklinks.priSum(), 0.1f); //CONSERVED LINK BUDGET
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) TaskLink(nars.link.TaskLink) Test(org.junit.jupiter.api.Test)

Example 8 with BeliefAnalysis

use of nars.test.analyze.BeliefAnalysis in project narchy by automenta.

the class BeliefTableTest method testPolation0.

@Test
public void testPolation0() {
    int spacing = 4;
    float conf = 0.9f;
    float[] freqPattern = // new float[]{0, 0.25f, 0.5f, 0.75f, 1f};
    { 0, 0.5f, 1f };
    long[] timing = { 0, 2, 4 };
    int dur = 1;
    NAR n = NARS.shell();
    n.time.dur(dur);
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    assertEquals(timing.length, freqPattern.length);
    int k = 0;
    for (float f : freqPattern) {
        // create linear gradient of belief across time, freq beginning at 0 and increasing to 1
        b.believe(0.5f, freqPattern[k], conf, timing[k]);
        k++;
    }
    int c = freqPattern.length;
    assertEquals(c, b.size(true));
    @NotNull BeliefTable table = b.concept().beliefs();
    b.print();
    int margin = spacing * (c / 2);
    for (int i = -margin; i < spacing * c + margin; i++) System.out.println(i + "\t" + table.truth(i, /* relative to zero */
    n));
    // measure exact timing
    for (int i = 0; i < c; i++) {
        long w = timing[i];
        Truth truth = table.truth(w, n);
        float fExpected = freqPattern[i];
        assertEquals(fExpected, truth.freq(), 0.01f, "exact truth @" + w + " == " + fExpected);
        Task match = table.match(w, null, n);
        assertEquals(fExpected, match.freq(), 0.01f, "exact belief @" + w + " == " + fExpected);
    }
    // measure midpoint interpolation
    for (int i = 1; i < c - 1; i++) {
        float f = (freqPattern[i - 1] + freqPattern[i] + freqPattern[i + 1]) / 3f;
        long w = timing[i];
        assertEquals(f, table.truth(w, n).freq(), 0.1f, () -> "t=" + w);
    }
// /* first */
// @Nullable Truth firstBeliefTruth = table.truth((long) 0, n);
// assertEquals(0.43f, firstBeliefTruth.freq(), 0.1f);
// 
// /* last */
// @Nullable Truth lastBeliefTruth = table.truth((long) (spacing * (c - 1)), n);
// assertEquals(0.56f, lastBeliefTruth.freq(), 0.1f);
// 
// @Nullable Truth endTruth = table.truth((long) (spacing * (c - 1) + margin), n);
// assertEquals(0.55f, endTruth.freq(), 0.2f);
// assertTrue(lastBeliefTruth.conf() >= endTruth.conf());
// 
// @Nullable Truth startTruth = table.truth((long) (0 - margin), n);
// assertEquals(0.44f, startTruth.freq(), 0.2f);
// assertTrue(firstBeliefTruth.conf() >= startTruth.conf());
}
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 9 with BeliefAnalysis

use of nars.test.analyze.BeliefAnalysis in project narchy by automenta.

the class RevectionTest method testConfidenceAccumulation.

public void testConfidenceAccumulation(int repeats, float freq, float inConf) {
    int maxBeliefs = repeats * 4;
    NAR n = newNAR(maxBeliefs);
    n.log();
    long at = 5;
    float outConf = w2c(c2w(inConf) * repeats);
    BeliefAnalysis b = null;
    try {
        b = new BeliefAnalysis(n, "<a-->b>");
    } catch (Narsese.NarseseException e) {
        fail(e);
    }
    for (int i = 0; i < repeats; i++) {
        b.believe(0.5f, freq, inConf, at);
    }
    b.run(1);
    b.print();
    assertTrue(repeats <= b.size(true));
    @Nullable Truth result = n.beliefTruth(b, at);
    assertEquals(freq, result.freq(), 0.25f);
    assertEquals(outConf, result.conf(), 0.25f);
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) RevisionTest.newNAR(nars.task.RevisionTest.newNAR) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth)

Aggregations

BeliefAnalysis (nars.test.analyze.BeliefAnalysis)9 Test (org.junit.jupiter.api.Test)7 RevisionTest.newNAR (nars.task.RevisionTest.newNAR)3 Truth (nars.truth.Truth)3 DynamicTruthBeliefTable (nars.concept.dynamic.DynamicTruthBeliefTable)2 BeliefTable (nars.table.BeliefTable)2 TestNAR (nars.test.TestNAR)2 NotNull (org.jetbrains.annotations.NotNull)2 HashSet (java.util.HashSet)1 TaskLink (nars.link.TaskLink)1 Nullable (org.jetbrains.annotations.Nullable)1