Search in sources :

Example 1 with DigitizedScalar

use of nars.concept.scalar.DigitizedScalar 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 2 with DigitizedScalar

use of nars.concept.scalar.DigitizedScalar in project narchy by automenta.

the class NSense method senseNumber.

@NotNull
default DigitizedScalar senseNumber(FloatSupplier v, DigitizedScalar.ScalarEncoder model, Term... states) {
    assert (states.length > 1);
    DigitizedScalar fs = new DigitizedScalar(new FloatCached(v, nar()::time), model, nar(), states);
    onFrame(fs);
    return fs;
}
Also used : DigitizedScalar(nars.concept.scalar.DigitizedScalar) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DigitizedScalar

use of nars.concept.scalar.DigitizedScalar in project narchy by automenta.

the class DigitizedScalarTest method testRewardConceptsFuzzification2.

@Test
public void testRewardConceptsFuzzification2() {
    NAR n = NARS.tmp();
    MutableFloat x = new MutableFloat(0f);
    testSteadyFreqCondition(x, new DigitizedScalar(new FloatNormalized(x::floatValue).updateRange(-1).updateRange(1), DigitizedScalar.FuzzyBinary, n, $.p("x0"), $.p("x1"), $.p("x2")), (f) -> true, /*Util.equals(f, 0.5f + 0.5f * m.floatValue(), tolerance)*/
    n);
}
Also used : FloatNormalized(jcog.math.FloatNormalized) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) DigitizedScalar(nars.concept.scalar.DigitizedScalar) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 4 with DigitizedScalar

use of nars.concept.scalar.DigitizedScalar in project narchy by automenta.

the class DigitizedScalarTest method testServiceAndFluidEncoder.

@Test
public void testServiceAndFluidEncoder() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    FloatRange x = new FloatRange(0f, 0f, 1f);
    DigitizedScalar xc = new DigitizedScalar(x, DigitizedScalar.Fluid, n, $.$("x(0)"), $.$("x(1)"));
    int dt = 20;
    for (float v : new float[] { 0f, 0.5f, 1f }) {
        x.set(v);
        xc.update(n.time() - n.dur() / 2, n.time() + n.dur() / 2, n.dur(), n);
        n.run(1);
        System.out.println("\n" + n.time() + " x=" + x);
        xc.forEach(d -> {
            Truth bt = n.beliefTruth(d, n.time());
            System.out.println(d + "\t" + bt);
        });
        int m = (dt - 1) / 2;
        n.run(m);
        Truth[] f = xc.belief(n.time(), n);
        float tolerance = 0.18f;
        if (v == 0) {
            assertEquals(0.0f, f[0].freq(), tolerance);
            assertEquals(0.0f, f[1].freq(), tolerance);
        } else if (v == 0.5f) {
            assertEquals(1.0f, f[0].freq(), tolerance);
            assertEquals(0.0f, f[1].freq(), tolerance);
        } else if (v == 1f) {
            assertEquals(1.0f, f[0].freq(), tolerance);
            assertEquals(1.0f, f[1].freq(), tolerance);
        }
        n.run(dt - 1 - m);
    }
}
Also used : DigitizedScalar(nars.concept.scalar.DigitizedScalar) FloatRange(jcog.math.FloatRange) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Aggregations

DigitizedScalar (nars.concept.scalar.DigitizedScalar)4 NAR (nars.NAR)3 Test (org.junit.jupiter.api.Test)3 FloatNormalized (jcog.math.FloatNormalized)2 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)2 FloatPolarNormalized (jcog.math.FloatPolarNormalized)1 FloatRange (jcog.math.FloatRange)1 Truth (nars.truth.Truth)1 NotNull (org.jetbrains.annotations.NotNull)1 Disabled (org.junit.jupiter.api.Disabled)1