use of nars.NAR in project narchy by automenta.
the class SecondLevelUnificationTest method test1.
@Test
public void test1() throws Narsese.NarseseException {
// this.activeTasks = activeTasks;
NAR n = new NARS().get();
// n.log();
// n.eventTaskRemoved.on(t -> {
// //System.err.println("rm: " + t + " " + t.getLogLast());
// });
// en("all xs are opened by some y");
n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,open(#2,$1))>", 1.00f, 0.90f);
// en("z is a y");
n.believe("<{z} --> y>", 1.00f, 0.90f);
// tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> (/,open,{z},_)>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
n.run(250);
}
use of nars.NAR in project narchy by automenta.
the class SecondLevelUnificationTest method test2.
@Test
public void test2() throws Narsese.NarseseException {
// this.activeTasks = activeTasks;
NAR n = new NARS().get();
// n.log();
// n.eventTaskRemoved.on(t -> {
// //System.err.println("rm: " + t + " " + t.getLogLast());
// });
// en("all xs are opened by some y");
n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,<$1 --> #2>)>", 1.00f, 0.90f);
// en("z is a y");
n.believe("<{z} --> y>", 1.00f, 0.90f);
// tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> {z}>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
n.run(250);
}
use of nars.NAR in project narchy by automenta.
the class NAL7ImplProjectionTest method test1.
@Test
public void test1() {
int implDT = 5;
int dur = 1;
/* eventTime, relative to impl belief */
for (int implTime = 0; implTime < 5; implTime += 2) {
for (int eventTime = 0; eventTime < 5; eventTime += 2) {
Term y = $.the("y");
Param.DEBUG = true;
NAR n = NARS.tmp();
// n.log();
n.time.dur(dur);
n.inputAt(eventTime, "x. :|:");
n.inputAt(implTime, "(x ==>+" + implDT + " y). :|:");
int end = Math.max(eventTime + implDT, implTime);
n.run(end + 1);
double[] max = new MyBrentOptimizer(0.001f, 0.01, 0, end, (t) -> {
Truth u = n.beliefTruth(y, Math.round(t));
if (u == null)
return -1f;
return u.conf();
}).max(0, end, end / 2.0);
long yTimeEstimate = Math.round(max[0]);
long yTimeActual = eventTime + implDT;
assertTrue(Math.abs(yTimeEstimate - yTimeActual) <= 1);
double yConfMax = max[1];
long eventBeliefDelta = Math.abs(eventTime - implTime);
System.out.println("+-" + eventBeliefDelta + " -> " + max[0] + "=" + max[1]);
}
}
// double zero = UnivariateSolverUtils.solve(t->{
// return 0;
// }, 0, end, 0.01f);
// n.concept(x).print();
// n.concept(y).print();
}
use of nars.NAR in project narchy by automenta.
the class ImplicationNetworkTest method testEternal_A_PosBelief_ToBC.
@Test
public void testEternal_A_PosBelief_ToBC() {
NAR n = NARS.tmp();
Param.DEBUG = true;
n.believe(IMPL.the(a, b));
n.believe(IMPL.the(b, c));
n.believe(a);
n.run(100);
BeliefTable aBeliefs = n.concept(a).beliefs();
Truth aBelief = aBeliefs.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, aBeliefs.size());
BeliefTable bBeliefs = n.concept(b).beliefs();
Truth bBelief = bBeliefs.truth(ETERNAL, n);
// n.concept(b).print();
// assertEquals(1, bBeliefs.size());
// b should have less conf than a but higher than c
// same freq among all
Truth cBelief = n.concept(c).beliefs().truth(ETERNAL, n);
// n.concept(c).print();
System.out.println("a: " + aBelief);
System.out.println("b: " + bBelief);
System.out.println("c: " + cBelief);
assertEquals(aBelief.freq(), bBelief.freq(), n.freqResolution.floatValue());
assertEquals(bBelief.freq(), cBelief.freq(), n.freqResolution.floatValue());
assertTrue(aBelief.conf() - bBelief.conf() > n.confResolution.floatValue() * 2);
assertTrue(bBelief.conf() - cBelief.conf() > n.confResolution.floatValue() * 2);
}
use of nars.NAR 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());
}
Aggregations