Search in sources :

Example 1 with NALTest

use of nars.util.NALTest in project narchy by automenta.

the class NARTestOptimize method test.

private static float test(Supplier<NAR> s, Method m) {
    try {
        NALTest t = (NALTest) m.getDeclaringClass().getConstructor().newInstance();
        // overwrite NAR with the supplier
        t.nar = s.get();
        t.nar.random().setSeed(System.nanoTime());
        m.invoke(t);
        try {
            Param.DEBUG = false;
            t.test.test(false);
            return t.test.score;
        // return 1 + t.test.score; //+1 for successful completion
        } catch (Throwable ee) {
            // return -2f;
            return 0f;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return 0f;
    }
}
Also used : NALTest(nars.util.NALTest)

Example 2 with NALTest

use of nars.util.NALTest in project narchy by automenta.

the class NARTestOptimize method tests.

/**
 * HACK runs all Junit test methods, summing the scores.
 * TODO use proper JUnit5 test runner api but it is a mess to figure out right now
 */
static float tests(Supplier<NAR> s, Class<? extends NALTest>... c) {
    List<Method> methods = Stream.of(c).flatMap(cc -> Stream.of(cc.getMethods()).filter(x -> x.getAnnotation(Test.class) != null)).collect(toList());
    final CountDownLatch remain = new CountDownLatch(methods.size());
    final AtomicDouble sum = new AtomicDouble(0);
    methods.forEach(m -> {
        exe.submit(() -> {
            try {
                sum.addAndGet(test(s, m));
            } finally {
                remain.countDown();
            }
        });
    });
    try {
        remain.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return sum.floatValue();
}
Also used : NAL1MultistepTest(nars.nal.nal1.NAL1MultistepTest) NARS(nars.NARS) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) NAL1Test(nars.nal.nal1.NAL1Test) Supplier(java.util.function.Supplier) NARLoop(nars.NARLoop) NAL3Test(nars.nal.nal3.NAL3Test) Method(java.lang.reflect.Method) NAL2Test(nars.nal.nal2.NAL2Test) ExecutorService(java.util.concurrent.ExecutorService) NAL5Test(nars.nal.nal5.NAL5Test) MultiOutputStream(jcog.data.MultiOutputStream) Set(java.util.Set) NALTest(nars.util.NALTest) Field(java.lang.reflect.Field) Executors(java.util.concurrent.Executors) Result(jcog.optimize.Result) Param(nars.Param) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) java.io(java.io) NAR(nars.NAR) Tweaks(jcog.optimize.Tweaks) MetaGoal(nars.control.MetaGoal) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Method(java.lang.reflect.Method) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

NALTest (nars.util.NALTest)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 java.io (java.io)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Supplier (java.util.function.Supplier)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 MultiOutputStream (jcog.data.MultiOutputStream)1 Result (jcog.optimize.Result)1 Tweaks (jcog.optimize.Tweaks)1 NAR (nars.NAR)1 NARLoop (nars.NARLoop)1 NARS (nars.NARS)1 Param (nars.Param)1