Example usage for org.apache.commons.math3.distribution UniformRealDistribution sample

List of usage examples for org.apache.commons.math3.distribution UniformRealDistribution sample

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution UniformRealDistribution sample.

Prototype

public double[] sample(int sampleSize) 

Source Link

Document

The default implementation generates the sample by calling #sample() in a loop.

Usage

From source file:com.github.tteofili.looseen.yay.SGM.java

private RealMatrix[] initWeights() {
    int[] conf = new int[] { configuration.inputs, configuration.vectorSize, configuration.outputs };
    int[] layers = new int[conf.length];
    System.arraycopy(conf, 0, layers, 0, layers.length);
    int weightsCount = layers.length - 1;

    RealMatrix[] initialWeights = new RealMatrix[weightsCount];

    for (int i = 0; i < weightsCount; i++) {
        RealMatrix matrix = MatrixUtils.createRealMatrix(layers[i + 1], layers[i]);

        UniformRealDistribution uniformRealDistribution = new UniformRealDistribution();
        double[] vs = uniformRealDistribution.sample(matrix.getRowDimension() * matrix.getColumnDimension());
        int r = 0;
        int c = 0;
        for (double v : vs) {
            matrix.setEntry(r % matrix.getRowDimension(), c % matrix.getColumnDimension(), v);
            r++;/*from   w w w  . j a  v a  2s. c  o m*/
            c++;
        }

        initialWeights[i] = matrix;
    }
    return initialWeights;

}