Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.CompactSparseVector


            return Collections.singletonList(mostSimilarCommittee);
        }
        else {
            // Make a copy of the row because will be changing the vector as we
            // assign it to more committees
            SparseDoubleVector copy = new CompactSparseVector(row);
           
            // let C be a list of clusters initially empty
            List<Integer> assignedClusters = new ArrayList<Integer>();
           
            // let S be the top-200 similar clusters to e
            MultiMap<Double,Duple<Committee,Integer>> mostSimilarCommittees =
                new BoundedSortedMultiMap<Double,Duple<Committee,Integer>>(200);
            // for (Committee c : committees)
            for (int i = 0; i < committees.size(); ++i) {
                Committee c = committees.get(i);
                mostSimilarCommittees.put(
                Similarity.cosineSimilarity(row, c.centroid()),
                new Duple<Committee,Integer>(c, i));
            }
           
            //         System.out.println("Most similar committees: " +
            //                            mostSimilarCommittees);
           
            // while S is not empty {
            // let c be the most similar cluster to e
            for (Duple<Committee,Integer> p : mostSimilarCommittees.values()) {
                Committee c = p.x;
                Integer comId = p.y;
               
                SparseDoubleVector centroid = c.centroid();
               
                // if the similarity(e, c) < SIGMA, exit the loop
                if (Similarity.cosineSimilarity(copy, centroid) < 0) {
                    // NOTE: we intentionally don't exit the loop
                    continue;
                }
               
                // if c is not similar to any cluster in C {
                boolean isSimilar = false;
                for (Integer committeeId : assignedClusters) {
                    Committee c2 = committees.get(committeeId);
                    if (Similarity.cosineSimilarity(c2.centroid(), centroid)
                            >= softClusteringThresh) {
                        isSimilar = true;
                        break;
                    }
                }
                if (!isSimilar) {
                    // assign e to c
                    assignedClusters.add(comId);         
                   
                    // remove from e its features that overlap with the features of
                    // c; remove c from S
                    for (int i : centroid.getNonZeroIndices()) {
                        copy.set(i, 0);
                    }
                }
            }
            return assignedClusters;
        }
View Full Code Here


    /**
     * Create a new empty {@code GrowingSparseMatrix} which uses a {@link
     * CompactSparseVector} as the backing data structure.
     */
    public GrowingSparseMatrix() {
        this(new CompactSparseVector());
    }
View Full Code Here

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

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

    public YaleSparseMatrix(int rows, int cols) {
        this.rows = rows;
        this.cols = cols;
        sparseMatrix = new CompactSparseVector[rows];
        for (int i = 0; i < rows; ++i)
            sparseMatrix[i] = new CompactSparseVector(cols);
    }
View Full Code Here

        for (int r = 0; r < rows; ++r) {
            if (values[r].length != cols)
                throw new IllegalArgumentException(
                        "Cannot form matrix from jagged array");

            sparseMatrix[r] = new CompactSparseVector(cols);
            for (int c = 0; c < cols; ++c)
                if (values[r][c] != 0d)
                    set(r, c, values[r][c]);
        }
    }
View Full Code Here

        if (numClusters == 0)
            return centroids;

        counts = new int[numClusters];
        for (int c = 0; c < numClusters; ++c)
            centroids[c] = new CompactSparseVector(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

               "12  .   _   .   .   _   3   P   _   _");

    private SparseDoubleVector testVector;

    @Test public void testProcessDocument() throws Exception {
        testVector = new CompactSparseVector(new double[] {0, 0, 1, 0});
        Map<String, String> termMap = new HashMap<String, String>();
        DependencyContextExtractor extractor =
            new PseudoWordDependencyContextExtractor(
                    new CoNLLDependencyExtractor(),
                    new MockGenerator(), termMap);
View Full Code Here

        "12  .   _   .   .   _   3   P   _   _";

    private SparseDoubleVector testVector;

    @Test public void testProcessDocument() throws Exception {
        testVector = new CompactSparseVector(new double[] {0, 0, 1, 0});
        DependencyContextExtractor extractor =
            new SemEvalDependencyContextExtractor(
                    new CoNLLDependencyExtractor(), new MockGenerator());
        MockWordsi wordsi = new MockWordsi(null, extractor);
View Full Code Here

        "12  .   _   .   .   _   3   P   _   _";

    private SparseDoubleVector testVector;

    @Test public void testProcessDocument() throws Exception {
        testVector = new CompactSparseVector(new double[] {0, 0, 1, 0});
        DependencyContextExtractor extractor = new DependencyContextExtractor(
                    new CoNLLDependencyExtractor(), new MockGenerator());
        MockWordsi wordsi = new MockWordsi(null, extractor);

        extractor.processDocument(
View Full Code Here

    };

    @Test public void testSparseListMatrix() {
        List<SparseDoubleVector> vectors = new ArrayList<SparseDoubleVector>();
        for (double[] values : VALUES)
            vectors.add(new CompactSparseVector(values));
        Matrix m = new ListMatrix<SparseDoubleVector>(vectors);
        assertEquals(VALUES.length, m.rows());
        assertEquals(VALUES[0].length, m.columns());
        for (int r = 0; r < m.rows(); ++r)
            for (int c = 0; c < m.columns(); ++c)
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.