Search in sources :

Example 41 with NAR

use of nars.NAR in project narchy by automenta.

the class ImplicationTest method testBelief.

@Test
public void testBelief() {
    // Z, X==>Y
    StringBuilder o = new StringBuilder();
    for (float condFreq : new float[] { 0, 1, 0.5f }) {
        for (boolean sp : B) {
            Term z = sp ? x : y;
            for (boolean xx : B) {
                for (boolean yy : B) {
                    NAR n = NARS.tmp(6);
                    Term impl = IMPL.the(x.negIf(!xx), y.negIf(!yy));
                    n.believe(impl);
                    n.believe(z, condFreq, n.confDefault(BELIEF));
                    n.run(256);
                    Term nz = sp ? y : x;
                    // BeliefTable nzb = n.concept(nz).beliefs();
                    // int bs = nzb.size();
                    // if (bs == 2) {
                    // nzb.print();
                    // System.out.println();
                    // }
                    // assert(bs == 0 || bs == 1 || bs == 3); //either one answer, or something revised to 0.5 via 2
                    @Nullable Truth nzt = n.beliefTruth(nz, ETERNAL);
                    o.append(z + ". %" + n2(condFreq) + "% " + impl + ". " + nz + "=" + nzt + "\n");
                }
            }
        }
    }
    String oo = o.toString();
    System.out.println(oo);
    assertContains(oo, "x. %0.0% ((--,x)==>y). y=%1.0;.81%");
    assertContains(oo, "y. %0.0% ((--,x)==>y). x=%1.0;.45%");
    assertContains(oo, "y. %0.0% (--,((--,x)==>y)). x=%0.0;.45%");
    assertContains(oo, "y. %0.0% (--,((--,x)==>y)). x=%0.0;.45%");
// ...
}
Also used : Term(nars.term.Term) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 42 with NAR

use of nars.NAR in project narchy by automenta.

the class DigitizedScalarTest method testRewardConceptsFuzzification3.

// @Test
// public void testRewardConceptsFuzzification1() {
// NAR d = new Default();
// MutableFloat m = new MutableFloat(0f);
// 
// testSteadyFreqCondition(m,
// new FuzzyScalarConcepts(
// new FloatNormalized(() -> m.floatValue()).updateRange(-1).updateRange(1),
// d, FuzzyScalarConcepts.FuzzyTriangle, $.p("x")),
// (f) -> Util.equals(f, 0.5f + 0.5f * m.floatValue(), tolerance)
// );
// }
@Disabled
@Test
public void testRewardConceptsFuzzification3() {
    NAR n = NARS.shell();
    MutableFloat m = new MutableFloat(0f);
    FloatNormalized range = new FloatPolarNormalized(() -> m.floatValue(), 1f);
    DigitizedScalar f = new DigitizedScalar(range, DigitizedScalar.FuzzyNeedle, n, $.p("low"), $.p("mid"), $.p("hih"));
    // {
    // f.clear();
    // m.setValue(0); d.next();
    // System.out.println(Texts.n4(m.floatValue()) + "\t" + f.toString());
    // assertEquals("(I-->[sad]) %0.25;.90%\t(I-->[neutral]) %1.0;.90%\t(I-->[happy]) %0.0;.90%", f.toString());
    // }
    // 
    // {
    // f.clear();
    // m.setValue(-1); d.next();
    // System.out.println(Texts.n4(m.floatValue()) + "\t" + f.toString());
    // assertEquals("(I-->[sad]) %1.0;.90%\t(I-->[neutral]) %0.0;.90%\t(I-->[happy]) %0.0;.90%", f.toString());
    // }
    // 
    // {
    // f.clear();
    // m.setValue(+1); d.next();
    // System.out.println(Texts.n4(m.floatValue()) + "\t" + f.toString());
    // assertEquals("(I-->[sad]) %0.0;.90%\t(I-->[neutral]) %0.0;.90%\t(I-->[happy]) %1.0;.90%", f.toString());
    // }
    testSteadyFreqCondition(m, f, (freqSum) -> {
        System.out.println(freqSum + " " + tolerance);
        return Util.equals(freqSum, 1f, tolerance);
    }, n);
}
Also used : FloatNormalized(jcog.math.FloatNormalized) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) DigitizedScalar(nars.concept.scalar.DigitizedScalar) FloatPolarNormalized(jcog.math.FloatPolarNormalized) NAR(nars.NAR) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 43 with NAR

use of nars.NAR in project narchy by automenta.

the class ImplierTest method testImplier1.

@Test
public void testImplier1() throws Narsese.NarseseException {
    NAR n = NARS.tmp(1);
    Term a = $("a");
    Term b = $("b");
    Term c = $("c");
    Term d = $("d");
    Term t = $("t");
    Term u = $("u");
    Term y = $("y");
    Implier imp = new Implier(n, new float[] { 0f }, y);
    n.run(1);
    n.log();
    n.believe(IMPL.the(a, y));
    n.believe(IMPL.the(b.neg(), y));
    n.believe(IMPL.the(c, y.neg()));
    n.believe(IMPL.the(d.neg(), y.neg()));
    n.believe(IMPL.the(t, -1, y));
    n.believe(IMPL.the(t.neg(), -2, y));
    n.believe(IMPL.the(u, +1, y.neg()));
    n.believe(IMPL.the(u.neg(), +2, y.neg()));
    n.believe(a);
    n.believe(b);
    n.believe(c);
    n.believe(d);
    // n.believe(t, ..);
    // n.believe(u, ..);
    n.run(15);
    System.out.println(imp.impl);
// for (int i = 0; i < 2; i++) {
// 
// n.run(2);
// System.out.println(imp.impl);
// assertEquals(2, imp.impl.nodeCount());
// assertEquals(1, imp.impl.edgeCount());
// }
// n.input("(z ==> x). :|:");
// n.run(1);
// System.out.println(imp.impl);
// n.run(1);
// System.out.println(imp.impl);
// System.out.println(imp.goalTruth);
}
Also used : Term(nars.term.Term) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 44 with NAR

use of nars.NAR in project narchy by automenta.

the class MathFuncTest method testAddSolve.

@Test
public void testAddSolve() throws Narsese.NarseseException {
    NAR n = NARS.shell();
    n.log();
    n.believe("(add(1,$x,3)==>its($x))");
    n.run(2);
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 45 with NAR

use of nars.NAR in project narchy by automenta.

the class OpjectsTest method learnMethodGoal.

@Disabled
@Test
public void learnMethodGoal() throws Narsese.NarseseException {
    // StringBuilder sb = new StringBuilder();
    // n.onTask(sb::append);
    Param.DEBUG = true;
    final NAR n = NARS.tmp();
    final Opjects objs = new Opjects(n);
    final SimpleClass x = objs.a("x", SimpleClass.class);
    n.beliefPriDefault.set(0.05f);
    n.questionPriDefault.set(0.05f);
    n.questPriDefault.set(0.05f);
    n.freqResolution.set(0.1f);
    n.time.dur(10);
    n.termVolumeMax.set(30);
    n.logPriMin(System.out, 0.02f);
    // n.onTask(xx -> {
    // if (xx instanceof DerivedTask) {
    // if (xx.isGoal())
    // System.out.println(xx);
    // }
    // });
    int N = 2;
    n.clear();
    int loops = 0, trainingRounds = 4;
    while (x.v != 2) {
        if (loops++ < trainingRounds) {
            for (int i = 0; i < 2; i++) {
                x.set(i % N);
                n.run(1);
                x.get();
                n.run(1);
            }
            // n.input("$0.5 (0<->2)?");
            // n.input("$0.5 (1<->2)?");
            n.input("$1.0 x(get,(),2)!");
            n.run(50);
        }
        // n.input("$1.0 x(set,2)! :|:");
        // n.input("$1.0 SimpleClass(get,x,(),2)! :|:");
        // n.input("$1.0 SimpleClass(get,x,(),_)! :|:");
        // n.input("$1.0 --SimpleClass(get,x,(),0)! :|:");
        // n.input("$1.0 --SimpleClass(get,x,(),1)! :|:");
        n.run(50);
    }
// while (x.v!=3) {
// 
// }
// n.input("$0.5 (0<->1)?");
// n.input("$0.5 (1<->2)?");
// n.input("$0.5 (2<->3)?");
// n.input("$0.5 (3<->4)?");
// n.input("$1.0 (SimpleClass(set,x,$x) ==> SimpleClass(get,x,(),$x))?");
// n.run(100);
// n.tasks().forEachOrdered(z -> {
// System.out.println(z);
// });
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

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