private static Tuple <double[][], double[][]> split(double[][] cluster, KMeans kmeans, double threshold) { kmeans.Randomize(cluster, useSeeding: false); kmeans.Tolerance = threshold; kmeans.ComputeInformation = false; int[] idx = kmeans.Compute(cluster); List <double[]> a = new List <double[]>(); List <double[]> b = new List <double[]>(); for (int i = 0; i < idx.Length; i++) { if (idx[i] == 0) { a.Add(cluster[i]); } else { b.Add(cluster[i]); } } return(Tuple.Create(a.ToArray(), b.ToArray())); }
/// <summary> /// Initializes the model with initial values obtained /// throught a run of the K-Means clustering algorithm. /// </summary> /// public double Initialize(double[][] data, double threshold) { double error = double.MaxValue; double errorNew; KMeans kmeans = new KMeans(clusters.Count); for (int i = 0; i < 100; ++i) { // Create a new K-Means algorithm KMeans _kmeans = new KMeans(clusters.Count); // Compute the K-Means _kmeans.Compute(data, threshold, out errorNew); // is this the best model so far? if (errorNew < error || i == 0) { error = errorNew; kmeans = _kmeans; } } // Initialize the model with K-Means Initialize(kmeans); return(error); }
/// <summary> /// Initializes the model with initial values obtained /// through a run of the K-Means clustering algorithm. /// </summary> /// public double Initialize(double[][] data, double threshold) { double error; // Create a new K-Means algorithm KMeans kmeans = new KMeans(clusters.Count); // Compute the K-Means kmeans.Compute(data, threshold, out error); // Initialize the model with K-Means Initialize(kmeans); return(error); }
/// <summary> /// Initializes the model with initial values obtained /// through a run of the K-Means clustering algorithm. /// </summary> /// public double Initialize(double[][] data, double threshold) { double error; // Create a new K-Means algorithm KMeans kmeans = new KMeans(clusters.Count) { ComputeInformation = true, UseCentroidSeeding = false, Tolerance = threshold }; // Compute the K-Means kmeans.Compute(data, out error); // Initialize the model with K-Means Initialize(kmeans); return(error); }
private static Tuple <double[][], double[][]> split(double[][] cluster, KMeans kmeans) { kmeans.Randomize(cluster); int[] idx = kmeans.Compute(cluster); List <double[]> a = new List <double[]>(); List <double[]> b = new List <double[]>(); for (int i = 0; i < idx.Length; i++) { if (idx[i] == 0) { a.Add(cluster[i]); } else { b.Add(cluster[i]); } } return(Tuple.Create(a.ToArray(), b.ToArray())); }