Search in sources :

Example 1 with TemporalMetrics

use of jcog.meter.TemporalMetrics in project narchy by automenta.

the class TemporalInductionTest method testPriorityOfInductedRulesVsEventsThatItLearnedFrom.

/**
 * higher-level rules learned from events, especially repeatd
 * events, "should" ultimately accumulate a higher priority than
 * the events themselves.
 */
@Test
public void testPriorityOfInductedRulesVsEventsThatItLearnedFrom() throws FileNotFoundException {
    NAR n = NARS.tmp();
    n.beliefPriDefault.set(0.1f);
    // n.deep.set(1f);
    n.log();
    TemporalMetrics m = new TemporalMetrics(1024);
    n.onCycle(() -> m.update(n.time()));
    m.add(new PriMeter(n, "(0)"));
    m.add(new PriMeter(n, "(1)"));
    m.add(new PriMeter(n, "(2)"));
    m.add(new PriMeter(n, "((0) && (1))"));
    m.add(new PriMeter(n, "((0) ==> (1))"));
    m.add(new PriMeter(n, "((1) && (2))"));
    m.add(new PriMeter(n, "((1) ==> (2))"));
    // expose to repeat sequence
    int loops = 32, eventsPerLoop = 3, delayBetweenEvents = 2;
    for (int i = 0; i < loops; i++) {
        for (int j = 0; j < eventsPerLoop; j++) {
            n.believe($.p(j), Tense.Present);
            n.run(delayBetweenEvents);
        }
    }
    m.printCSV4("/tmp/x.csv");
    m.printCSV4(System.out);
}
Also used : TemporalMetrics(jcog.meter.TemporalMetrics) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 2 with TemporalMetrics

use of jcog.meter.TemporalMetrics in project narchy by automenta.

the class MetricsTest method testSummaryStatistics.

// @Test public void testMeterDerivative() {
// 
// TemporalMetrics<Integer> tm = new TemporalMetrics<>(3);
// tm.add(timeDoubler);
// tm.add(new FirstOrderDifference(tm, timeDoubler.signalID(0)));
// 
// assertEquals(3, tm.getSignals().size());
// 
// tm.update(0.0);
// tm.update(1.0);
// 
// //check the '1' column ('x')
// assertEquals(0, tm.getData(1)[0]);
// assertEquals(2, tm.getData(1)[1]);
// 
// tm.update(2.0);
// 
// 
// 
// //check the '2' column (first order diff)
// assertEquals(null, tm.getData(2)[0]);
// assertEquals(2.0, tm.getData(2)[1]);
// 
// 
// }
@Disabled
@Test
public void testSummaryStatistics() {
    TemporalMetrics tm = new TemporalMetrics(10);
    tm.add(new BasicStatistics(tm, tm.getSignalIDs()[0]));
    for (int i = 0; i < 10; i++) {
        tm.update(0.1 * i);
    }
    // noinspection OverlyComplexAnonymousInnerClass
    PrintStream sb = new PrintStream(System.out) {

        int line;

        @Override
        public void println(String x) {
            String eq = null;
            switch(line++) {
                case 0:
                    eq = "\"key\",\"key.mean\",\"key.stdev\"";
                    break;
                case 1:
                    eq = "0,0,0";
                    break;
                case 3:
                    eq = "0.2,0.1,0.1";
                    break;
            }
            if (eq != null) {
                assertEquals(eq, x);
            }
        }
    };
    tm.printCSV(sb);
}
Also used : PrintStream(java.io.PrintStream) BasicStatistics(jcog.meter.func.BasicStatistics) TemporalMetrics(jcog.meter.TemporalMetrics) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with TemporalMetrics

use of jcog.meter.TemporalMetrics in project narchy by automenta.

the class MetricsTest method testTemporalMetrics.

@Test
public void testTemporalMetrics() {
    TemporalMetrics tm = new TemporalMetrics(3);
    tm.add(timeDoubler);
    assertEquals(0, tm.numRows());
    assertEquals(2, tm.getSignals().size(), "signal columns: time and 'x'");
    tm.update(1.0);
    assertEquals(1, tm.numRows());
    assertEquals(2, tm.getData(1)[0]);
    tm.update(1.5);
    tm.update(2.0);
    assertEquals(3, tm.numRows());
    tm.update(2.5);
    assertEquals(3, tm.numRows());
}
Also used : TemporalMetrics(jcog.meter.TemporalMetrics) Test(org.junit.jupiter.api.Test)

Aggregations

TemporalMetrics (jcog.meter.TemporalMetrics)3 Test (org.junit.jupiter.api.Test)3 PrintStream (java.io.PrintStream)1 BasicStatistics (jcog.meter.func.BasicStatistics)1 NAR (nars.NAR)1 TestNAR (nars.test.TestNAR)1 Disabled (org.junit.jupiter.api.Disabled)1