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");
}
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;
}
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;
}
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;
}
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) };
}
Aggregations