Added support for creating matrices with random values
This commit is contained in:
parent
b20f62309b
commit
e7de925373
1 changed files with 21 additions and 0 deletions
|
@ -14,6 +14,9 @@ import java.util.Random;
|
|||
public class Utilities {
|
||||
private static final double STANDARD_GAUSSIAN_FACTOR = 1.0d;
|
||||
|
||||
private static final double STANDARD_RANDOM_ORIGIN = -1.0d;
|
||||
private static final double STANDARD_RANDOM_BOUND = 1.0d;
|
||||
|
||||
/**
|
||||
* Creates a matrix filled with ones
|
||||
* @param rows amount of rows
|
||||
|
@ -50,6 +53,24 @@ public class Utilities {
|
|||
return gaussianMatrix(rows, columns, mean, stddev, STANDARD_GAUSSIAN_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a matrix with random values
|
||||
* @param rows amount of rows
|
||||
* @param columns amount of columns
|
||||
* @param origin minimum random value
|
||||
* @param bound maximum random value
|
||||
* @return matrix with random values
|
||||
*/
|
||||
public static SimpleMatrix randomMatrix(int rows, int columns, double origin, double bound) {
|
||||
Random random = new Random();
|
||||
return new SimpleMatrix(rows, columns, true,
|
||||
random.doubles((long) rows * columns, origin, bound).toArray());
|
||||
}
|
||||
|
||||
public static SimpleMatrix randomMatrix(int rows, int columns) {
|
||||
return randomMatrix(rows, columns, STANDARD_RANDOM_ORIGIN, STANDARD_RANDOM_BOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of evenly spaced values from the interval [start, end)
|
||||
* @param start start value
|
||||
|
|
Loading…
Reference in a new issue