Search in sources :

Example 6 with NAR

use of nars.NAR in project narchy by automenta.

the class QuerySpider method starting.

@Override
protected void starting(NAR nar) {
    nar.onTask(t -> {
        if (t.isQuestOrQuestion() && t.term().hasVarQuery()) {
            Term tt = t.term();
            AdjGraph<Term, Float> g = spider(nar, t, 3);
            g.nodes.keysView().takeWhile(r -> {
                new UnifySubst(null, nar, (z) -> {
                    // TODO
                    return true;
                }, Param.TTL_MIN()).unify(tt, r.v, true);
                return true;
            });
        }
    });
}
Also used : AdjGraph(jcog.data.graph.AdjGraph) Param(nars.Param) TermGraph(nars.util.graph.TermGraph) UnifySubst(nars.term.subst.UnifySubst) Bag(jcog.bag.Bag) NAR(nars.NAR) Termed(nars.term.Termed) PriReference(jcog.pri.PriReference) Concept(nars.concept.Concept) NARService(nars.control.NARService) Term(nars.term.Term) Term(nars.term.Term) UnifySubst(nars.term.subst.UnifySubst)

Example 7 with NAR

use of nars.NAR in project narchy by automenta.

the class RLBooster method accept.

@Override
public void accept(NAR ignored) {
    // TODO provide actual action vector, not what it thinks it enacted by itself
    // NAgent's happiness value, normalized to -1..+1
    float reward = (env.happy.asFloat() - 0.5f) * 2f;
    int O = rl.act(reward, input());
    // System.out.println(now + " "  + o + " " + a.o.floatValue() + " " + " " + a.rewardValue);
    float OFFfreq = 0f;
    // = Float.NaN;
    NAR nar = env.nar();
    long start = env.last;
    long end = env.now;
    // int dur = nar.dur();
    List<Task> e = new FasterList(actions.length);
    for (int o = 0; o < actions.length; o++) {
        Truth off = OFFfreq == OFFfreq ? $.t(OFFfreq, conf.floatValue()) : null;
        // float value = actionDiscretization==1 ? 1f /* full */ :
        // ((float)(j)) / (actionDiscretization-1);
        float value = 1f;
        Truth tK;
        if (o == O) {
            tK = $.t(value, conf.floatValue());
        } else {
            // cancel all other concept goal signals
            tK = off;
        }
        Task tt = new SignalTask(actions[o].term(), GOAL, tK, start, start, end, nar.time.nextStamp());
        if (tt != null)
            e.add(tt);
    }
    in.input(e);
}
Also used : SignalTask(nars.task.signal.SignalTask) ITask(nars.task.ITask) Task(nars.Task) FasterList(jcog.list.FasterList) SignalTask(nars.task.signal.SignalTask) NAR(nars.NAR) Truth(nars.truth.Truth)

Example 8 with NAR

use of nars.NAR in project narchy by automenta.

the class TaskBudgetingTest method structuralDeduction1.

/**
 * taskbudgeting - structural deduction test
 *    decompose large conj, analyze the durability, quality decay
 */
@Test
public void structuralDeduction1() throws Narsese.NarseseException {
    NAR d = NARS.tmp();
    d.log();
    d.believe("(&&, (a),(b),(c),(d),(e) )");
    d.run(100);
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 9 with NAR

use of nars.NAR in project narchy by automenta.

the class ScalarBeliefTableTest method test1.

@Test
public void test1() {
    NAR n = NARS.shell();
    MutableFloat xx = new MutableFloat(0);
    Scalar x = new Scalar($.the("x"), xx, n);
    DurService xAuto = x.auto(n, 1);
    ScalarBeliefTable xb = (ScalarBeliefTable) x.beliefs();
    n.synch();
    n.run(1);
    assertEquals(1, xb.series.size());
    assertEquals(1, xb.size());
    xx.set(0.5f);
    n.run(1);
    assertEquals(2, xb.series.size());
    assertEquals(2, xb.size());
}
Also used : MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) NAR(nars.NAR) Scalar(nars.concept.scalar.Scalar) DurService(nars.control.DurService) Test(org.junit.jupiter.api.Test)

Example 10 with NAR

use of nars.NAR in project narchy by automenta.

the class BasicRulesTest method testSubstitution2.

@Test
public void testSubstitution2() throws Narsese.NarseseException {
    // (($1 --> M) ==> C), (S --> M), substitute($1,S) |- C, (Truth:Deduction, Order:ForAllSame)
    NAR n = NARS.shell();
    n.input("<<$1 --> happy> ==> <$1--> dead>>. <S --> happy>.");
    // <<$1 --> drunk> ==> <$1--> dead>>. <S --> drunk>.     |-  <S --> dead>.
    // OUT: <S --> dead>. %1.00;0.81% {58: 1;2}
    // TextOutput.out(n);
    n.run(150);
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

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