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;
}
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());
}
Aggregations