private Dictionary <int, double[][]> UpdateClusterData(double[][] centroids, double[][] observations, int k) { var clusters = new Dictionary <int, double[][]>(); for (int j = 0; j < k; j++) { clusters.Add(j, new double[0][]); } for (int n = 0; n < observations.Length; n++) { double minDistance = double.MaxValue; var selectedCluster = int.MinValue; for (int i = 0; i < k; i++) { var distance = Euclidean.Calculate(centroids[i], observations[n]); if (distance < minDistance) { selectedCluster = i; minDistance = distance; } } clusters[selectedCluster] = clusters[selectedCluster].Append(observations[n]); } return(clusters); }
public void Calculate_TwoVectors_EuclideanDistance() { var x = new double[] { 500, 500 }; var y = new double[] { 410, 400 }; var d = Euclidean.Calculate(x, y); Assert.AreEqual(134.53624, Math.Round(d, 6)); }
public void ComparePoints() { Euclidean euclidean = new Euclidean(); var res = euclidean.Calculate(Points[1].CustomerSalesInfo, Points[2].CustomerSalesInfo); for (int i = 0; i < Points[1].CustomerSalesInfo.Length; i++) { Console.WriteLine(Points[1].CustomerSalesInfo[i] + ","); } Console.WriteLine("Euclidean: " + res); }
private void btnSearch_Click(object sender, RoutedEventArgs e) { if (txtPrice.Text.Length > 0) { if (cb_CPU.SelectedIndex != -1 || cb_cores.SelectedIndex != -1 || cb_RAM.SelectedIndex != -1 || cb_SSDorHDD.SelectedIndex != -1 || cb_Storage.SelectedIndex != -1 || cb_vRam.SelectedIndex != -1 || cb_diagonal.SelectedIndex != -1 || cb_weight.SelectedIndex != -1 || cb_battery_capacity.SelectedIndex != -1 || cb_refresh_rate.SelectedIndex != -1 || par_CPU.SelectedIndex != -1 || par_Cores.SelectedIndex != -1 || par_RAM.SelectedIndex != -1 || par_SDDHDD.SelectedIndex != -1 || par_Sorage.SelectedIndex != -1 || par_VRAM.SelectedIndex != -1 || par_DIAG.SelectedIndex != -1 || par_Weigh.SelectedIndex != -1 || !par_BATTERY.SelectedIndex.Equals(-1) || !par_REFRESH.SelectedIndex.Equals(-1)) { int prefPrice = cb_refresh_rate_Copy.SelectedIndex + 1; int prefCPU = cb_CPU.SelectedIndex + 1; int prefCores = cb_cores.SelectedIndex + 1; int prefRAM = cb_RAM.SelectedIndex + 1; int prefSSDorHDD = cb_SSDorHDD.SelectedIndex + 1; int prefStorage = cb_Storage.SelectedIndex + 1; int prefVRAM = cb_vRam.SelectedIndex + 1; int prefDiagonal = cb_diagonal.SelectedIndex + 1; int prefWeight = cb_weight.SelectedIndex + 1; int prefBatteryCapacity = cb_battery_capacity.SelectedIndex + 1; int prefRefreshRate = cb_refresh_rate.SelectedIndex + 1; Computer desiredSpecs = new Computer(); desiredSpecs.setBatteryCapacity(Convert.ToInt32(par_BATTERY.SelectedItem)); desiredSpecs.setCores(Convert.ToInt32(par_Cores.SelectedItem)); desiredSpecs.setCPU(Convert.ToDouble(par_CPU.SelectedItem)); desiredSpecs.setDiagonal(Convert.ToDouble(par_DIAG.SelectedItem)); desiredSpecs.setRAM(Convert.ToInt32(par_RAM.SelectedItem)); desiredSpecs.setRefreshRate(Convert.ToInt32(par_REFRESH.SelectedItem)); desiredSpecs.setVRAM(Convert.ToInt32(par_VRAM.SelectedItem)); desiredSpecs.setWeight(Convert.ToDouble(par_Weigh.SelectedItem)); desiredSpecs.setSSD(Convert.ToBoolean(par_SDDHDD.SelectedItem)); desiredSpecs.setStorageCapacity(Convert.ToInt32(par_Sorage.SelectedItem)); desiredSpecs.setPrice(Convert.ToDouble(txtPrice.Text)); pcs = Euclidean.Calculate(prefPrice, prefCPU, prefCores, prefRAM, prefSSDorHDD, prefStorage, prefVRAM, prefDiagonal, prefWeight, prefBatteryCapacity, prefRefreshRate, listOfComputers, desiredSpecs); pcs.Sort((x, y) => x.getResult().CompareTo(y.getResult())); FillUC(pcs); } else { MessageBox.Show("Neįrašėte pasirinkimų"); } } else { MessageBox.Show("Neįrašėte kainos"); } }
private double[] GetPointWithMaxDistance(double[][] clusterCentroids, double[][] observations, double[] point) { double[] result = null; var maxDistance = double.MinValue; for (int i = 0; i < observations.Length; i++) { var distance = Euclidean.Calculate(point, observations[i]); if (distance > maxDistance && !clusterCentroids.In(observations[i])) { maxDistance = distance; result = observations[i]; } } return(result); }
static void Main(string[] args) { Dictionary <int, List <UserPreferences> > dataSet; SelectFile selectFile = new SelectFile(); selectFile.selectDataSet();// FileReader newFile = new FileReader(); dataSet = newFile.selectBigDataset(); Console.WriteLine("------ Pearson ------"); Pearson pearsonTest = new Pearson(dataSet); for (int i = 1; i < dataSet.Count; i++) { Console.WriteLine("user: "******" | vs the rest!: " + pearsonTest.Calculate(i)); } Console.WriteLine("------ Euclidean ------"); Euclidean euclideanTest = new Euclidean(dataSet); for (int i = 1; i < dataSet.Count; i++) { Console.WriteLine(euclideanTest.Calculate(i)); } Console.WriteLine("------ Cosine ------"); Cosine cosineTest = new Cosine(dataSet); for (int i = 1; i < dataSet.Count; i++) { Console.WriteLine(cosineTest.Calculate(i)); } Console.WriteLine("Oopsiepoepsie"); Console.ReadKey(); }