Search in sources :

Example 16 with BeliefTable

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

the class TruthWave method project.

/**
 * fills the wave with evenly sampled points in a time range
 */
public void project(Concept c, boolean beliefOrGoal, long minT, long maxT, int dur, int points, NAR nar) {
    clear();
    if (minT == maxT) {
        return;
    }
    size(points);
    float dt = (maxT - minT) / ((float) points);
    long t = minT;
    float[] data = this.truth;
    int j = 0;
    int idt = (int) Math.ceil(dt);
    byte punc = beliefOrGoal ? BELIEF : GOAL;
    BeliefTable table = (BeliefTable) c.table(punc);
    for (int i = 0; i < points; i++) {
        long u = t + idt;
        long mid = (t + u) / 2;
        load(data, (j++) * ENTRY_SIZE, // table.truth(mid, nar) //point
        t, u, // range
        table.truth(t, u, nar));
        t = (long) (t + dt);
    }
    this.current = null;
    this.size = j;
    this.start = minT;
    this.end = maxT;
}
Also used : BeliefTable(nars.table.BeliefTable)

Example 17 with BeliefTable

use of nars.table.BeliefTable 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)

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