Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.CompactSparseVector


            if (tokens.length < 10)
                return;

            // Compute the vector length and create the context vector.
            vectorLength = (tokens.length - 1) / 2;
            SparseDoubleVector vector = new CompactSparseVector(
                  (tokens.length - 1) / 2);

            // Read each feature index and value.
            for (int i = 1; i < tokens.length; i+=2) {
                int index = Integer.parseInt(tokens[i]);
                double value = Double.parseDouble(tokens[i+1]);
                vector.set(index, value);
            }

            wordsi.handleContextVector(termSplit[0], tokens[0], vector);
        } catch (IOException ioe) {
            throw new IOError(ioe);
View Full Code Here


       
        // Reject any words not accepted by wordsi.
        if (!wordsi.acceptWord(headerRest[0]))
            return;

        SparseDoubleVector context = new CompactSparseVector();

        // Iterate through each feature and convert it to a dimension for the
        // context vector.
        for (String item : headerRest[1].split("\\|")) {
            String[] featureScore = item.split(",", 2);
            double score = Double.parseDouble(featureScore[0]);
            int dimension = basis.getDimension(featureScore[1]);
            if (dimension >= 0)
                context.set(dimension, score);
        }
        wordsi.handleContextVector(headerRest[0], headerRest[0], context);
    }
View Full Code Here

         */
        public CandidateCommittee(Set<Integer> rows,
                                  SparseMatrix sm) {
            this.rows = rows;
            // Compute the centroid
            centroid = new CompactSparseVector(sm.columns());
            double simSum = 0d;
            for (int r : rows) {
                SparseDoubleVector row = sm.getRowVector(r);
                VectorMath.add(centroid, row);

View Full Code Here

            centroids[c] = new DenseDynamicMagnitudeVector(
                    centroids[c].toArray());

        subSetup(m);

        SparseDoubleVector empty = new CompactSparseVector(m.columns());
        for (int c = 0; c < numClusters; ++c)
            if (clusterSizes[c] != 0)
                costs[c] = getOldCentroidScore(empty, c, clusterSizes[c]);
    }
View Full Code Here

            // appeared on one side of a context (its row or column vector would
            // never have been set).  Therefore, check the index with the matrix
            // size first.
            SparseDoubleVector rowVec = (index < cooccurrenceMatrix.rows())
                ? cooccurrenceMatrix.getRowVectorUnsafe(index)
                : new CompactSparseVector(termToIndex.numDimensions());
            SparseDoubleVector colVec = (index < cooccurrenceMatrix.columns())
                ? cooccurrenceMatrix.getColumnVectorUnsafe(index)
                : new CompactSparseVector(termToIndex.numDimensions());

            return new ConcatenatedSparseDoubleVector(rowVec, colVec);
        }

        // The co-occurrence matrix has had columns dropped so the vector is
View Full Code Here

        // 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);
            return;
        }

        Assignments clusterAssignment =
            new ClutoClustering().cluster(contexts, numClusters,
                                          ClutoClustering.Method.AGGLOMERATIVE,
                                          ClutoClustering.Criterion.UPGMA);
       
        LOGGER.fine("Generative sense vectors for " + term);
       
        // For each of the clusters, compute the mean sense vector
        int[] clusterSize = new int[numClusters];

        // Use CompactSparseVector to conserve memory given the potentially
        // large number of sense vectors
        SparseDoubleVector[] meanSenseVectors =
            new CompactSparseVector[numClusters];

        for (int i = 0; i < meanSenseVectors.length; ++i)
            meanSenseVectors[i] = new CompactSparseVector(termToIndex.size());

        // For each of the contexts, determine which cluster it was in and sum
        // it value with the other contexts
        for (int row = 0; row < clusterAssignment.size(); ++row) {
            // Check whether this row was assigned a cluster
View Full Code Here

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

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

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

                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

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.