Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.Vector


            // write out the number of time steps seen for this word
            dos.writeInt(timeSteps.size());

            for (long timestep : timeSteps) {
                Vector timeSlice =
                    sspace.getVectorBetween(word, timestep, timestep + 1);
                if (timeSlice != null) {
                    // count the non-zero
                    int nonZero = 0;
                    for (int i = 0; i < timeSlice.length(); ++i) {
                        if (timeSlice.getValue(i).doubleValue()  != 0d) {
                            nonZero++;
                        }
                    }

                    dos.writeLong(timestep);
                    dos.writeInt(nonZero);
                    for (int i = 0; i < timeSlice.length(); ++i) {
                        double d = timeSlice.getValue(i).doubleValue();
                        if (d != 0d) {
                            dos.writeInt(i);
                            dos.writeDouble(d);
                        }
                    }
View Full Code Here


            double bestSim = 0;
            while (true) {
                String query = (i == 0) ? focus : focus + "-" + i;
                i++;

                Vector v = wordsiSpace.getVector(query);
                if (v == null)
                    return bestSense;

                double sim = Similarity.cosineSimilarity(v, vector);
                if (sim >= bestSim) {
View Full Code Here

     * {@inheritDoc}
     */
    public SortedMultiMap<Double,String> getMostSimilar(
            String word, int numberOfSimilarWords) {

        Vector v = sspace.getVector(word);
        // if the semantic space did not have the word, then return null
        if (v == null)
            return null;
        // Find the most similar words vectors to this word's vector, which will
        // end up including the word itself.  Therefore, increase the count by
View Full Code Here

            return null;
        // Compute the mean vector for all the terms
        DoubleVector mean = new DenseVector(sspace.getVectorLength());
        int found = 0;
        for (String term : terms) {
            Vector v = sspace.getVector(term);
            if (v == null)
                info(LOGGER, "No vector for term " + term);
            else {
                VectorMath.add(mean, v);
                found++;
View Full Code Here

                        // Record the similarity in a local data structure so we
                        // avoid locking the global mostSimilar term map
                        SortedMultiMap<Double,String> localMostSimTerms =
                            new BoundedSortedMultiMap<Double,String>(k, false);
                        for (String term : terms) {
                            Vector tVec = sspace.getVector(term);
                            double sim = simFunc.sim(v, tVec);
                            localMostSimTerms.put(sim, term);
                        }
                        // Lock the global map and then add the local results
                        synchronized (kMostSimTerms) {
View Full Code Here

        }

        // Iterate through each term in the document and sum the term Vectors
        // found in the provided SemanticSpace.
        for (Map.Entry<String, Integer> entry : termCounts.entrySet()) {
            Vector termVector = sspace.getVector(entry.getKey());
            if (termVector == null)
                continue;
            add(documentVector, termVector, entry.getValue());
        }
View Full Code Here

     *
     * @throws IOError if any {@code IOException} occurs when reading the data
     *         from the underlying semantic space file.
     */
    public synchronized Vector getVector(String word) {
        Vector vector = wordToVector.get(word);
        if (vector != null)
            return Vectors.immutable(vector);

        Vector v = backingSpace.getVector(word);
        if (v != null)
            wordToVector.put(word, v);
        return v;
    }
View Full Code Here

     */
    public Vector permute(Vector v , int numPermutations) {
        if (v instanceof TernaryVector)
            return permute((TernaryVector) v, numPermutations, v.length());

        Vector result = Vectors.instanceOf(v);
        int[] dimensions = null;
        int[] oldDims = null;
        if (v instanceof SparseVector) {
            oldDims = ((SparseVector) v).getNonZeroIndices();
            dimensions = Arrays.copyOf(oldDims, oldDims.length);
        } else {
            dimensions = new int[v.length()];
            for (int i = 0; i < v.length(); ++i)
                dimensions[i] = i;
        }

        System.out.printf("input: %s%ninitial result: %s%n", v, result);

        boolean isInverse = numPermutations < 0;
       
        // NB: because we use the signum and !=, this loop will work for both
        // positive and negative numbers of permutations
        int totalPermutations = Math.abs(numPermutations);

        // Loop through the number of permutation that we have to do and keep
        // updating which indices are being assigned to which
        for (int count = 1; count <= totalPermutations; ++count) {           
            // load the reordering funcion for this iteration of the permutation
            Function function = getFunction(count, v.length());

            // based on whether this is an inverse permutation, select whether
            // to use the forward or backwards mapping.
            int[] reordering = (isInverse)
                ? function.backward : function.forward;

            oldDims = Arrays.copyOf(dimensions, dimensions.length);
           
            for (int i = 0; i < oldDims.length; ++i) {
                dimensions[i] = reordering[oldDims[i]];
            }
        }

        for (int d : dimensions)
            result.set(dimensions[d], v.getValue(d));

        System.out.printf("input: %s%nfinal permuted result: %s%n", v, result);
        return result;
    }
View Full Code Here

        int bestSense = 0;
        double bestSimilarity = -1;

        while (true) {
            // Create the word sense key based on the sense number.
            Vector wordSense = getVector((senseNumber == 0)
                    ? focusKey
                    : focusKey + "-" + senseNumber);

            // If no word sense exists then we have examined all known word senses.
            if (wordSense == null)
View Full Code Here

        final SortedMultiMap<Double,Integer> mostSimilar =
            new BoundedSortedMultiMap<Double,Integer>(kNearestRows, false);

        // loop through all the other words computing their similarity
        int rows = m.rows();
        Vector v = m.getRowVector(row);
        for (int i = 0; i < rows; ++i) {
            // skip same row
            if (i == row)
                continue;
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.vector.Vector

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.