use of nars.truth.Truth in project narchy by automenta.
the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToBC.
@Test
public void testEternal_A_NegBelief_NegToBC() {
NAR n = NARS.tmp(6);
n.termVolumeMax.set(16);
Param.DEBUG = true;
n.believe(IMPL.the(a.neg(), b));
n.believe(IMPL.the(b, c));
n.believe(a.neg());
n.run(800);
BeliefTable aa = n.concept(a).beliefs();
BeliefTable bb = n.concept(b).beliefs();
BeliefTable cc = n.concept(c).beliefs();
aa.print();
bb.print();
// cc.print();
cc.forEachTask(x -> System.out.println(x.proof()));
// assertEquals(1, aBeliefs.size());
Truth bBelief = bb.truth(ETERNAL, n);
Truth cBelief = cc.truth(ETERNAL, n);
assertEquals("%1.0;.81%", bBelief.toString());
assertEquals("%1.0;.73%", cBelief.toString());
}
use of nars.truth.Truth in project narchy by automenta.
the class ImplicationNetworkTest method testEternal_A_PosGoal_ToBC.
@Test
public void testEternal_A_PosGoal_ToBC() {
NAR n = NARS.tmp();
Param.DEBUG = true;
n.believe(IMPL.the(a, b));
n.believe(IMPL.the(b, c));
n.goal(a);
n.run(100);
BeliefTable aGoals = n.concept(a).goals();
Truth aGoal = aGoals.truth(ETERNAL, n);
// n.concept(a).print();
// a belief state should not exceed the input (default confidence) and freq remain stable
// additional beliefs are not helpful
assertEquals(1, aGoals.size());
BeliefTable bGoals = n.concept(b).goals();
Truth bGoal = bGoals.truth(ETERNAL, n);
n.concept(b).print();
assertEquals(1, bGoals.size());
// b should have less conf than a but higher than c
// same freq among all
BeliefTable cGoals = n.concept(c).goals();
Truth cGoal = cGoals.truth(ETERNAL, n);
n.concept(c).print();
// assertEquals(1, cGoals.size());
System.out.println("a: " + aGoal);
System.out.println("b: " + bGoal);
System.out.println("c: " + cGoal);
assertEquals(aGoal.freq(), bGoal.freq(), n.freqResolution.floatValue());
assertEquals(bGoal.freq(), cGoal.freq(), n.freqResolution.floatValue());
assertTrue(aGoal.conf() - bGoal.conf() > n.confResolution.floatValue() * 2);
assertTrue(bGoal.conf() - cGoal.conf() > n.confResolution.floatValue() * 2);
}
use of nars.truth.Truth in project narchy by automenta.
the class NarseseTest method testTruth.
void testTruth(String t, float freq, float conf) throws Narsese.NarseseException {
String s = "a:b. " + t;
Truth truth = task(s).truth();
assertEquals(freq, truth.freq(), 0.001);
assertEquals(conf, truth.conf(), 0.001);
}
use of nars.truth.Truth 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);
}
use of nars.truth.Truth in project narchy by automenta.
the class TruthletTaskTest method testImpulseTruthlet.
@Test
public void testImpulseTruthlet() {
NAR n = NARS.shell();
Term x = $.the("x");
float conf = 0.9f;
n.input(new TruthletTask(x, BELIEF, Truthlet.impulse(1, 2, 1f, 0f, c2w(conf)), n));
BeliefTable xb = n.truths(x, BELIEF);
for (int i = -1; i < 5; i++) {
Truth ti = xb.truth(i, n);
assertEquals((i <= 0 || i >= 3) ? 0 : 1, ti.freq());
if (i >= 1 && i <= 2)
assertEquals(conf, ti.conf());
else
assertTrue(conf > ti.conf());
System.out.println(i + ": " + ti);
}
}
Aggregations