Search in sources :

Example 1 with InferenceLogger

use of nars.gui.InferenceLogger in project opennars by opennars.

the class NALTest method testNAL.

protected double testNAL(final String path) {
    Memory.resetStatic();
    final List<OutputCondition> expects = new ArrayList();
    NAR n = null;
    boolean error = false;
    try {
        n = newNAR();
        String example = getExample(path);
        if (showOutput) {
            System.out.println(example);
            System.out.println();
        }
        List<OutputCondition> extractedExpects = OutputCondition.getConditions(n, example, similarsToSave);
        for (OutputCondition e1 : extractedExpects) expects.add(e1);
        if (showOutput)
            new TextOutputHandler(n, System.out);
        if (showTrace) {
            new InferenceLogger(n, System.out);
        }
        n.addInputFile(path);
        n.cycles(minCycles);
    } catch (Throwable e) {
        System.err.println(e);
        if (Parameters.DEBUG) {
            e.printStackTrace();
        }
        error = true;
    }
    System.err.flush();
    System.out.flush();
    boolean success = expects.size() > 0 && (!error);
    for (OutputCondition e : expects) {
        if (!e.succeeded)
            success = false;
    }
    double score = Double.POSITIVE_INFINITY;
    if (success) {
        long lastSuccess = -1;
        for (OutputCondition e : expects) {
            if (e.getTrueTime() != -1) {
                if (lastSuccess < e.getTrueTime())
                    lastSuccess = e.getTrueTime();
            }
        }
        if (lastSuccess != -1) {
            // score = 1.0 + 1.0 / (1+lastSuccess);
            score = lastSuccess;
            scores.put(path, score);
        }
    } else {
        scores.put(path, Double.POSITIVE_INFINITY);
    }
    if ((!success & showFail) || (success && showSuccess)) {
        System.err.println('\n' + path + " @" + n.memory.time());
        for (OutputCondition e : expects) {
            System.err.println("  " + e);
        }
    }
    // System.err.println("Status: " + success + " total=" + expects.size() + " " + expects);
    if (requireSuccess)
        assertTrue(path, success);
    return score;
}
Also used : InferenceLogger(nars.gui.InferenceLogger) OutputCondition(nars.lab.testutils.OutputCondition) ArrayList(java.util.ArrayList) TextOutputHandler(nars.io.events.TextOutputHandler) NAR(nars.main.NAR)

Aggregations

ArrayList (java.util.ArrayList)1 InferenceLogger (nars.gui.InferenceLogger)1 TextOutputHandler (nars.io.events.TextOutputHandler)1 OutputCondition (nars.lab.testutils.OutputCondition)1 NAR (nars.main.NAR)1