/matrix-algorithms

Java library of 2-dimensional matrix algorithms.

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

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.16</version>
    </dependency>

Examples

PCA

import com.github.waikatodatamining.matrix.core.matrix.Matrix;
import com.github.waikatodatamining.matrix.algorithms.PCA;
import com.github.waikatodatamining.matrix.core.matrix.MatrixHelper;

public class Main {
  public static void main(String[] args) {
    
    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 com.github.waikatodatamining.matrix.core.matrix.Matrix;
import com.github.waikatodatamining.matrix.algorithms.pls.SIMPLS;
import com.github.waikatodatamining.matrix.core.matrix.MatrixHelper;

public class Main {
  public static void main(String[] args) {
    
    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);
    try {
      pls.configure(predictors, response);
    } catch (Exception e) {
      System.out.println("\nInitialization failed:\n" + e);
      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()));
    
  }
}