SurrogateModel.java [src/java/utils] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.List;
import java.util.stream.Collectors;
import org.encog.ml.data.MLData;
import org.encog.neural.neat.NEATNetwork;

public class SurrogateModel {

    List<NEATNetwork> nn;


    public SurrogateModel(String annName) {
        nn = MongoAccess.retrieveANNs(annName);
        if (nn.isEmpty()) {
            throw new RuntimeException("No ANNs retrieved. Please check selection collection.");
        }
    }


    /**
     * Computes the output from all ANNs
     *
     * @param input
     * @return
     */
    public synchronized List<double[]> compute(MLData input) {
        return nn.parallelStream()
                .map(n -> n.compute(input).getData())
                .collect(Collectors.toList());
    }

}