Example usage for weka.core.matrix Matrix getArray

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

Introduction

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

Prototype

public double[][] getArray() 

Source Link

Document

Access the internal two-dimensional array.

Usage

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

License:Open Source License

/**
 * Turns a Weka matrix into a Jama one.//from   w  w w  .j av  a2  s .co m
 *
 * @param weka   the Weka matrix to convert
 * @return      the converted matrix
 */
public static Jama.Matrix wekaToJama(weka.core.matrix.Matrix weka) {
    return new Jama.Matrix(weka.getArray());
}

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

License:Open Source License

/**
 * Turns a Weka matrix into a matrix-algorithm one.
 *
 * @param weka   the Weka matrix to convert
 * @return      the converted matrix/*from   w  w w .  j a  v  a 2s  .  co m*/
 */
public static com.github.waikatodatamining.matrix.core.Matrix wekaToMatrixAlgo(weka.core.matrix.Matrix weka) {
    return MatrixFactory.fromRaw(weka.getArray());
}

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./*  w  ww. j av a  2s  .  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;
            }
        }
    }
}

From source file:meka.classifiers.multilabel.PLST.java

License:Open Source License

/**
 * Transforms the predictions of the internal classifier back to the original labels.
 *
 * @param y The predictions that should be transformed back. The array consists only of
 * the predictions as they are returned from the internal classifier.
 * @return The transformed predictions.//  w ww  .  ja  v a 2 s  . co m
 */
@Override
public double[] transformPredictionsBack(double[] y) {
    // y consists of predictions and maxindex, we need only predictions
    double[] predictions = new double[y.length / 2];

    for (int i = 0; i < predictions.length; i++) {
        predictions[i] = y[predictions.length + i];
    }

    double[][] dataArray = new double[1][predictions.length];

    dataArray[0] = predictions;

    Matrix yMat = new Matrix(dataArray);

    Matrix multiplied = yMat.times(this.m_v.transpose()).plus(m_Shift);

    double[] res = new double[multiplied.getColumnDimension()];

    // change back from -1/1 coding to 0/1
    for (int i = 0; i < res.length; i++) {
        res[i] = multiplied.getArray()[0][i] < 0.0 ? 0.0 : 1.0;
    }

    return res;
}

From source file:meka.core.MatrixUtils.java

License:Open Source License

/**
 * Helper method that transforms a Matrix object to an Instances object.
 *
 * @param mat The Matrix to transform.// w w w.j av a  2s .  c  o  m
 * @param patternInst the Instances template to use
 * @return  The resulting Instances object.
 */
public static Instances matrixToInstances(Matrix mat, Instances patternInst) {
    Instances result = new Instances(patternInst);
    for (int i = 0; i < mat.getRowDimension(); i++) {
        double[] row = mat.getArray()[i];
        DenseInstance denseInst = new DenseInstance(1.0, row);
        result.add(denseInst);
    }

    return result;
}