return Matrices.asSparseMatrix(Arrays.asList(rowVectors));
return Matrices.asSparseMatrix(Arrays.asList(rowVectors));
if (numClusters != 0) { assignments = HierarchicalAgglomerativeClustering.partitionRows( Matrices.asSparseMatrix(centroids), numClusters, ClusterLinkage.MEAN_LINKAGE, } else { assignments = HierarchicalAgglomerativeClustering.clusterRows( Matrices.asSparseMatrix(centroids), threshold, ClusterLinkage.MEAN_LINKAGE,
if (numClusters != 0) { assignments = HierarchicalAgglomerativeClustering.partitionRows( Matrices.asSparseMatrix(centroids), numClusters, ClusterLinkage.MEAN_LINKAGE, } else { assignments = HierarchicalAgglomerativeClustering.clusterRows( Matrices.asSparseMatrix(centroids), threshold, ClusterLinkage.MEAN_LINKAGE,
++curRow; m = Matrices.asSparseMatrix(Arrays.asList(rowArr));
Matrices.asSparseMatrix(v), AVG_LINK_MERGE_THRESHOLD, ClusterLinkage.MEAN_LINKAGE, SimType.COSINE);
Matrices.asSparseMatrix(v), AVG_LINK_MERGE_THRESHOLD, ClusterLinkage.MEAN_LINKAGE, SimType.COSINE);
wordToSemantics.entrySet()) vectorList[getIndexFor(e.getKey())] = e.getValue(); SparseMatrix matrix = Matrices.asSparseMatrix( Arrays.asList(vectorList)); matrix = Matrices.asSparseMatrix(Arrays.asList(newVectorList));
++curRow; m = Matrices.asSparseMatrix(Arrays.asList(rowArr));
wordToSemantics.entrySet()) vectorList[getIndexFor(e.getKey())] = e.getValue(); SparseMatrix matrix = Matrices.asSparseMatrix( Arrays.asList(vectorList)); matrix = Matrices.asSparseMatrix(Arrays.asList(newVectorList));
return Matrices.asSparseMatrix(vectors);
return Matrices.asSparseMatrix(vectors);
Properties props) { SparseMatrix contexts = Matrices.asSparseMatrix(contextSet);
Properties props) { SparseMatrix contexts = Matrices.asSparseMatrix(contextSet);
/** * 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); } }
Assignments assignments = null; if (sparseVectors.size() > 0) { SparseMatrix matrix = Matrices.asSparseMatrix(sparseVectors); assignments = (numClusters > 0) ? clustering.cluster(matrix, numClusters, props)
Assignments assignments = null; if (sparseVectors.size() > 0) { SparseMatrix matrix = Matrices.asSparseMatrix(sparseVectors); assignments = (numClusters > 0) ? clustering.cluster(matrix, numClusters, props)