Search in sources :

Example 1 with DenseDoubleAlgebra

use of cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra in project clusterMaker2 by RBVI.

the class ColtOps method invertMatrix.

/**
 * Invert the matrix in place
 */
public void invertMatrix() {
    if (!matrix.isSymmetrical()) {
        logger.warn("clusterMaker2 ColtMatrix: attempt to invert an assymetric network");
    }
    DenseDoubleAlgebra dda = new DenseDoubleAlgebra();
    DoubleMatrix2D inverse = dda.inverse(getData());
    ((ColtMatrix) matrix).data = inverse;
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 2 with DenseDoubleAlgebra

use of cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra in project clusterMaker2 by RBVI.

the class ColtOps method transpose.

/**
 * Create a new matrix that is the transpose of this matrix
 */
public Matrix transpose() {
    DenseDoubleAlgebra dda = new DenseDoubleAlgebra();
    DoubleMatrix2D trans = dda.transpose(matrix.data);
    ColtMatrix result = new ColtMatrix(matrix, trans);
    result.transposed = true;
    return result;
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 3 with DenseDoubleAlgebra

use of cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra in project clusterMaker2 by RBVI.

the class RunSCPS method getLMat.

// L = D^-1/2 * S * D^-1/2
public DoubleMatrix2D getLMat(DoubleMatrix2D sMat) {
    DenseDoubleAlgebra alg = new DenseDoubleAlgebra();
    DoubleMatrix2D dMat = getDMat(sMat);
    DoubleMatrix2D transDMat = getNegSqrRootDMat(dMat);
    return alg.mult(transDMat, alg.mult(sMat, transDMat));
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 4 with DenseDoubleAlgebra

use of cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra in project clusterMaker2 by RBVI.

the class RunSCPS method getNegSqrRoot.

// Calculate negative square root of matrix using singular value decomposition
public DoubleMatrix2D getNegSqrRoot(DoubleMatrix2D A) {
    // A = USV, where S is Diagnol Matrix
    DenseDoubleSingularValueDecomposition decomp = new DenseDoubleSingularValueDecomposition(A, true, true);
    DoubleMatrix2D U = decomp.getU();
    DoubleMatrix2D S = decomp.getS();
    DoubleMatrix2D V = decomp.getV();
    // S^1/2 = Square root of every value in diangol matrix
    for (int i = 0; i < S.rows(); i++) S.set(i, i, Math.pow(S.get(i, i), .5));
    // A^1/2 = VS^1/2U
    DenseDoubleAlgebra alg = new DenseDoubleAlgebra();
    DoubleMatrix2D sqrtA = alg.mult(alg.mult(V, S), U);
    // return A^-1/2
    return alg.inverse(sqrtA);
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DenseDoubleSingularValueDecomposition(cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition)

Example 5 with DenseDoubleAlgebra

use of cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra in project IR_Base by Linda-sunshine.

the class GaussianFields method test.

// Test the data set.
@Override
public double test() {
    _Node node;
    /**
     *Construct the nearest neighbor graph***
     */
    constructGraph(true);
    /**
     *Perform matrix inverse.***
     */
    DenseDoubleAlgebra alg = new DenseDoubleAlgebra();
    DoubleMatrix2D result = alg.inverse(m_graph);
    /**
     *setting up the corresponding weight for the true labels**
     */
    for (int i = m_U; i < m_L + m_U; i++) m_nodeList[i].m_classifierPred *= m_M;
    /**
     *get some statistics**
     */
    for (int i = 0; i < m_U; i++) {
        node = m_nodeList[i];
        double pred = 0;
        for (int j = 0; j < m_U + m_L; j++) pred += result.getQuick(i, j) * m_nodeList[j].m_label;
        // prediction for the unlabeled based on the labeled data and pseudo labels
        node.m_pred = pred;
        for (int j = 0; j < m_classNo; j++) m_pYSum[j] += Math.exp(-Math.abs(j - node.m_pred));
    }
    /**
     *evaluate the performance**
     */
    double acc = 0;
    int pred, ans;
    for (int i = 0; i < m_U; i++) {
        pred = getLabel(m_nodeList[i].m_pred);
        ans = m_testSet.get(i).getYLabel();
        m_TPTable[pred][ans] += 1;
        if (pred != ans) {
            if (m_debugOutput != null)
                debug(m_testSet.get(i));
        } else
            acc++;
    }
    m_precisionsRecalls.add(calculatePreRec(m_TPTable));
    return acc / m_U;
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) SparseDoubleMatrix2D(cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D) structures._Node(structures._Node)

Aggregations

DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)5 DenseDoubleAlgebra (cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra)5 DenseDoubleSingularValueDecomposition (cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition)1 SparseDoubleMatrix2D (cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D)1 structures._Node (structures._Node)1