Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.Vector


     */
    public SortedMultiMap<Double,String> getMostSimilar(
            final String word, final SemanticSpace sspace,
            int numberOfSimilarWords, Similarity.SimType similarityType) {

        Vector v = sspace.getVector(word);

        // if the semantic space did not have the word, then return null
        if (v == null) {
            return null;
        }
       
        final Vector vector = v;

        Set<String> words = sspace.getWords();
       
        // the most-similar set will automatically retain only a fixed number
        // of elements
View Full Code Here


            this.mostSimilar = mostSimilar;
        }

        public void run() {
            try {           
                Vector otherV = sspace.getVector(other);

                Double similarity = Similarity.getSimilarity(
                    similarityMeasure, vector, otherV);
               
                // lock on the Map, as it is not thread-safe
View Full Code Here

     * @return the assocation or {@code null} if either {@code word1} or {@code
     *         word2} are not in the semantic space
     */
    protected Double computeAssociation(SemanticSpace sspace,
                                        String word1, String word2) {
        Vector v1 = sspace.getVector(word1);
        Vector v2 = sspace.getVector(word2);
        if (v1 == null || v2 == null)
            return null;
       
        // Find the ranks of each of the two words to each other
        double rank1 = findRank(sspace, word1, word2);
View Full Code Here

     * Returns the ranking <i>k</i> such that {@code other} is the k<sup>th</th>
     * most similar word to {@code target} in the semantic space.
     */
    private int findRank(SemanticSpace sspace,
                         String target, String other) {
        Vector v1 = sspace.getVector(target);
        Vector v2 = sspace.getVector(other);
        // Compute the base similarity between the two words
        double baseSim = Similarity.cosineSimilarity(v1, v2);
        int rank = 0;
        // Next, count how many words are more similar to the target than the
        // other word is
        for (String word : sspace.getWords()) {
            Vector v = sspace.getVector(word);
            double sim = Similarity.cosineSimilarity(v1, v);
            if (sim > baseSim)
                rank++;
        }
        return rank;
View Full Code Here

        for (String word : interestingWords) {
            // update the vectors
            SortedMap<Long,double[]> temporalSemantics =
                wordToTemporalSemantics.get(word);
            Vector v = semanticPartition.getVector(word);
            // If the wor was not present in the current partition, then just
            // use the zero vector.  Otherwise, use it distirbution.
            double[] semantics = (v == null)
                ? zeroVector
                : Vectors.asDouble(v).toArray();
View Full Code Here

        // Space
        for (MultipleChoiceQuestion question : questions) {
            String promptWord = question.getPrompt();

            // get the vector for the prompt
            Vector promptVector = sspace.getVector(promptWord);

            // check that the s-space had the prompt word
            if (promptVector == null) {
                unanswerable++;
                continue;
            }

            int answerIndex = 0;
            double closestOption = Double.MIN_VALUE;

            // find the options whose vector has the highest similarity (or
            // equivalent comparison measure) to the prompt word.  The
            // running assumption hear is that for the value returned by the
            // comparison method, a high value implies more similar vectors.
            int optionIndex = 0;
            for (String optionWord : question.getOptions()) {
               
                // Get the vector for the option
                Vector optionVector = sspace.getVector(optionWord);
       
                // check that the s-space had the option word
                if (optionVector == null) {
                    unanswerable++;
                    continue question_loop;
View Full Code Here

            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(String.format("serializing text %d/%d: %s",
                              wordCount++, size, word));
            }
            for (long timestep : sspace.getTimeSteps(word)) {
                Vector timeSlice =
                    sspace.getVectorBetween(word, timestep, timestep + 1);
                if (timeSlice != null) {
                    pw.print(timestep + " " +
                             VectorIO.toString(timeSlice) + "|");
                }
View Full Code Here

            }

            SortedSet<Long> timeSteps = sspace.getTimeSteps(word);

            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++;
                        }
                    }
                   
                    pw.print(timestep + " " + nonZero + "%");
                    StringBuilder sb = new StringBuilder(nonZero * 4);
                    for (int i = 0; i < timeSlice.length(); ++i) {
                        double d = timeSlice.getValue(i).doubleValue();
                        if (d != 0d) {
                            sb.append(i).append(",").append(d);
                        }
                        if (i + 1 < timeSlice.length()) {
                            sb.append(",");
                        }
                    }
                    pw.print(sb.toString() + "|");
                }
View Full Code Here

                LOGGER.info(String.format("serializing binary %d/%d: %s",
                              wordCount++, size, word));
            }

            for (long timestep : sspace.getTimeSteps(word)) {
                Vector timeSlice =
                    sspace.getVectorBetween(word, timestep, timestep + 1);
                if (timeSlice != null) {
                    dos.writeLong(timestep);
                    for (int i = 0; i < timeSlice.length(); ++i) {
                        dos.writeDouble(timeSlice.getValue(i).doubleValue());
                    }
                }
            }
        }
        dos.close();
View Full Code Here

        // Compute the word pair similarity using the given Semantic Space for
        // each word.
        for (WordSimilarity pair : wordPairs) {
            // get the vector for each word
            Vector firstVector = sspace.getVector(pair.getFirstWord());
            Vector secondVector = sspace.getVector(pair.getSecondWord());

            // check that the s-space had both words
            if (firstVector == null || secondVector == null) {
                unanswerable++;
                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.