Examples of SparseDoubleVector


Examples of edu.ucla.sspace.vector.SparseDoubleVector

     */
    public SparseDoubleVector generateContext(DependencyTreeNode[] tree,
                                              int focusIndex) {
        DependencyTreeNode focusNode = tree[focusIndex];

        SparseDoubleVector meaning = new CompactSparseVector(indexVectorLength);

        Iterator<DependencyPath> paths = new FilteredDependencyIterator(
                focusNode, acceptor, pathLength);

        while (paths.hasNext()) {
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            // are traversed.
            SparseMatrix smatrix = (SparseMatrix) matrix;

            // Compute the col and row sums.
            for (int row = 0; row < matrix.rows(); ++row) {
                SparseDoubleVector rowVec = smatrix.getRowVector(row);
                int[] nonZeros = rowVec.getNonZeroIndices();
                for (int index : nonZeros) {
                    double value = rowVec.get(index);
                    rowSums[row] += (countRowOccurrances) ? 1 : value;
                    columnSums[index] += (countColumnOccurrances) ? 1 : value;
                    matrixSum += value;
                }
            }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

                // Ignore any focus words that are unaccepted by Wordsi.
                if (!acceptWord(focusNode, contextHeader, wordsi))
                    continue;

                // Create a new context vector.
                SparseDoubleVector focusMeaning = generator.generateContext(
                        nodes, wordIndex);
                wordsi.handleContextVector(
                        focusWord, secondarykey, focusMeaning);
            }
            document.close();
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        if (matrix instanceof SparseMatrix) {
            List<SparseDoubleVector> scaledVectors =
                new ArrayList<SparseDoubleVector>(matrix.rows());
            SparseMatrix sm = (SparseMatrix) matrix;
            for (int r = 0; r < matrix.rows(); ++r) {
                SparseDoubleVector v = sm.getRowVector(r);
                scaledVectors.add(new ScaledSparseDoubleVector(
                            v, 1/v.magnitude()));
            }
            return Matrices.asSparseMatrix(scaledVectors);
        } else {
            List<DoubleVector> scaledVectors =
                new ArrayList<DoubleVector>(matrix.rows());
            for (int r = 0; r < matrix.rows(); ++r) {
                DoubleVector v = matrix.getRowVector(r);
                scaledVectors.add(new ScaledDoubleVector(v, 1/v.magnitude()));
            }
            return Matrices.asMatrix(scaledVectors);
        }
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        // Get the first contextualized meaning.  Return any empty vector in
        // case we don't have any paths for the word of interest (this should
        // never happen).
        if (!paths.hasNext())
            return new CompactSparseVector();
        SparseDoubleVector focusMeaning = contextualize(paths.next());

        // If this focus word isn't connected to any other word, just return the
        // contextualized vector that we have.
        if (!paths.hasNext())
            return focusMeaning;
        SparseDoubleVector secondMeaning = contextualize(paths.next());

        // If we have two relations for the focus word, multiply each
        // contextualized vector from the relations and return that as the final
        // meaning.
        return VectorMath.multiplyUnmodified(focusMeaning, secondMeaning);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

    /**
     * {@inheritDoc}
     */
    public SparseDoubleVector generateContext(Queue<String> prevWords,
                                              Queue<String> nextWords) {
        SparseDoubleVector meaning = new CompactSparseVector(indexVectorLength);
        addContextTerms(meaning, prevWords, -1 * prevWords.size());
        addContextTerms(meaning, nextWords, 1);
        return meaning;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        LOGGER.info("CBC begining Phase 3");
        // PHASE 3: Assign elements to clusters
        Assignment[] result = new Assignment[m.rows()];
        for (int r = 0; r < m.rows(); ++r) {
            LOGGER.fine("Computing Phase 3 for row " + r);
            SparseDoubleVector row = sm.getRowVector(r);
            // Determine to which committees the row belongs
            List<Integer> committeeIds = phase3(
                row, committees, useHardClustering, softClusteringThresh);
            int[] assignments = new int[committeeIds.size()];
            for (int i = 0; i < committeeIds.size(); ++i) {
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

                 r = rowsToConsider.nextSetBit(r + 1)) {

            // 5.1) If e's similarity to every committee in C is below
            //      threshold2, add e to a list of residues R.
            boolean isResidue = true;
            SparseDoubleVector row = sm.getRowVector(r);
            for (Committee c : committees) {
                if (Similarity.cosineSimilarity(c.centroid(), row) >=
                        residueSimThresh) {
                    isResidue = false;
                }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            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

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            lockColumn(column, r);
        // Ensure that the column data is up to date
        while (lastVectorCacheUpdate.get() != modifications.get())
            updateVectorCache();
        int[] rowArr = colToRowsCache[column];
        SparseDoubleVector colVec = new SparseHashDoubleVector(r);
        for (int row : rowArr)
            colVec.set(row, matrixEntries.get(new Entry(row, column)));
        if (shouldLock)
            unlockColumn(column, r);
        return colVec;
    }
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.