Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.DoubleVector


     * between newly nerged clusters.
     */
    public Assignments cluster(Matrix m, int numClusters, Properties props) {
        Matrix adj = new SymmetricMatrix(m.rows(), m.rows());
        for (int r = 0; r < m.rows(); ++r) {
            DoubleVector v = m.getRowVector(r);
            for (int c = r+1; c < m.rows(); ++c)
                adj.set(r,c, simFunc.sim(v, m.getRowVector(c)));
        }
        return clusterAdjacencyMatrix(adj, method, numClusters);
    }
View Full Code Here


    public synchronized int addColumn(Vector col) {
        if (isFinished)
            throw new IllegalStateException(
                "Cannot add columns to a MatrixBuilder that is finished");

        DoubleVector column = Vectors.asDouble(col);

        if (column.length() > numRows)
            numRows = column.length();

        // Vector instances can take on the maximum possible array size when the
        // vector length isn't specified.  This ruins the matrix size
        // specification since the matrix shouldn't actually be that big.
        // However, because this is an implementation artifact, we can't check
        // for it explicitly with an exception.  Therefore, put in an assert to
        // indicate what is likely going on if asserts are enabled for debugging
        // they symptoms.
        assert column.length() != Integer.MAX_VALUE : "adding a column whose " +
            "length is Integer.MAX_VALUE (was likley left unspecified in the " +
            " constructor).";

        // Special case for sparse Vectors, for which we already know the
        // non-zero indices for the column
        if (column instanceof SparseVector) {
            SparseVector s = (SparseVector)column;
            int[] nonZero = s.getNonZeroIndices();
            nonZeroValues += nonZero.length;
            System.out.println(nonZero.length);
            try {
                matrixDos.writeInt(nonZero.length);
                for (int i : nonZero) {
                    double val = column.get(i);
                    matrixDos.writeInt(i); // write the row index
                    matrixDos.writeFloat((float)val);
                }
            } catch (IOException ioe) {
                throw new IOError(ioe);
            }
        }
        // For dense Vectors, find which values are non-zero and write only
        // those
        else {
            int nonZero = 0;
            for (int i = 0; i < column.length(); ++i) {
                double d = column.get(i);
                if (d != 0d)
                    nonZero++;                   
            }

            // Update the matrix count
            nonZeroValues += nonZero;
            try {
                matrixDos.writeInt(nonZero);
                // Write the number of non-zero values in the column
                for (int i = 0; i < column.length(); ++i) {
                    double value = column.get(i);
                    if (value != 0d) {
                        matrixDos.writeInt(i); // write the row index
                        matrixDos.writeFloat((float)value);
                    }
                }
View Full Code Here

        // comes up when comparing other solutions to the non-solution.
        if (numClusters != 1) {
            int nc = 0;
            for (int i = 0; i < matrix.rows(); ++i) {

                DoubleVector vector = matrix.getRowVector(i);
                double bestSimilarity = 0;
                for (int c = 0; c < numClusters; ++c) {
                    double similarity = Similarity.cosineSimilarity(
                            centers[c], vector);
                    nc++;
View Full Code Here

     * to {@link #rows()}
     */
    public DoubleVector getColumnVector(int column) {
        checkIndices(0, column);
        rowReadLock.lock();
        DoubleVector values = new DenseVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            double value = get(row, column);
            if (value != 0d)
                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 DoubleVector getColumnVectorUnsafe(int column) {
        checkIndices(0, column);
        DoubleVector values = new DenseVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            AtomicVector 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 DoubleVector getRowVector(int row) {
        DoubleVector 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

    /**
     * {@inheritDoc}
     */
    public DoubleVector getColumnVector(int column) {
        column = getIndexFromMap(colMaskMap, column);
        DoubleVector v = matrix.getColumnVector(column);
        return new MaskedDoubleVectorView(v, rowMaskMap);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public DoubleVector getRowVector(int row) {
        row = getIndexFromMap(rowMaskMap, row);
        DoubleVector v = matrix.getRowVector(row);
        return new MaskedDoubleVectorView(v, colMaskMap);
    }
View Full Code Here

            // between row j and row i, assuming that the edge similarity metric
            // is symmetric.  Each edge is written in the Matlab Sparse matrix
            // format.
            for (int i = 0; i < rows; ++i) {
                LOG.fine("computing affinity for row " + i);
                DoubleVector row1 = input.getRowVector(i);
                for (int j = i+1; j < rows; ++j) {
                    DoubleVector row2 = input.getRowVector(j);

                    double dataSimilarity = edgeSim.sim(row1, row2);

                    // If the edge similarity is above the threshold, compute
                    // the kernel similarity for each new edge.
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public DoubleVector getColumnVector(int column) {
        int i = 0;
        DoubleVector columnValues = new DenseVector(vectors.size());

        for (DoubleVector vector : vectors)
            columnValues.set(i++, vector.get(column));
        return columnValues;
    }
View Full Code Here

TOP

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

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.