use of nars.derive.Deriver in project narchy by automenta.
the class TrackXY method main.
public static void main(String[] args) {
boolean nars = true;
boolean rl = false;
int dur = 1;
NARS nb = new NARS().exe(new UniExec(64)).time(new CycleTime().dur(dur)).index(// new HijackConceptIndex(4 * 1024, 4)
new CaffeineIndex(32 * 1024));
NAR n = nb.get();
n.termVolumeMax.set(20);
// n.priDefault(BELIEF, 0.2f);
// n.priDefault(GOAL, 0.5f);
n.activationRate.set(0.2f);
// n.forgetRate.set(0.9f);
TrackXY t = new TrackXY(4, 4);
n.on(t);
int experimentTime = 8048;
n.synch();
if (rl) {
new RLBooster(t, // HaiQ::new,
HaiQae::new, // RandomAgent::new,
1);
t.curiosity.set(0);
}
if (nars) {
// Param.DEBUG = true;
// n.log();
// for (String action : new String[]{"up", "down", "left", "right"}) {
// //n.goal($.the(action), Tense.Present, 0f, 0.1f);
// n.goal($.the(action), Tense.Present, 1f, 0.1f);
// }
Deriver d = new Deriver(Derivers.rules(// 1,
1, 8, n, // "list.nal",
"motivation.nal"), n);
d.conceptsPerIteration.set(32);
n.timeFocus.set(2);
ConjClustering cjB = new ConjClustering(n, BELIEF, // (tt)->true,
(tt) -> tt.isInput(), 4, 16);
// ConjClustering cjG = new ConjClustering(n, GOAL,
// (tt)->true,
// //(tt) -> tt.isInput(),
// 5, 16);
// Implier ii = new Implier(t , 0, 1);
// ArithmeticIntroduction ai = new ArithmeticIntroduction(4, n);
window(new Gridding(new AutoSurface(d), new AutoSurface(cjB)), 400, 300);
n.onTask(tt -> {
if (tt instanceof DerivedTask && tt.isGoal()) {
System.out.println(tt.proof());
}
});
}
// n.log();
// n.startFPS(fps);
// t.runFPS(fps);
n.onCycle(t);
final double[] rewardSum = { 0 };
n.onCycle(() -> {
rewardSum[0] += t.reward;
});
n.runLater(() -> {
window(Vis.top(n), 800, 250);
NAgentX.chart(t);
window(new CameraSensorView(t.cam, n) {
@Override
protected void paint(GL2 gl, int dtMS) {
super.paint(gl, dtMS);
RectFloat2D at = cellRect(t.sx, t.sy, 0.5f, 0.5f);
gl.glColor4f(1, 0, 0, 0.9f);
Draw.rect(gl, at.move(x(), y(), 0.01f));
}
}.withControls(), 800, 800);
});
n.run(experimentTime);
// n.startFPS(10f);
// t.runFPS(10f);
// System.out.println(
//
// n4(rewardSum[0] / n.time()) + " avg reward");
// System.exit(0);
}
use of nars.derive.Deriver in project narchy by automenta.
the class NAgentTest method testSameCheat.
// n.onTask(t->{
// if (t.isGoal()) {
// if (t.term().equals(action))
// System.out.println(t.start() + ".." + t.end() + "\t" + t.proof());
// }
// });
@Test
public void testSameCheat() {
Param.DEBUG = true;
NAR n = new NARS().get();
Term action = $.$$("(t,y)");
Deriver d = new Deriver(n.exe::fire, (Collection<Task> x) -> {
// HACK TODO this is more efficiently done by filtering the rules rather than the results!
Collection<Task> filtered = Collections2.filter(x, Task::isGoal);
if (!filtered.isEmpty()) {
// System.out.println(filtered);
Collection<Task> filterAction = Collections2.filter(filtered, (t) -> t.term().equals(action));
filterAction.forEach(t -> {
System.out.println(t.proof());
System.out.println();
});
}
n.input(filtered);
}, Derivers.rules(1, 8, n).compile(), n);
new STMLinkage(n, 1, false);
d.conceptsPerIteration.set(8);
// n.log();
MiniTest a = new ToggleSame(n, $.the("t"), // $.$safe("t:y"),
action, true);
// n.onCycle(a::run);
// n.run(100);
// n.goal("(t,y)", Tense.Present, 1f);
n.synch();
Term ax = IMPL.the(action, 0, a.happy.filter[0].term);
n.believe(ax, Tense.Present);
a.runSynch(1500);
assertTrue(a.avgReward() > 0.1f);
assertTrue(a.dex.getMean() > 0f);
}
Aggregations