Search in sources :

Example 1 with PairedStatsAccumulator

use of com.google.common.math.PairedStatsAccumulator in project narchy by automenta.

the class RuleInductionTest method test1.

@Test
public void test1() {
    int dur = 1;
    int loops = 10;
    int period = 2;
    int dutyPeriod = 1;
    NAR n = NARS.tmp();
    n.termVolumeMax.set(3);
    // n.log();
    // dense proressing
    Deriver.derivers(n).forEach(d -> d.conceptsPerIteration.set(64));
    n.time.dur(dur);
    Term aConjB = $$("(a &&+" + dutyPeriod + " b)");
    float lastAConjB_exp = 0;
    PairedStatsAccumulator aConjB_exp = new PairedStatsAccumulator();
    for (int i = 0; i < loops; i++) {
        // n.clear(); //distraction clear
        n.believe("a", Tense.Present, 1, 0.9f);
        if (i > 0) {
        // TODO test that the newest tasklink inserted into concept 'a' is the, or nearly the strongest
        // n.concept("a").tasklinks().print();
        }
        n.run(dutyPeriod);
        n.believe("b", Tense.Present, 1, 0.9f);
        // delay
        n.run(period - dutyPeriod);
        long now = n.time();
        System.out.println("\n" + now);
        Truth aConjB_truth = n.belief(aConjB, now).truth(now, n.dur());
        System.out.println(aConjB_truth);
        n.conceptualize(aConjB).beliefs().print();
        float exp = aConjB_truth.expectation();
        if (!(exp >= lastAConjB_exp)) {
            // for debug
            Task tt = n.belief(aConjB, now);
        }
        // assertTrue(exp > lastAConjB_exp); //increasing
        aConjB_exp.add(now, exp);
        lastAConjB_exp = exp;
    }
    System.out.println(aConjB_exp.yStats());
    System.out.println("slope=" + aConjB_exp.leastSquaresFit().slope());
    // rising confidence
    assertTrue(aConjB_exp.leastSquaresFit().slope() > 0);
}
Also used : Task(nars.Task) Term(nars.term.Term) PairedStatsAccumulator(com.google.common.math.PairedStatsAccumulator) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 2 with PairedStatsAccumulator

use of com.google.common.math.PairedStatsAccumulator in project narchy by automenta.

the class AIMATests method assertBelief.

static void assertBelief(NAR n, boolean expcted, String x, int time) {
    final int metricPeriod = 150;
    PairedStatsAccumulator timeVsConf = new PairedStatsAccumulator();
    float symConf = 0;
    Task y = null;
    List<Float> evis = new FasterList();
    for (int i = 0; i < time; i += metricPeriod) {
        n.run(metricPeriod);
        y = n.belief($.the(x));
        if (y != null) {
            symConf = y.conf();
        }
        evis.add(c2wSafe(symConf, 1));
        timeVsConf.add(n.time(), symConf);
    }
    assertNotNull(y);
    assertTrue(y.isPositive() == expcted && y.polarity() > 0.5f);
    for (char c : "ABLMPQ".toCharArray()) {
        Term t = $.the(String.valueOf(c));
        Task cc = n.belief($.the(c));
        System.out.println(cc);
    }
    System.out.println(timeVsConf.yStats());
    System.out.println(SparkLine.renderFloats(evis, 8));
}
Also used : FasterList(jcog.list.FasterList) Term(nars.term.Term) PairedStatsAccumulator(com.google.common.math.PairedStatsAccumulator)

Aggregations

PairedStatsAccumulator (com.google.common.math.PairedStatsAccumulator)2 Term (nars.term.Term)2 FasterList (jcog.list.FasterList)1 NAR (nars.NAR)1 Task (nars.Task)1 Truth (nars.truth.Truth)1 Test (org.junit.jupiter.api.Test)1