Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.CompactSparseVector


    @Test (expected=IllegalArgumentException.class)
    public void testInvalidSparseListMatrix() {
        List<SparseDoubleVector> vectors = new ArrayList<SparseDoubleVector>();
        for (double[] values : INVALID_VALUES)
            vectors.add(new CompactSparseVector(values));
        Matrix m = new ListMatrix<SparseDoubleVector>(vectors);
    }
View Full Code Here


            rowWriteLock.lock();
            // ensure that another thread has not already added this row while
            // this thread was waiting on the lock
            rowEntry = sparseMatrix.get(row);
            if (rowEntry == null) {
                rowEntry = new AtomicVector(new CompactSparseVector());

                // update the bounds as necessary
                if (row >= rows.get()) {
                    rows.set(row + 1);
                }
View Full Code Here

        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())
            : Vectors.subview(v, 0, cols.get());
    }
View Full Code Here

     * @return an unsafe, non-atomic view of the row's data
     */
    public DoubleVector getRowVectorUnsafe(int row) {
        AtomicVector rowEntry = sparseMatrix.get(row);
        return (rowEntry == null)
            ? new CompactSparseVector(cols.get())
            : Vectors.immutable(Vectors.subview(rowEntry.getVector(),
                                                0, cols.get()));
    }
View Full Code Here

            rowWriteLock.lock();
            // ensure that another thread has not already added this row while
            // this thread was waiting on the lock
            rowEntry = sparseMatrix.get(row);
            if (rowEntry == null) {
                rowEntry = new AtomicSparseVector(new CompactSparseVector());

                // update the bounds as necessary
                if (row >= rows.get()) {
                    rows.set(row + 1);
                }
View Full Code Here

        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())
            : Vectors.subview(v, 0, cols.get());
    }
View Full Code Here

     * @return an unsafe, non-atomic view of the row's data
     */
    public SparseDoubleVector getRowVectorUnsafe(int row) {
        AtomicSparseVector rowEntry = sparseMatrix.get(row);
        return (rowEntry == null)
            ? new CompactSparseVector(cols.get())
            : Vectors.immutable(Vectors.subview(rowEntry.getVector(),
                                                0, cols.get()));
    }
View Full Code Here

                int nz = dis.readInt();
                double val = dis.readDouble();
                indices[i] = nz;
                values[i] = val;
            }
            rowVectors[row] = new CompactSparseVector(indices, values, cols);
        }
        return Matrices.asSparseMatrix(Arrays.asList(rowVectors));
    }
View Full Code Here

            case TEXT:
                return new DenseVector(loadTextVector(word));
            case BINARY:
                return new DenseVector(loadBinaryVector(word));
            case SPARSE_TEXT:
                return new CompactSparseVector(loadSparseTextVector(word));
            case SPARSE_BINARY:
                return new CompactSparseVector(loadSparseBinaryVector(word));
            }
        } catch (IOException ioe) {
            // rethrow as something catastrophic must have happened to the
            // underlying .sspace file
            throw new IOError(ioe);
View Full Code Here

    }

    private <E extends WeightedEdge> SparseDoubleVector computeWeightVector(
            WeightedGraph<E> g, int vertex) {

        SparseDoubleVector weightVec = new CompactSparseVector();//  g.order());
        Set<E> adjacent = g.getAdjacencyList(vertex);
       
        // Count how many neighbors have positive edge weights
        // (assume for now that all edges are weighted positive)
        double normalizer = 1d / adjacent.size();
       
        // For each of the neighbors, normalize the positive edge
        // weights by the number of neighbors (with pos. weights)
        for (E e : adjacent) {
            int v = (e.from() == vertex) ? e.to() : e.from();
            weightVec.set(v, normalizer * e.weight());
        }                   
       
        // Last, although the graph is assumed to not have self-loops, the
        // weight for an node to itself is the normalizing constant (1/num
        // positive weights).  This is analogous to the similarity contribution
        // from the keystone node in the unweighted version
        weightVec.set(vertex, normalizer);
        return weightVec;
    }
View Full Code Here

TOP

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

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.