private int FindClosestClusterCenter(List <Centeroid <T> > clusterCenter, DocumentVector <T> obj) { float[] similarityMeasure = new float[clusterCenter.Count()]; for (int i = 0; i < clusterCenter.Count(); i++) { similarityMeasure[i] = SimilarityMatrics.FindCosineSimilarity(clusterCenter[i].GroupedDocument[0].VectorSpace, obj.VectorSpace); } int index = 0; float maxValue = similarityMeasure[0]; for (int i = 0; i < similarityMeasure.Count(); i++) { if (similarityMeasure[i] > maxValue) { maxValue = similarityMeasure[i]; index = i; } } return(index); }
private int FindClosestClusterCenter(List <Centeroid <T> > clusterCenter, DocumentVector <T> docVector) { float[] similarityMeasure = new float[clusterCenter.Count]; int index = 0; float maxValue = similarityMeasure[0]; Parallel.For(0, clusterCenter.Count, i => { if (clusterCenter[i].GroupedDocument.Count > 0) { similarityMeasure[i] = SimilarityMatrics .FindCosineSimilarity(clusterCenter[i].GroupedDocument[0].VectorSpace, docVector.VectorSpace); } if (similarityMeasure[i] > maxValue) { maxValue = similarityMeasure[i]; index = i; } }); return(index); }
public static string FindClosestDocument() { if (centroid != null) { //int countCenter = centroid.GroupedDocument.Count() - 1; float max = 0; string doc = ""; // Tính độ tương tự của document với các center rồi add vào mảng similarityMeasure foreach (var ce in centroid.GroupedDocument) { if (ce.Content != documentVector.Content) { float current = SimilarityMatrics.FindCosineSimilarity(ce.VectorSpace, documentVector.VectorSpace); if (max < current) { max = current; doc = ce.Content; } } } return(doc); } return(null); }