Vectors.subview(e.getValue(), 0, getVectorLength()))); Matrix m = Matrices.asMatrix(vectorsInOrder);
/** * Returns a scaled {@link Matrix}, where each row is the unit * magnitude version of the corresponding row vector in {@link matrix}. * This is required so that dot product computations over a large number of * data points can be distributed, wherease the cosine similarity cannot be. */ private Matrix scaleMatrix(Matrix matrix) { // Scale every data point such that it has a dot product of 1 with // itself. This will make further calculations easier since the dot // product distrubutes when the cosine similarity does not. if (matrix instanceof SparseMatrix) { List<SparseDoubleVector> scaledVectors = new ArrayList<SparseDoubleVector>(matrix.rows()); SparseMatrix sm = (SparseMatrix) matrix; for (int r = 0; r < matrix.rows(); ++r) { SparseDoubleVector v = sm.getRowVector(r); scaledVectors.add(new ScaledSparseDoubleVector( v, 1/v.magnitude())); } return Matrices.asSparseMatrix(scaledVectors); } 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); } }
/** * Returns a scaled {@link Matrix}, where each row is the unit * magnitude version of the corresponding row vector in {@link matrix}. * This is required so that dot product computations over a large number of * data points can be distributed, wherease the cosine similarity cannot be. */ private Matrix scaleMatrix(Matrix matrix) { // Scale every data point such that it has a dot product of 1 with // itself. This will make further calculations easier since the dot // product distrubutes when the cosine similarity does not. if (matrix instanceof SparseMatrix) { List<SparseDoubleVector> scaledVectors = new ArrayList<SparseDoubleVector>(matrix.rows()); SparseMatrix sm = (SparseMatrix) matrix; for (int r = 0; r < matrix.rows(); ++r) { SparseDoubleVector v = sm.getRowVector(r); scaledVectors.add(new ScaledSparseDoubleVector( v, 1/v.magnitude())); } return Matrices.asSparseMatrix(scaledVectors); } 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); } }
Matrix clusterToSplit = Matrices.asMatrix(originalCluster); Assignments newAssignments = clustering.cluster(dataPoints, 2, props);
Matrix clusterToSplit = Matrices.asMatrix(originalCluster); Assignment[] newAssignments = clustering.cluster(clusterToSplit, 2, props).assignments();
/** * {@inheritDoc} */ public Assignments cluster(Matrix matrix, Properties props) { OnlineClustering<DoubleVector> results = computeStreamingCluster( matrix); int[] assignments = HierarchicalAgglomerativeClustering.clusterRows( Matrices.asMatrix(collectCentroids(results)), .15, ClusterLinkage.MEAN_LINKAGE, SimType.COSINE); List<Cluster<DoubleVector>> newClusters = mergeClusters( assignments, results.getClusters()); return computeAssignments(newClusters, matrix.rows()); }
/** * {@inheritDoc} */ public Assignments cluster(Matrix matrix, int numClusters, Properties props) { OnlineClustering<DoubleVector> results = computeStreamingCluster( matrix); int[] assignments = HierarchicalAgglomerativeClustering.partitionRows( Matrices.asMatrix(collectCentroids(results)), numClusters, ClusterLinkage.MEAN_LINKAGE, SimType.COSINE); List<Cluster<DoubleVector>> newClusters = mergeClusters( assignments, results.getClusters()); return computeAssignments(newClusters, matrix.rows()); }
: clustering.cluster(matrix, props); } else { Matrix matrix = Matrices.asMatrix(vectors); assignments = (numClusters > 0) ? clustering.cluster(matrix, numClusters, props)
: clustering.cluster(matrix, props); } else { Matrix matrix = Matrices.asMatrix(vectors); assignments = (numClusters > 0) ? clustering.cluster(matrix, numClusters, props)
Matrix m = Matrices.asMatrix(facilityCentroids);
Matrix m = Matrices.asMatrix(facilityCentroids);