Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.SparseDoubleVector


        // Iterate through each row of Y, and thux AX-Y.  For each row, compute
        // the difference between the two matrics.  Then multiply the values in
        // the correspond column of X' against this difference matrix. 
        for (int r = 0; r < Y.rows(); ++r) {
            // Get the row vector of Y.
            SparseDoubleVector v = Y.getRowVector(r);
            double[] vDiff = new double[v.length()];
            // Compute the difference between the row vector of AX and the row
            // vector of Y.  This is the straightforward dot product between A_i
            // and X'_i.
            for (int c = 0; c < X.columns(); c++) {
                double sum = 0;
                for (int k = 0; k < A.columns(); ++k)
                    sum += A.get(r, k) * X.get(k, c);
                vDiff[c] = sum - v.get(c);
            }

            for (int k = 0; k < X.rows(); ++k) {
                double sum = 0;
                for (int c = 0; c < X.columns(); ++c)
View Full Code Here


            PrintWriter affMatrixWriter = new PrintWriter(affMatrixFile);

            // Keep track of the first row and have a reference to the next row.
            // The nextRow reference avoid us having to advance into data
            // unnecessarily to retrieval the vector for processing to start
            SparseDoubleVector curRow = null;
            SparseDoubleVector nextRow = null;

            SvdlibcSparseBinaryFileRowIterator matrixIter =
                new SvdlibcSparseBinaryFileRowIterator(converted);
           
            for (int row = 0; row < rows; ++row) {
                LOG.fine("computing affinity for row " + row);

                // Loop through each of the rows, gathering the statistics
                // necessary to compute the affinity matrix.
                for (int other = 0; other < rows; ++other) {

                    // Special case for the very first row
                    if (row == 0 && curRow == null) {
                        curRow = matrixIter.next();
                        continue;
                    }
                   
                    SparseDoubleVector otherRow = matrixIter.next();

                    // Special case for the similarity threshold, which is
                    // symmetric.  In this case, we can skip over processing any
                    // rows that occur before the current row
                    if (other < row)
View Full Code Here

    public static EntropyStats entropy(SparseMatrix m) {
        double sum = 0;
        double[] colSums = new double[m.columns()];
        double[] rowSums = new double[m.rows()];
        for (int r = 0; r < m.rows(); ++r) {
            SparseDoubleVector sv = m.getRowVector(r);
            for (int c : sv.getNonZeroIndices()) {
                double v = m.get(r, c);
                sum += v;
                colSums[c] += v;
                rowSums[r] += v;
            }
        }

        double entropy = 0;
        double[] colEntropy = new double[m.columns()];
        double[] rowEntropy = new double[m.rows()];
        for (int r = 0; r < m.rows(); ++r) {
            SparseDoubleVector sv = m.getRowVector(r);
            for (int c : sv.getNonZeroIndices()) {
                double v = m.get(r, c);
                entropy -= entropy(v, sum);
                colEntropy[c] -= entropy(v, colSums[c]);
                rowEntropy[r] -= entropy(v, rowSums[r]);
            }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public SparseDoubleVector getColumnVector(int column) {
        int rows = rows();
        SparseDoubleVector v = new SparseHashDoubleVector(rows);
        for (int row = 0; row < rows; ++row) {
            double d = get(row, column);
            if (d != 0)
                v.set(row, d);
        }
        return v;
    }
View Full Code Here

     * to {@link #rows()}
     */
    public SparseDoubleVector getColumnVector(int column) {
        checkIndices(0, column);
        rowReadLock.lock();
        SparseDoubleVector values = new SparseHashDoubleVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            AtomicSparseVector rowEntry = getRow(row, -1, false);           
            double value = 0;
            if (rowEntry != null && (value = rowEntry.get(column)) != 0)
                values.set(row, value);
        }
        rowReadLock.unlock();
        return values;
    }
View Full Code Here

     * cases where the vector is being accessed at a time when the matrix (or
     * this particular row) will not be modified.
     */
    public SparseDoubleVector getColumnVectorUnsafe(int column) {
        checkIndices(0, column);
        SparseDoubleVector values = new SparseHashDoubleVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            AtomicSparseVector rowEntry = getRow(row, -1, false);           
            double value = 0;
            if (rowEntry != null && (value = rowEntry.get(column)) != 0)
                values.set(row, value);
        }
        return values;
    }
View Full Code Here

     * {@inheritDoc} The length of the returned row vector reflects the size of
     * matrix at the time of the call, which may be different from earlier calls
     * to {@link #columns()}.
     */
    public SparseDoubleVector getRowVector(int row) {
        SparseDoubleVector v = getRow(row, -1, false);
        // If no row was currently assigned in the matrix, then return an empty
        // vector in its place.  Otherwise, return a view on top of the vector
        // with its current length
        return (v == null)
            ? new CompactSparseVector(cols.get())
View Full Code Here

                // Compute the entropy for each row.
                for (int row = 0; row < matrix.rows(); ++row) {
                    // Compute the total count for each row.
                    double rowCount = 0;
                    SparseDoubleVector rowVec = smatrix.getRowVector(row);
                    int[] nonZeros = rowVec.getNonZeroIndices();
                    for (int index : nonZeros) {
                        double value = rowVec.get(index);
                        rowCount += value;
                    }

                    // Compute the entropy of each row based on the occurances
                    // of each row.
                    for (int index : nonZeros) {
                        double value = rowVec.get(index);
                        double rowProbabilityForFeature = value / rowCount;
                        rowEntropy[row] += rowProbabilityForFeature *
                                           log2(rowProbabilityForFeature);
                    }

View Full Code Here

            SparseMatrix smatrix = (SparseMatrix) matrix;

            // Copy a sparse matrix by only iterating over the non zero
            // values in each row.
            for (int row = 0; row < matrix.rows(); ++row) {
                SparseDoubleVector rowVec = smatrix.getRowVector(row);
                for (int col : rowVec.getNonZeroIndices())
                    output.set(row, col, rowVec.get(col));
            }
        } else {
            for (int row = 0; row < matrix.rows(); ++row)
                for (int col = 0; col < matrix.columns(); ++col)
                    output.set(row, col, matrix.get(row, col));
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public SparseDoubleVector getColumnVector(int column) {
        checkIndices(0, column);
        SparseDoubleVector columnValues =
            new SparseHashDoubleVector(values.length);
        columnValues.set(column, values[column]);
        return columnValues;
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.vector.SparseDoubleVector

Copyright © 2018 www.massapicom. 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.