Search in sources :

Example 46 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class TruthletTaskTest method test_LinearTruthlet_And_SustainTruthlet.

@Test
public void test_LinearTruthlet_And_SustainTruthlet() {
    float conf = 0.9f;
    RangeTruthlet s = Truthlet.slope(0, 1f, 3, 0f, c2w(conf));
    for (Truthlet t : new Truthlet[] { s, new SustainTruthlet(s, 1) }) {
        NAR n = NARS.shell();
        Term x = $.the("x");
        System.out.println(t);
        n.input(new TruthletTask(x, BELIEF, t, n));
        BeliefTable xb = n.truths(x, BELIEF);
        for (int i = -3; i < 7; i++) {
            Truth ti = xb.truth(i, n);
            if (i < 0 || i > 3) {
                if (t instanceof SustainTruthlet) {
                    // fade out
                    assertTrue(ti.conf() < 0.9f);
                } else {
                    assertNull(ti);
                }
            } else {
                assertEquals(0.9f, ti.conf());
                float f = ti.freq();
                switch(i) {
                    case 0:
                        assertEquals(1f, f, 0.01f);
                        break;
                    case 1:
                        assertEquals(0.666f, f, 0.01f);
                        break;
                    case 2:
                        assertEquals(0.333f, f, 0.01f);
                        break;
                    case 3:
                        assertEquals(0f, f, 0.01f);
                        break;
                }
            }
            System.out.println(i + ": " + ti);
        }
    }
}
Also used : BeliefTable(nars.table.BeliefTable) Term(nars.term.Term) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 47 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToBC_AB_only.

@Test
public void testEternal_A_NegBelief_NegToBC_AB_only() {
    NAR n = NARS.tmp(6);
    n.termVolumeMax.set(16);
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aa = n.concept(a).beliefs();
    BeliefTable bb = n.concept(b).beliefs();
    aa.print();
    // bb.print();
    bb.forEachTask(x -> System.out.println(x.proof()));
    Truth bBelief = bb.truth(ETERNAL, n);
    assertEquals("%1.0;.81%", bBelief.toString());
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 48 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToB_NegToC.

@Test
public void testEternal_A_NegBelief_NegToB_NegToC() {
    NAR n = NARS.tmp();
    n.log();
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b).neg());
    n.believe(IMPL.the(b.neg(), c));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aBeliefs = n.concept(a).beliefs();
    aBeliefs.print();
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = n.concept(b).beliefs().truth(ETERNAL, n);
    Truth cBelief = n.concept(c).beliefs().truth(ETERNAL, n);
    assertEquals("%0.0;.81%", bBelief.toString());
    assertEquals("%1.0;.73%", cBelief.toString());
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 49 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_ToBC.

@Test
public void testEternal_A_NegBelief_ToBC() {
    NAR n = NARS.tmp();
    Param.DEBUG = true;
    n.believe(IMPL.the(a, b));
    n.believe(IMPL.the(b, c));
    n.believe(a.neg());
    n.run(100);
    BeliefTable aBeliefs = n.concept(a).beliefs();
    // Truth aBelief = aBeliefs.truth(ETERNAL, n);
    // a belief state should not exceed the input (default confidence) and freq remain stable
    // additional beliefs are not helpful
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = n.concept(b).beliefs().truth(ETERNAL, n);
    // NOTHING
    assertNull(bBelief);
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 50 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class SoNAR method update.

private boolean update(@NotNull Concept c, Sound s) {
    // float p = nar.pri(k);
    // if (p == p && p > 0) {
    // v.setAmplitude(0.1f * p);
    Truth b = nar.goalTruth(c, now);
    // System.out.println(c + " "+ b + " " + nar.time() + " " + nar.dur());
    float thresh = 0.55f;
    if (b != null && b.freq() > thresh) {
        if (s.producer instanceof Granulize) {
            float stretchFactor = (b.freq() - 0.5f) * 2f;
            if (stretchFactor > 0 && stretchFactor < 0.05f)
                stretchFactor = 0.05f;
            else if (stretchFactor < 0 && stretchFactor > -0.05f)
                stretchFactor = -0.05f;
            ((Granulize) s.producer).setStretchFactor(stretchFactor);
        }
        if (s.producer instanceof SoundProducer.Amplifiable) {
            // v.setAmplitude(1f);
            ((SoundProducer.Amplifiable) s.producer).setAmplitude(2f * (b.freq() - 0.5f));
        }
        // v.play();
        return true;
    } else {
        if (s.producer instanceof SoundProducer.Amplifiable) {
            ((SoundProducer.Amplifiable) s.producer).setAmplitude(0f);
        }
        return false;
    // v.stop();
    // v.setStretchFactor(1f);
    }
// 
// v.setStretchFactor();
// v.pitchFactor.setValue(1f / Math.log(c.volume()));
// g.setStretchFactor(1f/(1f+kk.volume()/4f));
// }
// v.stop();
// return false;
}
Also used : Granulize(spacegraph.audio.granular.Granulize) Truth(nars.truth.Truth)

Aggregations

Truth (nars.truth.Truth)65 Term (nars.term.Term)31 Test (org.junit.jupiter.api.Test)22 Nullable (org.jetbrains.annotations.Nullable)20 NAR (nars.NAR)18 Task (nars.Task)14 BeliefTable (nars.table.BeliefTable)13 Concept (nars.concept.Concept)9 NALTask (nars.task.NALTask)9 TaskConcept (nars.concept.TaskConcept)7 PreciseTruth (nars.truth.PreciseTruth)7 NotNull (org.jetbrains.annotations.NotNull)7 FasterList (jcog.list.FasterList)6 ITask (nars.task.ITask)6 Tense (nars.time.Tense)6 Util (jcog.Util)5 BELIEF (nars.Op.BELIEF)5 Consumer (java.util.function.Consumer)4 Predicate (java.util.function.Predicate)4 Param (nars.Param)4