Search in sources :

Example 1 with IntRange

use of org.encog.mathutil.IntRange in project shifu by ShifuML.

the class NNTrainer method calculateMSEParallel.

public double calculateMSEParallel(BasicNetwork network, MLDataSet dataSet) {
    int numRecords = (int) dataSet.getRecordCount();
    assert numRecords > 0;
    // setup workers
    final DetermineWorkload determine = new DetermineWorkload(0, numRecords);
    // nice little workaround
    MSEWorker[] workers = new MSEWorker[determine.getThreadCount()];
    int index = 0;
    TaskGroup group = EngineConcurrency.getInstance().createTaskGroup();
    for (final IntRange r : determine.calculateWorkers()) {
        workers[index++] = new MSEWorker((BasicNetwork) network.clone(), dataSet.openAdditional(), r.getLow(), r.getHigh());
    }
    for (final MSEWorker worker : workers) {
        EngineConcurrency.getInstance().processTask(worker, group);
    }
    group.waitForComplete();
    double totalError = 0;
    for (final MSEWorker worker : workers) {
        totalError += worker.getTotalError();
    }
    return totalError / numRecords;
}
Also used : MSEWorker(ml.shifu.shifu.core.MSEWorker) BasicNetwork(org.encog.neural.networks.BasicNetwork) DetermineWorkload(org.encog.util.concurrency.DetermineWorkload) IntRange(org.encog.mathutil.IntRange) TaskGroup(org.encog.util.concurrency.TaskGroup)

Aggregations

MSEWorker (ml.shifu.shifu.core.MSEWorker)1 IntRange (org.encog.mathutil.IntRange)1 BasicNetwork (org.encog.neural.networks.BasicNetwork)1 DetermineWorkload (org.encog.util.concurrency.DetermineWorkload)1 TaskGroup (org.encog.util.concurrency.TaskGroup)1