Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.CompactSparseVector


                    RelationTuple relationKey = new RelationTuple(
                            focusIndex, relation.relation().intern());
                    SparseDoubleVector relationVector = localTuples.get(
                            relationKey);
                    if (relationVector == null) {
                        relationVector = new CompactSparseVector();
                        localTuples.put(relationKey, relationVector);
                    }
                    relationVector.add(featureIndex, 1);
                }
            }
        }

        document.close();

        // Once the document has been processed, update the co-occurrence matrix
        // accordingly.
        for (Map.Entry<Pair<String>,Double> e : localLemmaCounts.entrySet()){
            // Push the local co-occurrence counts to the larger mapping.
            Pair<String> p = e.getKey();

            // Get the prefernce vectors for the current focus word.  If they do
            // not exist, create it in a thread safe manner.
            SelectionalPreference preference = preferenceVectors.get(p.x);
            if (preference == null) {
                synchronized (this) {
                    preference = preferenceVectors.get(p.x);
                    if (preference == null) {
                        preference = new SelectionalPreference(combinor);
                        preferenceVectors.put(p.x, preference);
                    }
                }
            }
            // Add the local count.
            synchronized (preference) {
                preference.lemmaVector.add(
                        termBasis.getDimension(p.y), e.getValue());
            }
        }

        // Push the relation tuple counts to the larger counts.
        for (Map.Entry<RelationTuple, SparseDoubleVector> r :
                localTuples.entrySet()) {
            // Get the global counts for this relation tuple.  If it does not
            // exist, create a new one in a thread safe manner.
            SparseDoubleVector relationCounts = relationVectors.get(r.getKey());
            if (relationCounts == null) {
                synchronized (this) {
                    relationCounts = relationVectors.get(r.getKey());
                    if (relationCounts == null) {
                        relationCounts = new CompactSparseVector();
                        relationVectors.put(r.getKey(), relationCounts);
                    }
                }
            }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public void processSpace(Properties properties) {
        SparseDoubleVector empty = new CompactSparseVector();
        for (Map.Entry<RelationTuple, SparseDoubleVector> e :
                relationVectors.entrySet()) {
            RelationTuple relation = e.getKey();
            SparseDoubleVector relationCounts = e.getValue();
            String headWord = termBasis.getDimensionDescription(relation.head);
View Full Code Here

    private final VectorCombinor combinor;

    public SelectionalPreference(VectorCombinor combinor) {
        this.combinor = combinor;

        lemmaVector = new CompactSparseVector();
        selPreferences = new HashMap<String, SparseDoubleVector>();
        inverseSelPreferences = new HashMap<String, SparseDoubleVector>();
    }
View Full Code Here

            synchronized(this) {
                // recheck in case another thread added it while we were waiting
                // for the lock
                v = termToVector.get(word);
                if (v == null) {
                    v = new CompactSparseVector();
                    termToVector.put(word, v);
                }
            }
        }
        return v;
View Full Code Here

            synchronized(this) {
                // recheck in case another thread added it while we were waiting
                // for the lock
                v = wordToSemantics.get(word);
                if (v == null) {
                    v = new CompactSparseVector();
                    wordToSemantics.put(word, v);
                }
            }
        }
        return v;
View Full Code Here

        Queue<String> nextWords = new ArrayDeque<String>();
        for (int i = focusIndex+1;
                 i < Math.min(focusIndex+windowSize+1, tree.length); ++i)
            nextWords.add(getFeature(tree[i], i-focusIndex));

        SparseDoubleVector focusMeaning = new CompactSparseVector();
        addContextTerms(focusMeaning, prevWords, -1 * prevWords.size());
        addContextTerms(focusMeaning, nextWords, 1);
        return focusMeaning;
    }
View Full Code Here

                int cols = minValues.length;

                // If the average number of values per row is significantly
                // smaller than the total number of columns then select a subset
                // to be non zero.
                SparseDoubleVector column = new CompactSparseVector(cols);
                int numNonZeros =
                    (int) (random.nextGaussian() * stdevNumValuesPerRow +
                           averageNumValuesPerRow);
                if (numNonZeros == 0)
                    numNonZeros++;

                for (int j = 0; j < numNonZeros; ++j) {
                    // Get the next index to set.
                    int col = getNonZeroColumn();
                    double value = random.nextDouble() *
                            (maxValues[col] - minValues[col]) + minValues[col];
                    column.set(col, value);
                }
                vectors.add(column);
            }
            //builder.finish();

View Full Code Here

     */
    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

        // 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())
View Full Code Here

    /**
     * {@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

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.