use of nars.NAR in project narchy by automenta.
the class NARTest method testCycleScheduling.
@Test
public void testCycleScheduling() {
NAR n = NARS.tmp();
final int[] runs = { 0 };
long[] events = { 2, 4, 4 /* test repeat */
};
for (long w : events) {
n.at(w, () -> {
assertEquals(w, n.time());
runs[0]++;
});
}
n.run(1);
assertEquals(0, runs[0]);
/* nothing yet in that 1st cycle */
n.run((int) Longs.max(events));
assertEquals(events.length, runs[0]);
}
use of nars.NAR in project narchy by automenta.
the class WorkerMultiExecTest method testValueDerivationBranches.
@Test
public void testValueDerivationBranches() throws Narsese.NarseseException {
// int threads = 1;
// Exec exe = new MultiExec(32, threads, 2);
Exec exe = new UniExec(32);
NAR n = new NARS().deriverAdd(1, 1).deriverAdd(6, 6).exe(exe).get();
// all -1 except goal production
Arrays.fill(n.emotion.want, -1);
n.emotion.want(MetaGoal.Desire, +1);
Exec.Revaluator r = new Focus.DefaultRevaluator();
int cycles = 100;
// 2 competing independent processes. NAL1 rules will apply to one, and NAL6 rules apply to ther other.
// measure the amount of derivation work occurring for each
ByteIntHashMap byPunc = new ByteIntHashMap();
n.onTask(t -> {
if (t instanceof DerivedTask) {
byPunc.addToValue(t.punc(), 1);
}
});
n.log();
n.input("(x==>y).");
n.input("f:a.");
for (int i = 0; i < cycles; i++) {
n.input("f:b. :|:");
n.input("x! :|:");
n.run(1);
r.update(n);
}
System.out.println(byPunc);
n.causes.forEach(c -> {
double sum = Util.sum((ToDoubleFunction<Traffic>) (t -> t.total), c.goal);
if (sum > Double.MIN_NORMAL) {
System.out.println(Arrays.toString(c.goal) + "\t" + c);
}
});
}
use of nars.NAR in project narchy by automenta.
the class ListFuncTest method testAppendTransform.
@Test
public void testAppendTransform() {
NAR n = NARS.shell();
assertEquals(Set.of($$("(x,y)")), Solution.solve($$("append((x),(y))"), n.concepts.functors));
assertEquals(Set.of($$("append(#x,(y))")), Solution.solve($$("append(#x,(y))"), n.concepts.functors));
}
use of nars.NAR in project narchy by automenta.
the class ListFuncTest method testAppendResult.
@Test
public void testAppendResult() {
NAR n = NARS.shell();
// solve result
assertEquals(Set.of($$("append((x),(y),(x,y))")), Solution.solve($$("append((x),(y),#what)"), n.concepts.functors));
// solve result in multiple instances
assertEquals(Set.of($$("(append((x),(y),(x,y)) && ((x,y)<->solution))")), Solution.solve($$("(append((x),(y),#what) && (#what<->solution))"), n.concepts.functors));
}
use of nars.NAR in project narchy by automenta.
the class ExeCharts method metaGoalControls.
public static Surface metaGoalControls(NAR n) {
CheckBox auto = new CheckBox("Auto");
auto.set(false);
float[] want = n.emotion.want;
Gridding g = grid(// Stream.of(auto),
IntStream.range(0, want.length).mapToObj(w -> new FloatSlider(want[w], -1f, +1f) {
@Override
protected void paintWidget(GL2 gl, RectFloat2D bounds) {
if (auto.on()) {
value(want[w]);
}
}
}.text(MetaGoal.values()[w].name()).type(BaseSlider.Knob).on((s, v) -> {
if (!auto.on())
want[w] = v;
})).toArray(Surface[]::new));
return g;
}
Aggregations