Search in sources :

Example 91 with NAR

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);
}
Also used : NARS(nars.NARS) Line1DSimplest(nars.test.agent.Line1DSimplest) NAR(nars.NAR)

Example 92 with NAR

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();
    }
}
Also used : Opjects(nars.op.java.Opjects) NAR(nars.NAR)

Example 93 with NAR

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");
}
Also used : NARS(nars.NARS) NAR(nars.NAR)

Example 94 with NAR

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
        );*/
}
Also used : DepIndepVarIntroduction(nars.op.DepIndepVarIntroduction) PrediTerm(nars.term.pred.PrediTerm) AbstractPatternOp(nars.derive.op.AbstractPatternOp) nars.$(nars.$) DeriveRuleSource(nars.derive.rule.DeriveRuleSource) AndCondition(nars.term.pred.AndCondition) UnifyTerm(nars.derive.op.UnifyTerm) AbstractPred(nars.term.pred.AbstractPred) Nullable(org.jetbrains.annotations.Nullable) VAR_INTRO(nars.derive.Conclude.IntroVars.VAR_INTRO) Task(nars.Task) List(java.util.List) TaskBeliefOp(nars.derive.op.TaskBeliefOp) NAR(nars.NAR) Op(nars.Op) DeriveRuleProto(nars.derive.rule.DeriveRuleProto) PatternIndex(nars.index.term.PatternIndex) Map(java.util.Map) SubTermStructure(nars.derive.op.SubTermStructure) Termed(nars.term.Termed) Cause(nars.control.Cause) Pair(org.eclipse.collections.api.tuple.Pair) Term(nars.term.Term) AbstractPatternOp(nars.derive.op.AbstractPatternOp) TaskBeliefOp(nars.derive.op.TaskBeliefOp) Op(nars.Op) TaskBeliefOp(nars.derive.op.TaskBeliefOp) AbstractPatternOp(nars.derive.op.AbstractPatternOp) UnifyTerm(nars.derive.op.UnifyTerm) PrediTerm(nars.term.pred.PrediTerm) UnifyTerm(nars.derive.op.UnifyTerm) Term(nars.term.Term) Termed(nars.term.Termed)

Example 95 with NAR

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());
}
Also used : Termed(nars.term.Termed) Concept(nars.concept.Concept) Term(nars.term.Term) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NAR (nars.NAR)124 Test (org.junit.jupiter.api.Test)92 NARS (nars.NARS)23 Term (nars.term.Term)20 Truth (nars.truth.Truth)18 TestNAR (nars.test.TestNAR)16 BeliefTable (nars.table.BeliefTable)10 Disabled (org.junit.jupiter.api.Disabled)9 PrologCore (nars.op.prolog.PrologCore)8 Nullable (org.jetbrains.annotations.Nullable)8 Task (nars.Task)7 Concept (nars.concept.Concept)6 Param (nars.Param)5 Termed (nars.term.Termed)5 List (java.util.List)4 FasterList (jcog.list.FasterList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 nars.$ (nars.$)3 ITask (nars.task.ITask)3 NALTest (nars.util.NALTest)3