Examples of DenseVector


Examples of edu.ucla.sspace.vector.DenseVector

   
    private static IntPair pickFirstTwo(Matrix dataPoints,
                                        SimilarityFunction simFunc,
                                        int[] weights, double[] inverseSimilarities) {
  double OPT_1 = 0; // optimal 1-means cost.
  DoubleVector centerOfMass = new DenseVector(dataPoints.columns());
  double sum = 0d;
  int rows = dataPoints.rows();
        int cols = dataPoints.columns();
        double[] probs = new double[rows];
  int totalWeight = 0;

  for (int i = 0; i < rows; i++) {
            DoubleVector v = dataPoints.getRowVector(i);
            int weight = weights[i];
            // Update the center of mass for the entire solution based
            VectorMath.add(centerOfMass, new ScaledDoubleVector(v, weight));
            totalWeight += weight;
        }
        
        // Then rescale the center of mass based on the total weight
        for (int j = 0; j < cols; j++)
            centerOfMass.set(j, centerOfMass.get(j) / totalWeight);
       
       
        for (int i = 0; i < rows; i++) {
            double sim = simFunc.sim(centerOfMass, dataPoints.getRowVector(i));
            sim = invertSim(sim);
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        clusterSizes = new int[numClusters];
        costs = new double[numClusters];

        // Initialize the clusters.
        for (int c = 0; c < numClusters; ++c)
            centroids[c] = new DenseVector(m.columns());

        // Form the cluster composite vectors, i.e. unscaled centroids.
        for (int i = 0; i < m.rows(); ++i) {
            int assignment = initialAssignments[i];
            VectorMath.add(centroids[assignment], matrix.get(i));
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

            // For any extra slots that do not have a data point, use an empty
            // vector, which will have zero similarity with any other data
            // point.
            for (int i = dataPoints.rows(); i < numCentroids; ++i)
                centers[i] = new DenseVector(dataPoints.columns());

            return centers;
        }

        // Select a subset of data points to be the new centroids.
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        DoubleVector[] centroids = new DoubleVector[numCentroids];

        // Compute the centroid assuming that there is only one cluster to be
        // found.  This is required for computing the optimal cost of a single
        // cluster solution.
        DoubleVector singleCentroid = new DenseVector(dataPoints.columns());
        for (int i = 0; i < numDataPoints; ++i)
            VectorMath.add(singleCentroid, dataPoints.getRowVector(i));
        singleCentroid = new ScaledDoubleVector(
                singleCentroid, 1/((double)numDataPoints));
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        /**
         * {@inheritDoc}
         */
        protected DoubleVector computeSecondEigenVector(Matrix matrix,
                                                        int vectorLength) {
            DoubleVector Rinv = new DenseVector(vectorLength);
            DoubleVector baseVector = new DenseVector(vectorLength);
            for (int i = 0; i < vectorLength; ++i) {
                Rinv.set(i, 1/Math.sqrt(rho.get(i)));
                baseVector.set(i, rho.get(i) * Rinv.get(i));
            }
    
            // Step 1, generate a random vector, v,  that is orthogonal to
            // pi*D-Inverse.
            DoubleVector v = new DenseVector(vectorLength);
            for (int i = 0; i < v.length(); ++i)
                v.set(i, Math.random());

            Matrix RinvData = (matrix instanceof SparseMatrix)
                ? new RowScaledSparseMatrix((SparseMatrix) matrix, Rinv)
                : new RowScaledMatrix(matrix, Rinv);

View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

                    SparseVector sv = (SparseVector)sumVector;
                    for (int nz : sv.getNonZeroIndices())
                        centroid.set(nz, sumVector.get(nz) * d);
                }
                else {
                    centroid = new DenseVector(length);
                    for (int i = 0; i < length; ++i)
                        centroid.set(i, sumVector.get(i) * d);                   
                }
            }
        }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

        boolean added = indices.add(index);
        assert added : "Adding duplicate indices to candidate facility";
        if (sumVector == null) {
            sumVector = (v instanceof SparseVector)
                ? new SparseHashDoubleVector(v)
                : new DenseVector(v);
        }
        else {
            VectorMath.add(sumVector, v);
            centroid = null;
        }          
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

    /**
     * {@inheritDoc}
     */
    public DoubleVector getColumnVector(int column) {
        return new DenseVector(getColumn(column));
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DenseVector

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

Examples of edu.ucla.sspace.vector.DenseVector

                               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;
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.