use of nars.NAR 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);
}
}
use of nars.NAR in project narchy by automenta.
the class ArithmeticTest method testMul.
@Test
public void testMul() throws Narsese.NarseseException {
NAR t = NARS.shell();
assertEquals("0", $.$("mul(x,0)").eval(t.concepts.functors).toString());
assertEquals("x", $.$("mul(x,1)").eval(t.concepts.functors).toString());
}
use of nars.NAR in project narchy by automenta.
the class ArithmeticTest method testCompleteAddInduction.
@Test
public void testCompleteAddInduction() throws Narsese.NarseseException {
NAR n = NARS.tmp();
new ArithmeticIntroduction(16, n);
TestNAR t = new TestNAR(n);
t.confTolerance(0.8f);
t.log();
// t.believe("(x:1,x:2)");
// t.believe("(x:2,x:3)");
// t.believe("(x:3,x:4)");
// t.believe("(x:4,x:5)");
// t.ask("(x:5,?1)");
// t.mustBelieve(1000, "(x:5,x:6)", 1f, 0.81f);
t.believe("(a,1)");
t.believe("(a,2)");
t.believe("(a,3)");
t.believe("(a,4)");
t.ask("(a,#x)");
t.mustBelieve(1000, // "((a,add(#1,1))&&(#1<->4))",
"((a,add($1,1))==>(#1<->4))", 1f, 0.81f);
t.mustBelieve(1000, "(a,5)", 1f, 0.81f);
t.test(true);
}
use of nars.NAR in project narchy by automenta.
the class ConjClusteringTest method testSameTruthSameTime.
@Test
public void testSameTruthSameTime() throws Narsese.NarseseException {
NAR n = NARS.shell();
int ccap = 4;
ConjClustering c = new ConjClustering(n, BELIEF, (t) -> t.isInput(), 4, ccap);
n.log();
for (int i = 0; i < ccap; i++) n.believe($.the("x" + i), Tense.Present);
n.run(1);
assertEquals(1, n.concept($.$("(&&,x0,x1,x2,x3)")).beliefs().size());
}
use of nars.NAR in project narchy by automenta.
the class RuleInductionTest method test1.
@Test
public void test1() {
int dur = 1;
int loops = 10;
int period = 2;
int dutyPeriod = 1;
NAR n = NARS.tmp();
n.termVolumeMax.set(3);
// n.log();
// dense proressing
Deriver.derivers(n).forEach(d -> d.conceptsPerIteration.set(64));
n.time.dur(dur);
Term aConjB = $$("(a &&+" + dutyPeriod + " b)");
float lastAConjB_exp = 0;
PairedStatsAccumulator aConjB_exp = new PairedStatsAccumulator();
for (int i = 0; i < loops; i++) {
// n.clear(); //distraction clear
n.believe("a", Tense.Present, 1, 0.9f);
if (i > 0) {
// TODO test that the newest tasklink inserted into concept 'a' is the, or nearly the strongest
// n.concept("a").tasklinks().print();
}
n.run(dutyPeriod);
n.believe("b", Tense.Present, 1, 0.9f);
// delay
n.run(period - dutyPeriod);
long now = n.time();
System.out.println("\n" + now);
Truth aConjB_truth = n.belief(aConjB, now).truth(now, n.dur());
System.out.println(aConjB_truth);
n.conceptualize(aConjB).beliefs().print();
float exp = aConjB_truth.expectation();
if (!(exp >= lastAConjB_exp)) {
// for debug
Task tt = n.belief(aConjB, now);
}
// assertTrue(exp > lastAConjB_exp); //increasing
aConjB_exp.add(now, exp);
lastAConjB_exp = exp;
}
System.out.println(aConjB_exp.yStats());
System.out.println("slope=" + aConjB_exp.leastSquaresFit().slope());
// rising confidence
assertTrue(aConjB_exp.leastSquaresFit().slope() > 0);
}
Aggregations