/** * <p> * Sets each element in the matrix to a value drawn from an Gaussian distribution with the specified mean and * standard deviation * </p> * * @param mat The matrix who is to be randomized. Modified. * @param mean Mean value in the distribution * @param stdev Standard deviation in the distribution * @param rand Random number generator used to fill the matrix. */ public static void fillGaussian(FMatrixD1 mat, float mean, float stdev, IMersenneTwister rand) { float[] d = mat.getData(); int size = mat.getNumElements(); for (int i = 0; i < size; i++) { d[i] = mean + stdev * (float)rand.NextGaussian(); } }
/** * <p> * Sets each element in the matrix to a value drawn from an uniform distribution from 'min' to 'max' inclusive. * </p> * * @param min The minimum value each element can be. * @param max The maximum value each element can be. * @param mat The matrix who is to be randomized. Modified. * @param rand Random number generator used to fill the matrix. */ public static void fillUniform(FMatrixD1 mat, float min, float max, IMersenneTwister rand) { float[] d = mat.getData(); int size = mat.getNumElements(); float r = max - min; for (int i = 0; i < size; i++) { d[i] = r * rand.NextFloat() + min; } }