Search in sources :

Example 1 with Matrix

use of Jama.Matrix in project h2o-2 by h2oai.

the class CholTest method test.

public void test() {
    Log.info("CholTest::test enter");
    for (int sz = 6000; sz < 10000; sz += 2000) {
        Log.info("CholTest::test sz is " + sz);
        DataSetup data = new DataSetup(sz, 12345);
        long start = System.currentTimeMillis();
        CholeskyDecomposition jamaChol = new Matrix(data.xx).chol();
        Log.info("JAMA CHOLESKY [N = " + sz + "] TAKES " + (System.currentTimeMillis() - start) + " MILLISECONDS.");
        if (!jamaChol.isSPD())
            continue;
        ForkJoinPool fjp = new ForkJoinPool(32);
        for (int t = 2; t <= 32; t += 2) {
            for (int step : STEPS) fjp.invoke(new TestSetup(new DataSetup(data.xx), jamaChol.getL().getArray(), step, t));
        }
    }
    Log.info("CholTest::test exit");
}
Also used : CholeskyDecomposition(Jama.CholeskyDecomposition) Matrix(Jama.Matrix) ForkJoinPool(jsr166y.ForkJoinPool)

Example 2 with Matrix

use of Jama.Matrix in project knime-core by knime.

the class LogisticRegressionContent method getZScoreMatrix.

/**
 * Computes the Wald's statistic.
 */
private Matrix getZScoreMatrix() {
    Matrix stdErr = getStdErrorMatrix();
    // Wald's statistic
    Matrix waldStat = new Matrix(1, m_covMat.getRowDimension());
    for (int i = 0; i < m_covMat.getRowDimension(); i++) {
        waldStat.set(0, i, m_beta.get(0, i) / stdErr.get(0, i));
    }
    return waldStat;
}
Also used : Matrix(Jama.Matrix)

Example 3 with Matrix

use of Jama.Matrix in project knime-core by knime.

the class LogisticRegressionContent method getPValueMatrix.

/**
 * Computes the two-tailed p-values of the z-test, which can be calculated
 * by 2*Phi(-|Z|), where Phi is the standard normal cumulative
 * distribution function.
 */
private Matrix getPValueMatrix() {
    Matrix zScore = getZScoreMatrix();
    // p-value
    Matrix pvalue = new Matrix(1, m_covMat.getRowDimension());
    for (int i = 0; i < m_covMat.getRowDimension(); i++) {
        double absZ = Math.abs(zScore.get(0, i));
        pvalue.set(0, i, 2 * Gaussian.Phi(-absZ));
    }
    return pvalue;
}
Also used : Matrix(Jama.Matrix)

Example 4 with Matrix

use of Jama.Matrix in project knime-core by knime.

the class EigenValue method createSortedList.

/**
 * create list of {@link EigenValue}s sorted by absolute value
 * @param eigenVectors matrix of eigenvector (in columns)
 * @param eigenvalues eigenvalues, same order as columns of eigenVectors
 * @return sorted list of {@link EigenValue}s
 */
public static List<EigenValue> createSortedList(final double[][] eigenVectors, final double[] eigenvalues) {
    final int[] rowindices = new int[eigenvalues.length];
    final Matrix v = new Matrix(eigenVectors);
    for (int i = 0; i < rowindices.length; i++) {
        rowindices[i] = i;
    }
    final LinkedList<EigenValue> list = new LinkedList<EigenValue>();
    for (int i = 0; i < eigenvalues.length; i++) {
        list.add(new EigenValue(i, eigenvalues[i], v.getMatrix(rowindices, new int[] { i })));
    }
    Collections.sort(list);
    return list;
}
Also used : Matrix(Jama.Matrix) LinkedList(java.util.LinkedList)

Example 5 with Matrix

use of Jama.Matrix in project knime-core by knime.

the class PCAComputeNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    if (!(inData[DATA_INPORT] instanceof BufferedDataTable)) {
        throw new IllegalArgumentException("Datatable as input expected");
    }
    final BufferedDataTable dataTable = (BufferedDataTable) inData[DATA_INPORT];
    if (dataTable.size() == 0) {
        throw new IllegalArgumentException("Input table is empty!");
    }
    final double[] meanVector = PCANodeModel.getMeanVector(dataTable, m_inputColumnIndices, m_failOnMissingValues.getBooleanValue(), exec.createSubExecutionContext(0.4));
    final double[][] m = new double[m_inputColumnIndices.length][m_inputColumnIndices.length];
    exec.checkCanceled();
    final int missingValues = PCANodeModel.getCovarianceMatrix(exec.createSubExecutionContext(0.4), dataTable, m_inputColumnIndices, meanVector, m);
    if (missingValues > 0) {
        if (m_failOnMissingValues.getBooleanValue()) {
            throw new IllegalArgumentException("missing, infinite or impossible values in table");
        }
        setWarningMessage(missingValues + " rows ignored because of missing, " + "infinite or impossible values");
    }
    exec.checkCanceled();
    final Matrix covarianceMatrix = new Matrix(m);
    exec.setProgress("calculation of spectral decomposition");
    final EigenvalueDecomposition evd = covarianceMatrix.eig();
    exec.checkCanceled();
    exec.setProgress(0.9);
    final Matrix d = evd.getD();
    final double[] evs = new double[d.getRowDimension()];
    for (int i = 0; i < evs.length; i++) {
        evs[i] = d.get(i, i);
    }
    exec.checkCanceled();
    return new PortObject[] { PCANodeModel.createCovarianceTable(exec, m, m_inputColumnNames), PCANodeModel.createDecompositionOutputTable(exec.createSubExecutionContext(0.1), evd, m_inputColumnNames), new PCAModelPortObject(evd.getV().getArray(), evs, m_inputColumnNames, meanVector) };
}
Also used : Matrix(Jama.Matrix) EigenvalueDecomposition(Jama.EigenvalueDecomposition) BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject)

Aggregations

Matrix (Jama.Matrix)20 DataCell (org.knime.core.data.DataCell)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)4 PortObject (org.knime.core.node.port.PortObject)4 CholeskyDecomposition (Jama.CholeskyDecomposition)3 EigenvalueDecomposition (Jama.EigenvalueDecomposition)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataRow (org.knime.core.data.DataRow)3 RowKey (org.knime.core.data.RowKey)3 CellFactory (org.knime.core.data.container.CellFactory)3 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)3 DataTable (org.knime.core.data.DataTable)2 SingularValueDecomposition (Jama.SingularValueDecomposition)1 Gram (hex.gram.Gram)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1