Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.ScaledDoubleVector


  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++)
View Full Code Here


          
    /**
     * {@inheritDoc}
     */
    public DoubleVector getRowVector(int row) {
        return new ScaledDoubleVector(m.getRowVector(row), scales.get(row));
    }
View Full Code Here

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

        // Compute the optimal cost of the single cluster case.
        double optimalSingleCost = 0;
        double[] distances = new double[numDataPoints];
View Full Code Here

        } else {
            List<DoubleVector> scaledVectors =
                new ArrayList<DoubleVector>(matrix.rows());
            for (int r = 0; r < matrix.rows(); ++r) {
                DoubleVector v = matrix.getRowVector(r);
                scaledVectors.add(new ScaledDoubleVector(v, 1/v.magnitude()));
            }
            return Matrices.asMatrix(scaledVectors);
        }
    }
View Full Code Here

        }

        // Scale any non empty clusters by their size.
        for (int c = 0; c < numClusters; ++c)
            if (counts[c] != 0)
                centroids[c] = new ScaledDoubleVector(
                        centroids[c],1d/counts[c]);

        return centroids;
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public double getKMeansObjective() {
        // Note that the scaled vector handles any recursive scaling.
        DoubleVector centroid = new ScaledDoubleVector(
                matrixRowSums, 1/((double) dataMatrix.rows()));
        double score = 0;
        for (int r = 0; r < dataMatrix.rows(); ++r)
            score += VectorMath.dotProduct(
                    centroid, dataMatrix.getRowVector(r));
View Full Code Here

        // Scale non empty centroids.  Note that the scaled vector handles any
        // recursive scaling.
        for (int i = 0; i < centroids.length; ++i)
            if (sizes[i] != 0)
                centroids[i] = new ScaledDoubleVector(centroids[i],1d/sizes[i]);

        // Compute the total distance of each asisgned point to it's centroid.
        for (int i = 0; i < assignments.length; ++i)
            score += VectorMath.dotProduct(
                    centroids[assignments[i]], data.getRowVector(i));
View Full Code Here

        dot = VectorMath.dotProduct(v, v);
        if (1/dot == 0d || dot == 0)
            return v;

        // Note that the scaled vector handles any recursive scaling.
        return new ScaledDoubleVector(v, 1/dot);
    }
View Full Code Here

TOP

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

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.