Java library of 2-dimensional matrix algorithms.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
RELEASE.md
pom.xml

README.md

matrix-algorithms

Java library of 2-dimensional matrix algorithms.

Algorithms

Unsupervised:

Supervised:

Planned:

Maven

Add the following dependency to your pom.xml:

    <dependency>
      <groupId>nz.ac.waikato.cms.adams</groupId>
      <artifactId>matrix-algorithms</artifactId>
      <version>0.0.12</version>
    </dependency>

Examples

PCA

import Jama.Matrix;
import com.github.waikatodatamining.matrix.algorithm.PCA;
import com.github.waikatodatamining.matrix.core.MatrixHelper;
...
Matrix data = MatrixHelper.read("bolts.csv", true, ',');
// remove the class column, if present
//data = MatrixHelper.deleteCol(data, data.getColumnDimension() - 1);

System.out.println("\nInput");
System.out.println(MatrixHelper.toString(data));

PCA pca = new PCA();
Matrix transformed = pca.transform(data);
System.out.println("\nTransformed");
System.out.println(MatrixHelper.toString(transformed));

SIMPLS

import Jama.Matrix;
import com.github.waikatodatamining.matrix.algorithm.pls.SIMPLS;
import com.github.waikatodatamining.matrix.core.MatrixHelper;
...
Matrix predictors = MatrixHelper.read("bolts.csv", true, ',');
Matrix response = MatrixHelper.read("bolts_response.csv", true, ',');

System.out.println("\nPredictors");
System.out.println(MatrixHelper.toString(predictors));

System.out.println("\nResponse");
System.out.println(MatrixHelper.toString(response));

SIMPLS pls = new SIMPLS();
pls.setNumComponents(3);
String msg = pls.initialize(predictors, response);
if (msg != null) {
  System.out.println("\nInitialization failed:\n" + msg);
  return;
}
System.out.println("\nTransformed");
System.out.println(MatrixHelper.toString(pls.transform(predictors)));
System.out.println("\nPredictions");
System.out.println(MatrixHelper.toString(pls.predict(predictors)));
System.out.println("\nLoadings");
System.out.println(MatrixHelper.toString(pls.getLoadings()));