Examples of SparseDoubleVector


Examples of edu.ucla.sspace.vector.SparseDoubleVector

     * then throw away all but one of them.
     */
    protected static double subtractedMagnitudeSqrd(DoubleVector c,
                                                   DoubleVector v) {
        if (v instanceof SparseDoubleVector) {
            SparseDoubleVector sv = (SparseDoubleVector) v;
            int[] nonZeros = sv.getNonZeroIndices();

            double magnitude = Math.pow(c.magnitude(), 2);
            for (int i : nonZeros) {
                double value = c.get(i);
                magnitude -= Math.pow(value, 2);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            if (it.hasNext())
                nextWords.offer(it.next());

            // Represent the word if wordsi is willing to process it.
            if (wordsi.acceptWord(focus)) {
                SparseDoubleVector contextVector = generator.generateContext(
                        prevWords, nextWords);
                wordsi.handleContextVector(focus, secondaryKey, contextVector);
            }

            // Advance the sliding window to the right.
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        // Cluster each of the rows into seven groups.  Note that if the term is
        // not purely alphabetic (i.e. contains number of other symbols), don't
        // bother clustering it.  This is done to reduce the computation time,
        // and to avoid clustering non-meaningful terms such as '.' or '''
        if (!(term.matches("[a-zA-z]+") && numClusters > 6)) { // special case           
            SparseDoubleVector meanSenseVector =
                new CompactSparseVector(termToIndex.size());           
            int rows = contexts.rows();
            for (int row = 0; row < rows; ++row)
                VectorMath.add(meanSenseVector, contexts.getRowVector(row));
            termToVector.put(term, meanSenseVector);
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();
        addContextTerms(meaning, prevWords, -1 * prevWords.size());
        addContextTerms(meaning, nextWords, 1);
        return meaning;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        // Get each function used in this hybrid method.
        i1Func = getInternalFunction();
        e1Func = getExternalFunction();

        SparseDoubleVector empty = new CompactSparseVector(m.columns());
        // Compute the cost of each centroid.
        for (int c = 0; c < numClusters; ++c) {
            if (clusterSizes[c] != 0) {
                // Compute the internal costs.
                i1Costs[c] = i1Func.getOldCentroidScore(
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

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

        SparseDoubleVector focusMeaning = new CompactSparseVector();
        // Get all the valid paths starting from this word.
        Iterator<DependencyPath> paths = new FilteredDependencyIterator(
                focusNode, acceptor, pathLength);
           
        // For each of the paths rooted at the focus word, update the
        // co-occurrences of the focus word in the dimension that the
        // BasisFunction states with the weight generated by the
        // DependencyPathWeight function.
        while (paths.hasNext()) {
            DependencyPath path = paths.next();

            // Get the dimension from the basis mapping, ignore any features
            // that are not mapped.
            int dimension = basisMapping.getDimension(path);
                if (dimension < 0)
                    continue;

            double weight = weighter.scorePath(path);
            focusMeaning.add(dimension, weight);                                       
        }
        return focusMeaning;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            PrintWriter affMatrixWriter = new PrintWriter(affMatrixFile);

            // Keep track of the first row and have a reference to the next row.
            // The nextRow reference avoid us having to advance into data
            // unnecessarily to retrieval the vector for processing to start
            SparseDoubleVector curRow = null;
            SparseDoubleVector nextRow = null;

            SvdlibcSparseBinaryFileRowIterator matrixIter =
                new SvdlibcSparseBinaryFileRowIterator(converted);
           
            for (int row = 0; row < rows; ++row) {
                LOG.fine("computing affinity for row " + row);

                // The map is to the row and its weighted affinity value.  We
                // need to store the potential value at the time of the
                // similarity calculation because that is the only time the two
                // row vectors are in memory
                MultiMap<Double,Duple<Integer,Double>> neighbors =
                    new BoundedSortedMultiMap<Double,Duple<Integer,Double>>(
                        numNearestNeighbors, false);

                // Loop through each of the rows, gathering the statistics
                // necessary to compute the affinity matrix.
                for (int other = 0; other < rows; ++other) {
                    //System.out.printf("cur: %d, other %d%n", row, other);
                    // Special case for the very first row
                    if (row == 0 && curRow == null) {
                        curRow = matrixIter.next();
                        continue;
                    }
                   
                    SparseDoubleVector otherRow = matrixIter.next();

                    // Save the row that will be used next so we have it to do
                    // comparisons with for earlier rows in the file
                    if (other == row + 1)
                        nextRow = otherRow;
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

                double[] vals = new double[nzInCol];
                for (int i = 0; i < nzInCol; ++i, ++entriesSeen) {
                    indices[i] = dis.readInt();
                    vals[i] = dis.readFloat();
                }
                SparseDoubleVector rowVec =
                    new CompactSparseVector(indices, vals, rows);
                rowArr[curRow] = rowVec;
                ++curRow;               
            }
            m = Matrices.asSparseMatrix(Arrays.asList(rowArr));
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

                    if (!relation.headNode().word().equals(focusWord))
                        continue;

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

Examples of edu.ucla.sspace.vector.SparseDoubleVector

    /**
     * {@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);
            String rel = relation.relation;

            SelectionalPreference headPref = preferenceVectors.get(headWord);

            if (headPref == null)
                LOG.fine("what the fuck");

            for (int index : relationCounts.getNonZeroIndices()) {
                double frequency = relationCounts.get(index);
                String depWord = termBasis.getDimensionDescription(index);
                SelectionalPreference depPref = preferenceVectors.get(depWord);

                // It's possible that the dependent word is not being
                // represented in this space, so skip missing terms.
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.