Examples of DoubleVector


Examples of edu.ucla.sspace.vector.DoubleVector

            if (clusterAssignment.get(row).assignments().length == 0)
                continue;               
            int assignment = clusterAssignment.get(row).assignments()[0];               
            clusterSize[assignment]++;

            DoubleVector contextVector = contexts.getRowVector(row);
            VectorMath.add(meanSenseVectors[assignment], contextVector);
        }
       
        // For each of the clusters with more than 2% of the contexts, generage
        // an average sense vectors.  For those clusters with less than that
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

        // Setup the best cost and index for the best cost.
        double bestTotal = totalCost;
        int bestDeltaIndex = -1;

        // Get the current vector.
        DoubleVector vector = matrix.get(currentVectorIndex);

        // Get the base cost for removing the data point from the current
        // cluster.
        double baseE1Delta = 0;
        double baseI1Delta = 0;
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

            for (int i = 0; i < rows; ++i) {
                LOG.fine("computing affinity for row " + i);
                MultiMap<Double,Integer> neighborMap = rc.getMostSimilar(
                        input, i, numNearestNeighbors, edgeSim);

                DoubleVector row = input.getRowVector(i);
                for (int n : neighborMap.values()) {
                    double edgeWeight = kernelSim.sim(
                            row, input.getRowVector(n));
                    affMatrixWriter.printf("%d %d %f\n", i+1 ,n+1, edgeWeight);
                }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

    /**
     * {@inheritDoc}
     */
    public synchronized int addColumn(Vector col) {
        DoubleVector column = Vectors.asDouble(col);
        if (isFinished)
            throw new IllegalStateException(
                "Cannot add columns to a MatrixBuilder that is finished");
        if (column instanceof SparseVector) {
            SparseVector s = (SparseVector)column;
            for (int r : s.getNonZeroIndices()) {
                // NB: Matlab sparse format is in [row col val] format
                //
                // NOTE: Matlab indices start at 1, not 0, so update all the
                // column and column values to be Matlab formatted.
                addEntry(r + 1, curColumn + 1, column.get(r));
            }
        }
        else {
            for (int r = 0; r < column.length(); ++r) {
                double d = column.get(r);
                if (d != 0d) {
                    // NOTE: Matlab indices start at 1, not 0, so update all
                    // the row and column values to be Matlab formatted.
                    addEntry(r + 1, curColumn + 1, d);
                }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

            if (!focusWord.equals(IteratorFactory.EMPTY_TOKEN)) {
                // Incorporate the context into the semantic vector for the
                // focus word.  If the focus word has no semantic vector yet,
                // create a new one, as determined by the index builder.
                DoubleVector meaning = termHolographs.get(focusWord);
                if (meaning == null) {
                    meaning = new DenseVector(indexVectorSize);
                    documentVectors.put(focusWord, meaning);
                }
                updateMeaning(meaning, prevWords, nextWords);
            }

            prevWords.offer(focusWord);
            if (prevWords.size() > 1)
                prevWords.remove();
        }

        // Add the local cached semantics to the global term semantics.
        for (Map.Entry<String, DoubleVector> entry :
                documentVectors.entrySet()) {
            synchronized (entry.getKey()) {
                // Get the global semantic representation of each word.  If it
                // does not currently exist, then just put the local copies
                // representation, otherwise add the local copy to the global
                // version.
                DoubleVector existingVector =
                    termHolographs.get(entry.getKey());
                if (existingVector == null)
                    termHolographs.put(entry.getKey(), entry.getValue());
                else
                    VectorMath.add(existingVector, entry.getValue());
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

                               Queue<String> nextWords) {
        // Generate the semantics of the context using summation of index
        // vectors.
        if (semanticType == SemanticType.COMPOSITE ||
            semanticType == SemanticType.CONTEXT) {
            DoubleVector context = new DenseVector(indexVectorSize);

            // Sum the words prior to the focus word, skipping filtered tokens.
            for (String term: prevWords) {
                if (term.equals(IteratorFactory.EMPTY_TOKEN))
                    continue;
                VectorMath.add(context, vectorMap.get(term));
            }

            // Sum the words after the focus word, skipping filtered tokens.
            for (String term: nextWords) {
                if (term.equals(IteratorFactory.EMPTY_TOKEN))
                    continue;
                VectorMath.add(context, vectorMap.get(term));
            }

            // Normalize the context vector and add it to the meaning.
            normalize(context);
            VectorMath.add(meaning, context);
        }

        // Generate the semantics of the ordering using circular convolution of
        // n-grams.
        if (semanticType == SemanticType.COMPOSITE ||
            semanticType == SemanticType.ORDERING) {
            DoubleVector order = groupConvolution(prevWords, nextWords);

            // Normalize the order vector and add it to the meaning.
            normalize(order);
            VectorMath.add(meaning, order);
        }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

     * @return The semantic vector generated from the circular convolution.
     */
    private DoubleVector groupConvolution(Queue<String> prevWords,
                                          Queue<String> nextWords) {
        // Generate an empty DoubleVector to hold the convolution.
        DoubleVector result = new DenseVector(indexVectorSize);

        // Do the convolutions starting at index 0.
        String prevWord = prevWords.peek();
        DoubleVector tempConvolution;
        if (!prevWord.equals(IteratorFactory.EMPTY_TOKEN)) {
            tempConvolution =
                convolute(vectorMap.get(prevWords.peek()), placeHolder);
            VectorMath.add(result, tempConvolution);
        } else
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

        // Use the Fast Fourier Transform on each vector.
        FastFourierTransform.transform(left);
        FastFourierTransform.transform(right);

        // Multiply the two together.
        DoubleVector result = VectorMath.multiply(left, right);

        // The inverse transform completes the convolution.
        FastFourierTransform.backtransform(result);
        return result;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

     * @param orderVector The ordering of values to be used.
     *
     * @return The shuffled version of {@code data}.
     */
    private DoubleVector changeVector(DoubleVector data, int[] orderVector) {
        DoubleVector result = new DenseVector(indexVectorSize);
        for (int i = 0; i < indexVectorSize; i++)
            result.set(i, data.get(orderVector[i]));
        return result;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

            PrintWriter pw = new PrintWriter(output);
            // Count the number of non-zero values in the matrix
            int nonZero = 0;
            int rows = matrix.rows();
            for (int i = 0; i < rows; ++i) {
                DoubleVector v = matrix.getRowVector(i);
                if (v instanceof SparseVector)
                    nonZero += ((SparseVector)v).getNonZeroIndices().length;
                else {
                    for (int col = 0; col < v.length(); ++col) {
                        if (v.get(col) != 0)
                            nonZero++;
                    }
                }
            }
            // Write the header: rows cols non-zero
            pw.println(matrix.rows() + " " + matrix.columns() + " " + nonZero);
            for (int row = 0; row < rows; ++row) {
                StringBuilder sb = new StringBuilder(nonZero / rows);
                // NOTE: the columns in CLUTO start at 1, not 0, so increment
                // one to each of the columns
                DoubleVector v = matrix.getRowVector(row);
                if (v instanceof SparseVector) {
                    int[] nzIndices = ((SparseVector)v).getNonZeroIndices();
                    for (int nz : nzIndices) {
                        sb.append(nz + 1).append(" ").
                            append(v.get(nz)).append(" ");
                    }
                }
                else {
                    for (int col = 0; col < v.length(); ++col) {
                        double d = v.get(col);
                        if (d != 0)
                            sb.append(col+1).append(" ").append(d).append(" ");
                    }
                }
                pw.println(sb.toString());
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.