Examples of DenseVector


Examples of edu.ucla.sspace.vector.DenseVector

    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
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        Random random = new Random();

        final DoubleVector[] principles = new DoubleVector[numPrincipleVectors];
        for (int i = 0; i < principles.length; ++i)
            principles[i] = new DenseVector(sspace.getVectorLength());

        // Randomly assign the data set to different intitial clusters
        final MultiMap<Integer,Integer> clusterAssignment =
            new HashMultiMap<Integer,Integer>();
        for (int i = 0; i < numTerms; ++i)
            clusterAssignment.put(random.nextInt(numPrincipleVectors), i);
       
        int numIters = 1;
        for (int iter = 0; iter < numIters; ++iter) {
            verbose(LOGGER, "Computing principle vectors (round %d/%d)", iter+1, numIters);
            // Compute the centroids
            for (Map.Entry<Integer,Set<Integer>> e
                     : clusterAssignment.asMap().entrySet()) {
                int cluster = e.getKey();
                DoubleVector principle = new DenseVector(sspace.getVectorLength());
                principles[cluster] = principle;
                for (Integer row : e.getValue())
                    VectorMath.add(principle, termVectors.get(row));
            }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

     * 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.DenseVector

    public SortedMultiMap<Double,String> getMostSimilar(
             Set<String> terms, int numberOfSimilarWords) {
        if (terms.isEmpty())
            return null;
        // Compute the mean vector for all the terms
        DoubleVector mean = new DenseVector(sspace.getVectorLength());
        int found = 0;
        for (String term : terms) {
            Vector v = sspace.getVector(term);
            if (v == null)
                info(LOGGER, "No vector for term " + term);
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

     * 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.DenseVector

    @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.DenseVector

    @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

Examples of edu.ucla.sspace.vector.DenseVector

    @Test (expected=UnsupportedOperationException.class)
    public void testFailSetColumnFull() {
        SparseMatrix base = matrix();
        Matrix scaled = new RowScaledSparseMatrix(base, SCALE);
        scaled.setColumn(0, new DenseVector(new double[] {1, 1, 1}));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    @Test (expected=UnsupportedOperationException.class)
    public void testFailSetRowFull() {
        SparseMatrix base = matrix();
        Matrix scaled = new RowScaledSparseMatrix(base, SCALE);
        scaled.setRow(0, new DenseVector(VALUES[0]));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    @Test (expected=UnsupportedOperationException.class)
    public void testFailSetColumnFull() {
        Matrix base = new ArrayMatrix(VALUES);
        Matrix scaled = new RowScaledMatrix(base, SCALE);
        scaled.setColumn(0, new DenseVector(new double[] {1, 1, 1}));
    }
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.