Examples of DenseVector


Examples of edu.ucla.sspace.vector.DenseVector

    /**
     * {@inheritDoc}
     */
    public DoubleVector getRowVector(int row) {
        return new DenseVector(getRow(row));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

            return sim;
        }
       
        public DoubleVector getRowVector(int row) {
            int cols = columns();
            DoubleVector vec = new DenseVector(cols);
            for (int c = 0; c < cols; ++c) {
                vec.set(c, get(row, c));
            }
            return vec;
        }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    /**
     * {@inheritDoc}
     */
    public DoubleVector getColumnVector(int column) {
        return new DenseVector(getColumn(column));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    /**
     * {@inheritDoc}
     */
    public DoubleVector getRowVector(int row) {
        return new DenseVector(getRow(row));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        // Initialzie the centroid vectors and the cluster sizes.
        DoubleVector[] centroids = new DoubleVector[numClusters];
        counts = new int[numClusters];
        for (int c = 0; c < numClusters; ++c)
            centroids[c] = new DenseVector(matrix.columns());

        // For each initial assignment, add the vector to it's centroid and
        // increase the size of the cluster.
        int row = 0;
        for (Assignment assignment : assignments) {
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        protected DoubleVector computeSecondEigenVector(Matrix matrix,
                                                        int vectorLength) {
           // Compute pi, and D.  Pi is the normalized form of rho.  D a
           // diagonal matrix with sqrt(pi) as the values along the diagonal.
           // Also compute pi * D^-1.
            DoubleVector pi = new DenseVector(vectorLength);
            DoubleVector D = new DenseVector(vectorLength);
            DoubleVector piDInverse = new DenseVector(vectorLength);
            for (int i = 0; i < vectorLength; ++i) {
                double piValue = rho.get(i)/pSum;
                pi.set(i, piValue);
                if (piValue > 0d) {
                    D.set(i, Math.sqrt(piValue));
                    piDInverse.set(i, piValue / D.get(i));
                }
            }

            // Create the second largest eigenvector of the a scaled form of the
            // row normalized affinity matrix.  The computation is using the
            // power method such that the affinity matrix is never explicitly
            // computed.
            // piDInverse serves as a vector which is similar to the first eigen
            // vector.  The second eigen vector is assumed to be orthogonal to
            // piDInverse.  This algorithm makes O(log(matrix.rows())) passes
            // through the data matrix.
        
            // Step 1, generate a random vector, v,  that is orthogonal to
            // pi*D-Inverse.
            DoubleVector v = new DenseVector(vectorLength);
            for (int i = 0; i < v.length(); ++i)
                v.set(i, Math.random());

            // Make log(matrix.rows()) passes.
            int log = (int) Statistics.log2(vectorLength);
            for (int k = 0; k < log; ++k) {
                // start the orthonormalizing the eigen vector.
                v = orthonormalize(v, piDInverse);

                // Step 2, repeated, (a) normalize v (b) set v = Q*v, where Q =
                // D * R-Inverse * matrix * matrix-Transpose * D-Inverse.

                // v = Q*v is broken into 4 sub steps that allow for sparse
                // multiplications.
                // Step 2b-1) v = D-Inverse*v.
                for (int i = 0; i < vectorLength; ++ i)
                    if (D.get(i) != 0d)
                        v.set(i, v.get(i) / D.get(i));

                // Step 2b-2) v = matrix-Transpose * v.
                DoubleVector newV = computeMatrixTransposeV(matrix, v);

                // Step 2b-3) v = matrix * v.
                computeMatrixDotV(matrix, newV, v);

                // Step 2b-4) v = D*R-Inverse * v. Note that R is a diagonal
                // matrix with rho as the values along the diagonal.
                for (int i = 0; i < vectorLength; ++i) {
                    double oldValue = v.get(i);
                    double newValue = oldValue * D.get(i) / rho.get(i);
                    v.set(i, newValue);
                }
            }

            return v;
        }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    /**
     * {@inheritDoc}
     */
    public DoubleVector getColumnVector(int column) {
        DoubleVector col = new DenseVector(rows());
        for (int r = 0; r < rows(); ++r)
            col.set(r, getRowVector(r).get(column));
        return col;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        int vectorLength = matrix.rows();
        matrixRowSums = computeMatrixRowSum(matrix);
        dataMatrix = matrix;

        // Compute rho, where rho[i] = dataPoint_i DOT matrixRowSums.
        rho = new DenseVector(vectorLength);
        pSum = 0;
        for (int r = 0; r < matrix.rows(); ++r) {
            double dot = VectorMath.dotProduct(
                    matrixRowSums, matrix.getRowVector(r));
            pSum += dot;
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        // Create a reordering mapping for the indices in the original data
        // matrix and of rho.  The ith data point and rho value will be ordered
        // based on the position of the ith value in the second eigen vector
        // after it has been sorted.
        DoubleVector sortedRho = new DenseVector(matrix.rows());
        int[] reordering = new int[v.length()];
        for (int i = 0; i < v.length(); ++i) {
            reordering[i] = elementIndices[i].index;
            sortedRho.set(i, rho.get(elementIndices[i].index));
        }

        // Create the sorted matrix based on the reordering.  Note that both row
        // masked matrices internally handle masking a masked matrix to avoid
        // recursive calls to the index lookups.
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        // Initialize the clusters.
        double score = 0;
        DoubleVector[] centroids = new DoubleVector[numClusters];
        double[] sizes = new double[numClusters];
        for (int i = 0; i < centroids.length; ++i)
            centroids[i] = new DenseVector(data.columns());

        // Add vectors to each cluster.
        for (int i = 0; i < assignments.length; ++i) {
            VectorMath.add(centroids[assignments[i]], data.getRowVector(i));
            sizes[assignments[i]]++;
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.