Examples of DoubleVector


Examples of edu.ucla.sspace.vector.DoubleVector

        final SortedMultiMap<Double,Map.Entry<DoubleVector,Set<String>>>
            mostSimilarPrincipleVectors = new BoundedSortedMultiMap
                <Double,Map.Entry<DoubleVector,Set<String>>>(k, false);       
        for (Map.Entry<DoubleVector,Set<String>> e :
                 principleVectorToNearestTerms.asMap().entrySet()) {
            DoubleVector pVec = e.getKey();
            double sim = Similarity.cosineSimilarity(v, pVec);
            mostSimilarPrincipleVectors.put(sim, e);
        }
       
        // Create a global map to store the results of the principle vectors'
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    /**
     * {@inheritDoc}
     */
    public double getKMeansObjective() {
        // Note that the scaled vector handles any recursive scaling.
        DoubleVector centroid = new ScaledDoubleVector(
                matrixRowSums, 1/((double) dataMatrix.rows()));
        double score = 0;
        for (int r = 0; r < dataMatrix.rows(); ++r)
            score += VectorMath.dotProduct(
                    centroid, dataMatrix.getRowVector(r));
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

        DoubleVector[] centroids = new DoubleVector[numComparisons.length];
        int[] centroidSizes = new int[numComparisons.length];
        double intraClusterScore = 0;
        for (int i = 0; i < assignments.length; ++i) {
            int assignment = assignments[i];
            DoubleVector v = m.getRowVector(i);
            if (centroids[assignment] == null)
                centroids[assignment] = Vectors.copyOf(v);
            else {
                DoubleVector centroid = centroids[assignment];
                intraClusterScore += (centroidSizes[assignment] -
                                      VectorMath.dotProduct(v, centroid));
                VectorMath.add(centroid, v);
                numComparisons[assignment] += centroidSizes[assignment];
            }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    protected static int computeCut(Matrix matrix,
                                    DoubleVector rho,
                                    double rhoSum,
                                    DoubleVector matrixRowSums) {
        // Compute the conductance of the newly sorted matrix.
        DoubleVector x = new DenseVector(matrix.columns());
        DoubleVector y = matrixRowSums;
        VectorMath.subtract(y, x);

        // First compute x and y, which are summations of different cuts of the
        // matrix, starting with x being the first row and y being the summation
        // of all other rows.  While doing this, also compute different
        // summations of values in the rho vector using the same cut.
        VectorMath.add(x, matrix.getRowVector(0));
        double rhoX = rho.get(0);
        double rhoY = rhoSum - rho.get(0);

        // Compute the dot product between the first possible cut.
        double u = VectorMath.dotProduct(x, y);

        // Find the current conductance for the cut, assume that this is the
        // best so far.
        double minConductance = u / Math.min(rhoX, rhoY);
        int cutIndex = 0;

        // Compute the other possible cuts, ignoring the last cut, which would
        // leave no data points in a partition.  The cut with the smallest
        // conductance is maintained.
        for (int i = 1; i < rho.length() - 2; ++i) {
            // Compute the new value of u, the denominator for computing the
            // conductance.
            DoubleVector vector = matrix.getRowVector(i);
            double xv = VectorMath.dotProduct(x, vector);
            double yv = VectorMath.dotProduct(y, vector);
            u = u - xv + yv + 1;

            // Shift over vectors from y to x.
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

     * This method also assumes that {@code matrix} is row based and iterates
     * over each of the values in the row before iterating over another row.
     */
    protected static DoubleVector computeMatrixTransposeV(Matrix matrix,
                                                          DoubleVector v) {
        DoubleVector newV = new DenseVector(matrix.columns());
        if (matrix instanceof SparseMatrix) {
            SparseMatrix smatrix = (SparseMatrix) matrix;
            for (int r = 0; r < smatrix.rows(); ++r) {
                SparseDoubleVector row = smatrix.getRowVector(r);
                int[] nonZeros = row.getNonZeroIndices();
                for (int c : nonZeros)
                    newV.add(c, row.get(c) * v.get(r));
            }
        } else {
            for (int r = 0; r < matrix.rows(); ++r)
                for (int c = 0; c < matrix.columns(); ++c)
                    newV.add(c, matrix.get(r, c) * v.get(r));
        }
        return newV;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

     * Compute the row sums of the values in {@code matrix} and returns the
     * values in a vector of length {@code matrix.columns()}.
     */
    protected static <T extends Matrix> DoubleVector computeMatrixRowSum(
            T matrix) {
        DoubleVector rowSums = new DenseVector(matrix.columns());
        for (int r = 0; r < matrix.rows(); ++r)
            VectorMath.add(rowSums, matrix.getRowVector(r));
        return rowSums;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    @Test
    public void testGetRowVector() {
        Matrix baseMatrix = new ArrayMatrix(baseValues);
        Matrix maskedMatrix = new CellMaskedMatrix(baseMatrix, rowMap, colMap);
        for (int r = 0; r < maskedMatrix.rows(); ++r) {
            DoubleVector rowVector = maskedMatrix.getRowVector(r);
            assertEquals(4, rowVector.length());
            for (int c = 0; c < 4; ++c)
                assertEquals(getBaseValue(baseMatrix, r, c),
                             rowVector.get(c), .000001);
        }
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    @Test
    public void testGetColumnVector() {
        Matrix baseMatrix = new ArrayMatrix(baseValues);
        Matrix maskedMatrix = new CellMaskedMatrix(baseMatrix, rowMap, colMap);
        for (int c = 0; c < maskedMatrix.columns(); ++c) {
            DoubleVector colVector = maskedMatrix.getColumnVector(c);
            assertEquals(3, colVector.length());
            for (int r = 0; r < 3; ++r)
                assertEquals(getBaseValue(baseMatrix, r, c),
                             colVector.get(r), .000002);
        }
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    @Test
    public void testSetRowVector() {
        Matrix baseMatrix = new ArrayMatrix(baseValues);
        Matrix maskedMatrix = new CellMaskedMatrix(baseMatrix, rowMap, colMap);
        DoubleVector row = new DenseVector(new double[]{1, 2, 3, 4});
        maskedMatrix.setRow(0, row);
        for (int i = 0; i < 4; i++)
            assertEquals(getBaseValue(baseMatrix, 0, i), row.get(i), .000001);
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    @Test
    public void testSetColumnVector() {
        Matrix baseMatrix = new ArrayMatrix(baseValues);
        Matrix maskedMatrix = new CellMaskedMatrix(baseMatrix, rowMap, colMap);
        DoubleVector col = new DenseVector(new double[] {1, 2, 3});
        maskedMatrix.setColumn(0, col);
        for (int i = 0; i < 3; i++)
            assertEquals(getBaseValue(baseMatrix, i, 0), col.get(i), .000001);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.