Example usage for weka.core.matrix Matrix getRowPackedCopy

List of usage examples for weka.core.matrix Matrix getRowPackedCopy

Introduction

In this page you can find the example usage for weka.core.matrix Matrix getRowPackedCopy.

Prototype

public double[] getRowPackedCopy() 

Source Link

Document

Make a one-dimensional row packed copy of the internal array.

Usage

From source file:adams.data.instancesanalysis.pls.SIMPLS.java

License:Open Source License

/**
 * Zeroes the coefficients of the W matrix beyond the specified number of
 * coefficients.//from w w w  .j a va 2 s .c  om
 *
 * @param in      the matrix to process in-place
 */
protected void slim(Matrix in) {
    double[][] B = in.getArray();

    for (int i = 0; i < in.getColumnDimension(); i++) {
        Matrix l = in.getMatrix(0, in.getRowDimension() - 1, i, i);
        double[] ld = l.getRowPackedCopy();
        for (int t = 0; t < ld.length; t++) {
            ld[t] = Math.abs(ld[t]);
        }
        int[] srt = weka.core.Utils.sort(ld);
        //int index = srt.length - 1 - srt[Math.min(getNumCoefficients(),srt.length-1)]; //nonono
        int index = srt[Math.max(srt.length - 1 - getNumCoefficients(), 0)];

        double val = ld[index];
        for (int c = 0; c < in.getRowDimension(); c++) {
            if (Math.abs(B[c][i]) < val) {
                B[c][i] = 0;
            }
        }
    }
}