Compare commits
2 commits
ffcf9fa975
...
281b42b0fb
Author | SHA1 | Date | |
---|---|---|---|
281b42b0fb | |||
adfd701817 |
2 changed files with 32 additions and 0 deletions
|
@ -11,6 +11,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation 'org.ejml:ejml-all:0.41'
|
||||
implementation 'org.knowm.xchart:xchart:3.8.1'
|
||||
implementation 'com.opencsv:opencsv:5.6'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
|
|
|
@ -7,14 +7,45 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Utilities {
|
||||
private static final double STANDARD_GAUSSIAN_FACTOR = 1.0d;
|
||||
|
||||
public static SimpleMatrix ones(int rows, int columns) {
|
||||
SimpleMatrix mat = new SimpleMatrix(rows, columns);
|
||||
Arrays.fill(mat.getDDRM().data, 1);
|
||||
return mat;
|
||||
}
|
||||
|
||||
public static SimpleMatrix gaussianMatrix(int rows, int columns, double mean, double stddev, double factor) {
|
||||
SimpleMatrix mat = new SimpleMatrix(rows, columns);
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < mat.getNumElements(); i++) {
|
||||
mat.set(i, factor * random.nextGaussian(mean, stddev));
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
public static SimpleMatrix gaussianMatrix(int rows, int columns, double mean, double stddev) {
|
||||
return gaussianMatrix(rows, columns, mean, stddev, STANDARD_GAUSSIAN_FACTOR);
|
||||
}
|
||||
|
||||
public static double[] linspace(double start, double end, int num) {
|
||||
double[] result = new double[num];
|
||||
double stepSize = Math.abs(end - start) / num;
|
||||
double nextEntry = start;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
result[i] = nextEntry;
|
||||
nextEntry += stepSize;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<List<String>> readCSV(String filename) {
|
||||
List<List<String>> entries = new ArrayList<>();
|
||||
try (CSVReader csvReader = new CSVReader(new FileReader(filename))) {
|
||||
|
|
Loading…
Reference in a new issue