use of org.eclipse.collections.api.block.function.primitive.LongToFloatFunction 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);
}
Aggregations