use of com.simiacryptus.mindseye.layers.java.ValueLayer in project MindsEye by SimiaCryptus.
the class StochasticSamplingSubnetLayer method average.
/**
* Average result.
*
* @param samples the samples
* @param precision the precision
* @return the result
*/
public static Result average(final Result[] samples, final Precision precision) {
PipelineNetwork gateNetwork = new PipelineNetwork(1);
gateNetwork.wrap(new ProductLayer().setPrecision(precision), gateNetwork.getInput(0), gateNetwork.wrap(new ValueLayer(new Tensor(1, 1, 1).mapAndFree(v -> 1.0 / samples.length)), new DAGNode[] {}));
SumInputsLayer sumInputsLayer = new SumInputsLayer().setPrecision(precision);
try {
return gateNetwork.evalAndFree(sumInputsLayer.evalAndFree(samples));
} finally {
sumInputsLayer.freeRef();
gateNetwork.freeRef();
}
}
Aggregations