use of nars.NAR in project narchy by automenta.
the class Line1DQ method main.
public static void main(String[] args) {
// Param.DEBUG = true;
NAR n = new NARS().get();
// n.log();
n.time.dur(5);
Line1DSimplest a = new Line1DSimplest();
a.curiosity.set(0.01f);
a.onFrame((z) -> {
a.target(Util.unitize(// (float) (0.5f * (Math.sin(n.time() / 50f) + 1f))
(Math.abs(3484 ^ n.time() / 200) % 11) / 10.0f));
});
// Arkancide a = new Arkancide(n, false, true);
// Tetris a = new Tetris(n, 6, 10, 4);
// a.onFrame(x -> Util.sleep(1));
// a.trace = true;
// Line1DTrainer trainer = new Line1DTrainer(a);
// new RLBooster(a, new HaiQAgent(), 2); n.deriver.rate.setValue(0); a.curiosity.setValue(0f);
NAgentX.chart(a);
// int h = q.ae.W[0].length;
// int w = q.ae.W.length;
// window( grid(
// new MatrixView(w, h, MatrixView.arrayRenderer(q.ae.W)),
// new MatrixView(w, 1, MatrixView.arrayRenderer(q.ae.y)),
// new MatrixView(w, 1, MatrixView.arrayRenderer(q.ae.z))
// ), 500, 500);
float grandTotal = 0;
for (int i = 0; i < 100; i++) {
int period = 1000;
// a.runCycles(period);
}
System.err.println(" grand total = " + grandTotal);
}
use of nars.NAR in project narchy by automenta.
the class ConnectFour method main.
public static void main(String[] args) {
NAR n = NARS.tmp();
n.log();
Opjects o = new Opjects(n);
ConnectFourState game = o.a("c", ConnectFourState.class);
JFrame frame = constructApplicationFrame(game);
frame.setSize(450, 450);
frame.setVisible(true);
while (true) {
switch(game.moving()) {
case 1:
game.drop(n.random().nextInt(game.cols));
break;
case 2:
game.drop(n.random().nextInt(game.cols));
break;
}
frame.repaint();
n.run(1);
Util.sleep(25);
if (game.isTerminal())
game.clear();
}
}
use of nars.NAR in project narchy by automenta.
the class SATStream method main.
public static void main(String[] args) throws Narsese.NarseseException {
// this.activeTasks = activeTasks;
NAR d = new NARS().get();
// d.inputActivation.setValue(0.2f);
d.log();
d.input("$0.1;0.2;0.5$ T:x1. :|:", "$0.1;0.2;0.5$ T:x2. :|:", "$0.1;0.2;0.5$ T:(--,x3). :|:", "$0.1;0.2;0.5$ T:(--,x4). :|:", "$1.0;1.0;1.0$ (($c:$x && $c:$y) ==> AND({$x,$y})). %1.00;1.00%");
d.run(10360);
// d.dumpConcepts("/tmp/x.txt");
}
use of nars.NAR in project narchy by automenta.
the class Conclude method match.
public static void match(final DeriveRuleProto rule, List<PrediTerm<PreDerivation>> pre, List<PrediTerm<Derivation>> post, PatternIndex index, NAR nar) {
Term pattern = rule.conclusion().sub(0);
// TODO may interfere with constraints, functors, etc or other features, ie.
// if the pattern is a product for example?
// pattern = pattern.replace(ta, Derivation._taskTerm);
// determine if any cases where a shortcut like this can work (ie. no constraints, not a product etc)
// //substitute compound occurrences of the exact task and belief terms with the short-cut
// Term ta = rule.getTask();
// if (!ta.op().var) {
// if (pattern.equals(ta))
// pattern = Derivation.TaskTerm;
// }
// Term tb = rule.getBelief();
// if (!tb.op().var) {
// //pattern = pattern.replace(tb, Derivation._beliefTerm);
// if (pattern.equals(tb))
// pattern = Derivation.BeliefTerm;
// }
// HACK unwrap varIntro so we can apply it at the end of the derivation process, not before like other functors
boolean introVars1;
Pair<Termed, Term> outerFunctor = Op.functor(pattern, (i) -> i.equals(VAR_INTRO) ? VAR_INTRO : null);
if (outerFunctor != null) {
introVars1 = true;
pattern = outerFunctor.getTwo().sub(0);
} else {
introVars1 = false;
}
pattern = index.get(pattern, true).term();
Taskify taskify = new Taskify(nar.newCause((s) -> new RuleCause(rule, s)));
PrediTerm<Derivation> conc = AndCondition.the(new Termify($.func("derive", pattern), pattern, rule), introVars1 ? AndCondition.the(introVars, taskify) : taskify);
final Term taskPattern = rule.getTask();
final Term beliefPattern = rule.getBelief();
Op to = taskPattern.op();
boolean taskIsPatVar = to == Op.VAR_PATTERN;
Op bo = beliefPattern.op();
boolean belIsPatVar = bo == Op.VAR_PATTERN;
if (!taskIsPatVar) {
pre.add(new TaskBeliefOp(to, true, false));
pre.addAll(SubTermStructure.get(0, taskPattern.structure()));
}
if (!belIsPatVar) {
if (to == bo) {
pre.add(new AbstractPatternOp.TaskBeliefOpEqual());
} else {
pre.add(new TaskBeliefOp(bo, false, true));
pre.addAll(SubTermStructure.get(1, beliefPattern.structure()));
}
}
if (taskPattern.equals(beliefPattern)) {
post.add(new UnifyTerm.UnifySubtermThenConclude(0, taskPattern, conc));
}
if (taskFirst(taskPattern, beliefPattern)) {
// task first
post.add(new UnifyTerm.UnifySubterm(0, taskPattern));
post.add(new UnifyTerm.UnifySubtermThenConclude(1, beliefPattern, conc));
} else {
// belief first
post.add(new UnifyTerm.UnifySubterm(1, beliefPattern));
post.add(new UnifyTerm.UnifySubtermThenConclude(0, taskPattern, conc));
}
// Term beliefPattern = pattern.term(1);
// if (Global.DEBUG) {
// if (beliefPattern.structure() == 0) {
// if nothing else in the rule involves this term
// which will be a singular VAR_PATTERN variable
// then allow null
// if (beliefPattern.op() != Op.VAR_PATTERN)
// throw new RuntimeException("not what was expected");
// }
// }
/*System.out.println( Long.toBinaryString(
pStructure) + " " + pattern
);*/
}
use of nars.NAR in project narchy by automenta.
the class LinkageTest method ProperlyLinkedIndirectlyTest.
// interlinked with an intermediate concept, this is needed in order to select one as task and the other as belief
public void ProperlyLinkedIndirectlyTest(@NotNull String spremise1, byte punc, @NotNull String spremise2) throws Exception {
test.requireConditions = false;
NAR nar = test.nar;
// nar.log();
Termed premise1 = $.$(spremise1);
assertEquals($.$(spremise1), premise1, "reparsed");
assertNotNull(premise1);
assertEquals($.$(spremise1), premise1);
Termed premise2 = $.$(spremise2);
assertEquals($.$(spremise2), premise2, "reparsed");
assertNotNull(premise2);
assertEquals($.$(spremise2), premise2);
String t1 = getTask(punc, premise1);
String t2 = getTask(punc, premise2);
nar.input(t1, t2).run(runCycles);
// List<String> fails = new ArrayList();
@Nullable Concept p1 = nar.concept(premise1);
assertNotNull(p1.state());
// p1.print(); System.out.println("------------------------");
Concept p2 = nar.concept(premise2);
assertNotNull(p2);
assertNotNull(p2.state());
// c2.print(); System.out.println("------------------------");
AdjGraph<Term, Float> g = TermGraph.termlink(nar);
boolean p12 = linksIndirectly(p1, p2, nar);
assertTrue(p12, why(nar, premise1, premise2));
boolean p21 = linksIndirectly(p2, p1, nar);
assertTrue(p21, why(nar, premise2, premise1));
System.err.println(premise1 + " not linked with " + premise2);
int numNodes = g.nodeCount();
assertTrue(numNodes > 0);
assertTrue(g.edgeCount() > 0, g.toString());
// for (Term x : g.nodes()) {
// assertEquals(x + " not reachable by all other nodes", numNodes, Graphs.reachableNodes(g.asGraph(), x).size());
// }
// //g.print(System.out);
// //System.out.println(g.isConnected() + " " + g.vertexSet().size() + " " + g.edgeSet().size());
// if (!g.isConnected()) {
// // if (!g.isStronglyConnected()) {
// // StrongConnectivityInspector ci =
// ConnectivityInspector ci = new ConnectivityInspector(g);
// // new StrongConnectivityInspector(g);
//
// System.out.println("premises: " + premise1 + " and " + premise2 + " termlink subgraph connectivity:");
//
// ci
// .connectedSets()
// //.stronglyConnectedSubgraphs()
// .forEach( s -> System.out.println("\t" + s));
//
// nar.forEachConceptActive(x -> x.get().print());
//
// }
// assertTrue(g.isConnected());
}
Aggregations