Search in sources :

Example 1 with BeliefAnalysis

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

the class RevisionTest method testTruthOscillation.

@Test
public void testTruthOscillation() {
    // newNAR(8);
    NAR n = NARS.shell();
    Param.DEBUG = true;
    n.log();
    int offCycles = 2;
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    // assertEquals(0.0, (Double) b.energy().get(MemoryBudget.Budgeted.ActiveConceptPrioritySum), 0.001);
    b.believe(1.0f, 0.9f, Tense.Present);
    b.run(1);
    // b.printEnergy();
    b.run(1);
    // b.printEnergy();
    b.believe(0.0f, 0.9f, Tense.Present);
    b.run(1);
    // b.printEnergy();
    b.run(1);
    // b.printEnergy();
    b.print();
    assertEquals(2, b.size(true));
    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.run(1);
    // TODO test that they are sorted ?
    }
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) Test(org.junit.jupiter.api.Test)

Example 2 with BeliefAnalysis

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

the class RevisionTest method testRevision.

void testRevision(int delay1, boolean beliefOrGoal) {
    Param.DEBUG = true;
    NAR n = newNAR(6);
    // arbitrary time delays in which to observe that certain behavior does not happen
    BeliefAnalysis b = new BeliefAnalysis(n, x).input(beliefOrGoal, 1f, 0.9f).run(1);
    assertEquals(1, b.size(beliefOrGoal));
    b.input(beliefOrGoal, 0.0f, 0.9f).run(1);
    b.run(delay1);
    // b.print(beliefOrGoal);
    b.table(beliefOrGoal).print();
    assertEquals(3, b.size(beliefOrGoal));
    n.run(delay1);
    assertEquals(3, b.size(beliefOrGoal), "no additional revisions");
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis)

Example 3 with BeliefAnalysis

use of nars.test.analyze.BeliefAnalysis 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 4 with BeliefAnalysis

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

the class RevectionTest method testTemporalRevection.

@Test
public void testTemporalRevection() throws Narsese.NarseseException {
    Param.DEBUG = true;
    // includes 3 eternal beliefs we arent using:
    int maxBeliefs = 4;
    NAR n = newNAR(maxBeliefs);
    BeliefAnalysis b = new BeliefAnalysis(n, "<a-->b>");
    // assertEquals(0.0, (Double) b.energy().get(MemoryBudget.Budgeted.ActiveConceptPrioritySum), 0.001);
    b.believe(0.5f, 0.0f, 0.85f, 5);
    n.run();
    b.believe(0.5f, 0.95f, 0.85f, 10);
    n.run();
    // this and the previous one should get combined when inserting the 4th
    b.believe(0.5f, 1.0f, 0.85f, 11);
    n.run();
    b.print();
    assertTrue(3 <= b.size(true));
    assertEquals(5, b.wave().start());
    assertEquals(11, b.wave().end());
    // this should cause the cycle=10 and cycle=11 beliefs to get revected into one and allow this belief to be inserted
    b.believe(0.5f, 1.0f, 0.99f, 12);
    // the cycle=5 belief should remain since it is more unique
    n.run(3);
    b.print();
    assertEquals(4 + 4, b.capacity(true));
    assertEquals(4, b.size(true));
    b.print();
    assertEquals(5, b.wave().start());
    assertEquals(12, b.wave().end());
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) RevisionTest.newNAR(nars.task.RevisionTest.newNAR) Test(org.junit.jupiter.api.Test)

Example 5 with BeliefAnalysis

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

the class RevectionTest method testTemporalProjectionInterpolation.

@Test
public void testTemporalProjectionInterpolation() throws Narsese.NarseseException {
    Param.DEBUG = true;
    int maxBeliefs = 12;
    NAR n = newNAR(maxBeliefs);
    BeliefAnalysis b = new BeliefAnalysis(n, "<a-->b>");
    b.believe(0.5f, 1.0f, 0.85f, 5);
    b.believe(0.5f, 0.0f, 0.85f, 10);
    b.believe(0.5f, 1.0f, 0.85f, 15);
    b.run(1);
    assertTrue(3 <= b.size(true));
    int period = 1;
    int loops = 20;
    Set<Task> tops = new HashSet();
    for (int i = 0; i < loops; i++) {
        b.run(period);
        long now = b.nar.time();
        Task tt = n.belief(b.concept().term(), now);
        tops.add(tt);
        System.out.println(now + " " + tt);
    }
    assertTrue(3 <= tops.size(), "all beliefs covered");
    b.print();
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) RevisionTest.newNAR(nars.task.RevisionTest.newNAR) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

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