Search in sources :

Example 1 with FloatSupplier

use of jcog.math.FloatSupplier in project narchy by automenta.

the class LivePredictorTest method d.

// @Test public void testN() {
// MutableFloat m = new MutableFloat();
// 
// FloatSupplier[] in = {
// () -> 1f * (m.floatValue() % 2) > 0 ? 1 : -1,
// () -> 1f * ((m.floatValue() % 3) > 0 ? 1 : -1)
// };
// FloatSupplier[] out = {
// () -> 1f * (((m.floatValue() % 2) + (m.floatValue() % 3)) > 2 ? 1 : -1)
// };
// LivePredictor l = new LivePredictor(new LivePredictor.LSTMPredictor(),
// in,
// 5, out
// );
// 
// for (int i = 0; i < 1500; i++) {
// double[] prediction = l.next();
// 
// //System.out.print( n4(prediction) + "\t=?=\t");
// m.increment();
// //System.out.println(n4(d(in)) + "\t" + n4(d(out)) );
// }
// 
// }
static double[] d(FloatSupplier[] f) {
    double[] d = new double[f.length];
    int i = 0;
    for (FloatSupplier g : f) d[i++] = g.asFloat();
    return d;
}
Also used : FloatSupplier(jcog.math.FloatSupplier)

Example 2 with FloatSupplier

use of jcog.math.FloatSupplier in project narchy by automenta.

the class LivePredictorTest method assertCorrect.

static void assertCorrect(IntToFloatFunction ii, IntToFloatFunction oo, LivePredictor.Predictor model, int iHistory, int errorWindow, int totalTime, float maxMeanError) {
    MutableInteger m = new MutableInteger();
    FloatSupplier[] in = { () -> ii.valueOf(m.intValue()), () -> oo.valueOf(m.intValue() - 1) };
    FloatSupplier[] out = { () -> oo.valueOf(m.intValue()) };
    LivePredictor.HistoryFramer ih = new LivePredictor.HistoryFramer(in, iHistory, out);
    LivePredictor l = new LivePredictor(model, ih);
    DescriptiveStatistics error = new DescriptiveStatistics(errorWindow);
    for (int i = 0; i < totalTime; i++, m.increment()) {
        double[] prediction = l.next();
        // test time shift preseves previous value;
        {
            float[] i0 = ih.data.get(0).data;
            assertEquals(i0[0], in[0].asFloat(), 0.001f);
            if (i > 1)
                assertEquals(i0[1], ii.valueOf(m.intValue() - 1), 0.001f);
        }
        double predicted = prediction[0];
        double actual = oo.valueOf(m.intValue() + 1);
        // absolute error
        double e = Math.abs(actual - predicted);
        error.addValue(e);
    // System.out.println( n4(predicted) + "\t" + n4(actual));
    }
    double eMean = error.getMean();
    assertTrue(eMean < maxMeanError, () -> "mean error: " + eMean);
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) FloatSupplier(jcog.math.FloatSupplier) MutableInteger(jcog.math.MutableInteger)

Example 3 with FloatSupplier

use of jcog.math.FloatSupplier in project narchy by automenta.

the class Line1DCalibrate method conceptPlot.

public static Gridding conceptPlot(NAR nar, Iterable<FloatSupplier> concepts, int plotHistory) {
    // TODO make a lambda Grid constructor
    Gridding grid = new Gridding(VERTICAL);
    List<Plot2D> plots = $.newArrayList();
    for (FloatSupplier t : concepts) {
        Plot2D p = new Plot2D(plotHistory, Plot2D.Line);
        p.add(t.toString(), t::asFloat, 0f, 1f);
        grid.add(p);
        plots.add(p);
    }
    grid.layout();
    nar.onCycle(f -> {
        plots.forEach(Plot2D::update);
    });
    return grid;
}
Also used : Gridding(spacegraph.space2d.container.Gridding) FloatSupplier(jcog.math.FloatSupplier) List(java.util.List) Line1DSimplest(nars.test.agent.Line1DSimplest) Plot2D(spacegraph.space2d.widget.meter.Plot2D)

Aggregations

FloatSupplier (jcog.math.FloatSupplier)3 List (java.util.List)1 MutableInteger (jcog.math.MutableInteger)1 Line1DSimplest (nars.test.agent.Line1DSimplest)1 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)1 Gridding (spacegraph.space2d.container.Gridding)1 Plot2D (spacegraph.space2d.widget.meter.Plot2D)1