Compare commits

..

2 commits

2 changed files with 32 additions and 0 deletions

View file

@ -11,6 +11,7 @@ repositories {
dependencies { dependencies {
implementation 'org.ejml:ejml-all:0.41' implementation 'org.ejml:ejml-all:0.41'
implementation 'org.knowm.xchart:xchart:3.8.1'
implementation 'com.opencsv:opencsv:5.6' implementation 'com.opencsv:opencsv:5.6'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'

View file

@ -7,14 +7,45 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random;
public class Utilities { public class Utilities {
private static final double STANDARD_GAUSSIAN_FACTOR = 1.0d;
public static SimpleMatrix ones(int rows, int columns) { public static SimpleMatrix ones(int rows, int columns) {
SimpleMatrix mat = new SimpleMatrix(rows, columns); SimpleMatrix mat = new SimpleMatrix(rows, columns);
Arrays.fill(mat.getDDRM().data, 1); Arrays.fill(mat.getDDRM().data, 1);
return mat; 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) { public static List<List<String>> readCSV(String filename) {
List<List<String>> entries = new ArrayList<>(); List<List<String>> entries = new ArrayList<>();
try (CSVReader csvReader = new CSVReader(new FileReader(filename))) { try (CSVReader csvReader = new CSVReader(new FileReader(filename))) {