use of nars.NAR in project narchy by automenta.
the class QueryVariableTest method testQueryAnswered.
void testQueryAnswered(int cyclesBeforeQuestion, int cyclesAfterQuestion) throws Narsese.NarseseException {
AtomicBoolean b = new AtomicBoolean(false);
String question = cyclesBeforeQuestion == 0 ? "<a --> b>" : /* unknown solution to be derived */
"<b --> a>";
// this.activeTasks = activeTasks;
NAR n = NARS.tmpEternal();
n.input("<a <-> b>. %1.0;0.5%", "<b --> a>. %1.0;0.5%");
n.run(cyclesBeforeQuestion);
n.question(question, ETERNAL, (q, a) -> {
if (!a.isDeleted())
b.set(true);
});
n.stopIf(b::get);
n.run(cyclesAfterQuestion);
assertTrue(b.get());
}
use of nars.NAR in project narchy by automenta.
the class TruthletTaskTest method test_LinearTruthlet_And_SustainTruthlet.
@Test
public void test_LinearTruthlet_And_SustainTruthlet() {
float conf = 0.9f;
RangeTruthlet s = Truthlet.slope(0, 1f, 3, 0f, c2w(conf));
for (Truthlet t : new Truthlet[] { s, new SustainTruthlet(s, 1) }) {
NAR n = NARS.shell();
Term x = $.the("x");
System.out.println(t);
n.input(new TruthletTask(x, BELIEF, t, n));
BeliefTable xb = n.truths(x, BELIEF);
for (int i = -3; i < 7; i++) {
Truth ti = xb.truth(i, n);
if (i < 0 || i > 3) {
if (t instanceof SustainTruthlet) {
// fade out
assertTrue(ti.conf() < 0.9f);
} else {
assertNull(ti);
}
} else {
assertEquals(0.9f, ti.conf());
float f = ti.freq();
switch(i) {
case 0:
assertEquals(1f, f, 0.01f);
break;
case 1:
assertEquals(0.666f, f, 0.01f);
break;
case 2:
assertEquals(0.333f, f, 0.01f);
break;
case 3:
assertEquals(0f, f, 0.01f);
break;
}
}
System.out.println(i + ": " + ti);
}
}
}
use of nars.NAR in project narchy by automenta.
the class TemporalInductionTest method testTemporalRevisionOfTemporalRelation.
@Test
public void testTemporalRevisionOfTemporalRelation() throws Narsese.NarseseException {
NAR n = NARS.tmp();
// TextOutput.out(n);
n.input("(a ==>+0 b). %1.0;0.7%");
n.input("(a ==>+5 b). %1.0;0.6%");
n.run(1);
// n.forEachActiveConcept(Concept::print);
// Concept c = n.concept("a:b");
// assertEquals("(b-->a). 5+0 %.50;.95%", c.getBeliefs().top().toStringWithoutBudget());
}
use of nars.NAR in project narchy by automenta.
the class TemporalInductionTest method testInductionStability.
@Test
public void testInductionStability() throws Narsese.NarseseException {
// two entirely disjoint events, and all inductable beliefs from them, should produce a finite system that doesn't explode
NAR d = NARS.tmp();
d.input("a:b. :|:");
d.run(5);
d.input("c:d. :|:");
d.run(200);
// everything should be inducted by now:
int before = d.concepts.size();
int numBeliefs = getBeliefCount(d);
// System.out.println(numConcepts + " " + numBeliefs);
d.run(60);
// # unique concepts unchanged:
int after = d.concepts.size();
assertEquals(before, after);
// assertEquals(numBeliefs, getBeliefCount(d));
}
use of nars.NAR in project narchy by automenta.
the class TemporalStabilityTests method testTemporalStabilityLinkedImplExt2.
@Test
public void testTemporalStabilityLinkedImplExt2() {
// Param.DEBUG = true;
@NotNull NAR n = NARS.tmp();
int time = CYCLES;
T1 a = new T1(linkedimpl, 1, 2, 5, 10);
T1 b = new T1(linkedinh, 1, 2, 5, 10);
a.test(-1, n);
b.test(-1, n);
n.run(time);
// a.evaluate(n);
// b.evaluate(n);
}
Aggregations