use of nars.test.TestNAR in project narchy by automenta.
the class NAL8EternalMixTest method goal_deduction_impl_after.
@Test
public void goal_deduction_impl_after() {
TestNAR tester = test;
tester.input("x:y! :|:");
tester.input("(goto(z) ==>-5 x:y).");
tester.mustGoal(cycles, "goto(z)", 1.0f, 0.45f, 5);
}
use of nars.test.TestNAR in project narchy by automenta.
the class NAL8EternalMixTest method subgoal_1_abd.
@Test
public void subgoal_1_abd() {
TestNAR tester = test;
tester.input("opened:{t001}. :|:");
tester.input("((hold(SELF,{t002}) &&+5 ( at(SELF,{t001}) &&+5 open({t001}))) ==>+5 opened:{t001}).");
tester.mustBelieve(cycles, "( hold(SELF,{t002}) &&+5 ( at(SELF,{t001}) &&+5 open({t001})))", 1.0f, 0.45f, -15);
}
use of nars.test.TestNAR in project narchy by automenta.
the class NAL8EternalMixTest method ded_with_indep_var_temporal.
@Test
public void ded_with_indep_var_temporal() {
TestNAR tester = test;
tester.input("goto({t003}). :|:");
tester.inputAt(10, "(goto($1) ==>+5 at(SELF,$1)).");
tester.mustBelieve(cycles, "at(SELF,{t003})", 1.0f, 0.81f, 5);
}
use of nars.test.TestNAR in project narchy by automenta.
the class NAL8TestExt method subsent_simultaneous.
@Test
public void subsent_simultaneous() {
TestNAR tester = test;
// TODO decide correct parentheses ordering
// tester.nar.log();
tester.input("[opened]:t1. :|:");
tester.inputAt(10, "(hold:t2 &&+0 (at:t1 &&+0 (open(t1) &&+0 [opened]:t1))).");
// TODO Narsese parser for this:
// tester.mustBelieve(cycles, "( &&+0 ,(t1-->at),(t2-->hold),(t1-->[opened]),open(t1))",
tester.mustBelieve(cycles, "( && ,(t1-->at),(t2-->hold),(t1-->[opened]),open(t1))", 1.0f, 0.43f, 0);
tester.mustBelieve(cycles, "(&&, hold:t2, at:t1, open(t1)).", 1.0f, 0.81f, ETERNAL);
}
use of nars.test.TestNAR in project narchy by automenta.
the class QuestionTest method questionDrivesInference.
// @Test public void testQuestionHandler() throws Narsese.NarseseException {
// NAR nar = NARS.shell();
//
// final int[] s = {0};
// new TaskMatch("add(%1, %2, #x)", nar) {
//
// @Override public boolean test(@NotNull Task task) { return task.isQuestOrQuestion(); }
//
// @Override
// protected void accept(Task task, Map<Term, Term> xy) {
// System.out.println(task + " " + xy);
// s[0] = xy.size();
// }
// };
//
// nar.ask($.$("add(1, 2, #x)"));
//
// assertEquals(3, s[0]);
//
// }
// @Test public void testOperationHandler() throws Narsese.NarseseException {
// NAR nar = NARS.shell();
//
// final int[] s = {0};
// StringBuilder match = new StringBuilder();
// new OperationTaskMatch( $.$("add(%1, %2, #x)"), nar) {
//
// @Override public boolean test(@NotNull Task task) { return task.isQuestOrQuestion(); }
//
// @Override
// protected void onMatch(Term[] args) {
// match.append(Arrays.toString(args)).append(' ');
// }
// };
//
// nar.ask($.$("add(1, 2, #x)"));
//
// assertTrue(match.toString().contains("[1, 2, #1026]"));
//
// nar.ask($.$("add(1, #x)"));
// nar.ask($.$("(#x --> add)"));
//
// assertFalse(match.toString().contains("[1, #1026]"));
// }
/**
* tests whether the use of a question guides inference as measured by the speed to reach a specific conclusion
*/
@Test
public void questionDrivesInference() {
final int[] dims = { 3, 2 };
final int timelimit = 2400;
TaskStatistics withTasks = new TaskStatistics();
TaskStatistics withoutTasks = new TaskStatistics();
DoubleSummaryStatistics withTime = new DoubleSummaryStatistics();
DoubleSummaryStatistics withOutTime = new DoubleSummaryStatistics();
IntFunction<NAR> narProvider = (seed) -> {
NAR d = NARS.tmp(1);
d.random().setSeed(seed);
d.termVolumeMax.set(16);
d.freqResolution.set(0.1f);
return d;
};
BiFunction<Integer, Integer, TestNAR> testProvider = (seed, variation) -> {
NAR n = narProvider.apply(seed);
TestNAR t = new TestNAR(n);
switch(variation) {
case 0:
new DeductiveMeshTest(t, dims, timelimit);
break;
case 1:
new DeductiveMeshTest(t, dims, timelimit) {
@Override
public void ask(@NotNull TestNAR n, Term term) {
// disabled
}
};
break;
}
return t;
};
for (int i = 0; i < 10; i++) {
int seed = i + 1;
TestNAR withQuestion = testProvider.apply(seed, 0);
withQuestion.test(true);
withTime.accept(withQuestion.time());
withTasks.add(withQuestion.nar);
TestNAR withoutQuestion = testProvider.apply(seed, 1);
withoutQuestion.test(true);
withOutTime.accept(withoutQuestion.time());
withoutTasks.add(withoutQuestion.nar);
}
withTasks.print();
withoutTasks.print();
assertNotEquals(withTime, withOutTime);
System.out.println("with: " + withTime);
System.out.println("withOut: " + withOutTime);
// assertTrue(withTime.getSum() < withOutTime.getSum());
// assertTrue(withTime.getSum() < 2 * withOutTime.getSum()); //less than half, considering that a search "diameter" becomes a "radius" by providing the answer end-point
}
Aggregations