use of nars.test.DeductiveMeshTest 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
}
use of nars.test.DeductiveMeshTest in project narchy by automenta.
the class MetaGoalTest method test1.
@Test
public void test1() {
NAR n = NARS.tmp(6);
n.emotion.want(MetaGoal.Believe, 0.05f);
n.emotion.want(MetaGoal.Perceive, -0.05f);
n.log();
DeductiveMeshTest m = new DeductiveMeshTest(n, new int[] { 3, 3 }, 3500);
m.test.test(true);
// n.run(500);
analyzeCauses(n);
}
Aggregations