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 ParticleAreaFilter(int numberOfParticles, int numberOfCircleDistances) { _numberOfParticles = numberOfParticles; _numberOfCircleDistances = numberOfCircleDistances; _particles = new ConcurrentDictionary <int, ParticleHistory>(); _euclidean = new Euclidean(); }
public static void PickAlgorithm() { Console.WriteLine("Pick 1 for Euclidean"); Console.WriteLine("Pick 2 for Pearson"); Console.WriteLine("Pick 3 for Cosine"); choice = int.Parse(Console.ReadLine()); var user1 = SelectUser.selectUserCosine(dictionary); var user2 = SelectUser.selectUserCosine(dictionary); switch (choice) { case 1: Console.WriteLine("You have chosen Euclidian"); Console.WriteLine("The similarity is: " + Euclidean.ComputeEuclidean(user1, user2)); Console.ReadLine(); break; case 2: Console.WriteLine("You have chosen Pearson"); Console.WriteLine("The similarity is: " + Pearson.ComputePearson(user1, user2)); Console.ReadLine(); break; case 3: Console.WriteLine("You have chosen Cosine"); Console.WriteLine("The similarity is: " + Cosine.ComputeCosine(user1, user2)); Console.ReadLine(); break; default: Console.WriteLine("Closed"); Console.ReadLine(); break; } }
void onClickSave() { GameObject car = null; // check if the simulation is running.... if (isRiding) { if (isSimulating) { String data = ""; //check the simulation tyep if (SimulationMode == 1) { car = Euclidean.FinalSelectedCar; data = Euclidean.getSavingData(); } if (SimulationMode == 2) { car = AntColonyController.FirstCar; data = AntColonyController.getSavingData(); } if (SimulationMode == 3) { data = MPAC.getSavingData(); } // save the data on a local file StreamWriter writer = new StreamWriter("Data.csv", true); writer.WriteLine(data); writer.Close(); } } }
public ParticleHistory3D(int historyCount) { _historyCount = historyCount; GeneratedCoordinate = new List <CoordinateHistory>(historyCount); _lastAccelerations = new ConcurrentQueue <double>(); _euclid = new Euclidean(); }
public void EuclideanDistance(double[] x, double[] y, double expected) { var result = Euclidean.Distance(x, y); result = Math.Truncate(result * 100) / 100; Assert.Equal(expected, result); }
/// <summary> /// Gets the equivalent angle moved within the range of <paramref name="minValue"/> /// and <paramref name="minValue"/> + 2.0 * <see cref="Math.PI"/>. /// </summary> /// <param name="minValue">The minimum value of the range.</param> /// <param name="inclusive">Indicates whether the range is inclusive of the minimum value.</param> /// <returns>The equivalent angle within the specified range.</returns> public Angle ToRange(Angle minValue, bool inclusive = true) { const double TwoPI = 2.0D * Math.PI; return(inclusive ? Euclidean.Wrap(this, minValue, TwoPI) : Euclidean.Wrap(this, -minValue, -TwoPI)); }
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 EuclideanCase() { var result1 = Euclidean.Distance(new double[] { 0, 0 }, new double[] { 1, 0 }); var result2 = Euclidean.Distance(new double[] { 0, 0 }, new double[] { 3, 2 }); var result3 = Euclidean.Distance(new double[] { -7, -4, 3 }, new double[] { 17, 6, 2.5 }); var result4 = Euclidean.Distance(new double[] { 5, 13, 17, 3, 25, 21, 7, 1 }, new double[] { 20, 26, 7, 5, 28, 3, 23, 10 }); }
//тест с вызовом рекурсии public void GetNodTest_5() { Euclidean test1 = new Euclidean(); int first = 13; int second = 13; int expected = 13; int result = test1.GetNod(first, second, out _); Assert.AreEqual(expected, result); }
public void GetNodSteinTest() { Euclidean test2 = new Euclidean(); int first = 15; int second = 21; int expected = 3; int result = test2.GetNodStein(first, second, out double ts); Assert.AreEqual(expected, result); }
//тест с обычными значениями public void GetNodTest_1() { Euclidean test1 = new Euclidean(); int first = 100; int second = 25; int expected = 25; int result = test1.GetNod(first, second, out _); EuclideanTests.Equals(expected, result); }
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); }
//тест с тремя входными public void GetNodTest_7() { Euclidean test1 = new Euclidean(); int first = 130; int second = 374; int third = 258; int expected = 2; int result = test1.GetNod(first, second, third); Assert.AreEqual(expected, result); }
public static IEnumerable <User> findSimilarUsers(this List <User> db, User user) { foreach (var user2 in db) { if (user.name == user2.name) { continue; } user2.scores = Euclidean.euclidean_score(user, user2); yield return(user2); } }
static void Main(string[] args) { long x = 1; for (int i = 2; i < maxNumber; i++) { x = Euclidean.Lcm(x, i); } Debug.Assert(x == 232792560); Console.WriteLine(x); Console.ReadLine(); }
//тест с пятью входными, 1 после первых двух чисел public void GetNodTest_10() { Euclidean test1 = new Euclidean(); int first = 7; int second = 24; int third = 240; int fourth = 138; int fifth = 186; int expected = 1; int result = test1.GetNod(first, second, third, fourth, fifth); Assert.AreEqual(expected, result); }
static void Main(string[] args) { System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; bool optionChosen = true; while (optionChosen) { string option = Options.ChooseTopic(); while (!int.TryParse(option, out _) || int.Parse(option) < 1 || int.Parse(option) > 26) { Console.WriteLine("Invalid option."); option = Console.ReadLine(); } optionChosen = option switch { "1" => SinglyLinkedListSample.Sample(), "2" => DoublyLinkedListSample.Sample(), "3" => ArraySamples.SingleDimensionalArrays(), "4" => ArraySamples.MultidimensionalArrays(), "5" => ArraySamples.JaggedArrays(), "6" => ArraySamples.ArrayListClass(), "7" => BubbleSort.SortSample(), "8" => SelectionSort.SortSample(), "9" => InsertionSort.SortSample(), "10" => ShellSort.SortSample(), "11" => MergeSort.SortSample(), "12" => HeapSort.SortSample(), "13" => QuickSortSample.SortSample(), "14" => CountingSort.SortSample(), "15" => RadixSortSample.SortSample(), "16" => BucketSortSample.SortSample(), "17" => SequentialSearch.SearchSample(), "18" => BinarySearchSample.SearchSample(), "19" => TestBinarySearchTree(), "20" => BreadthFirstSearchSample.SearchSample(), "21" => DepthFirstSearchSample.SearchSample(), "22" => FibonacciSample.Run(), "23" => AnagramSample.Run(), "24" => PalindromeSample.Run(), "25" => Euclidean.Run(), _ => false, }; Console.ReadKey(); } }
public void GetAlgsTimeTest() { Euclidean test3 = new Euclidean(); int first = 1073; int second = 1597; test3.GetAlgsTime(first, second, out string [] masX, out double [] masY); string algsEuclidName = "EuclidAlgs"; string algsSteinName = "SteinAlgs"; Assert.AreEqual(algsEuclidName, masX[0]); Assert.AreEqual(algsSteinName, masX[1]); //Assert.AreEqual(masY[0], masY[1]); //тест с ошибкой, чтобы увидеть время выполнения }
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"); } }
public void FindDeviderForTwoDigitsTest() { TimeSpan time; for (int i = 0; i < testValuesCasesForTwoDigits.GetLength(0); i++) { int result = Euclidean.FindDevider(testValuesCasesForTwoDigits[i, 0], testValuesCasesForTwoDigits[i, 1], out time); Assert.AreEqual(testValuesCasesForTwoDigits[i, 2], result); TestContext.WriteLine(string.Format("Значение 1: {0}, Значение 2: {1}, Ожидаемое значение: {2}, Затраченое время: {3}", testValuesCasesForTwoDigits[i, 0], testValuesCasesForTwoDigits[i, 1], testValuesCasesForTwoDigits[i, 2], time.TotalMilliseconds)); } }
public static void InverseTest() => TrafoTesting.GenericTest(rnd => { var e = TrafoTesting.GetRandomEuclidean(rnd); var p = rnd.UniformV3d() * rnd.UniformInt(1000); var q = e.TransformPos(p); // Inverse property var res = e.Inverse.TransformPos(q); // Invert method Euclidean.Invert(ref e); var res2 = e.TransformPos(q); TrafoTesting.AreEqual(p, res); TrafoTesting.AreEqual(p, res2); });
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); }
// 0 = no Simulation // 1 = Euclidean // 2 = Ant Colony // 3 = MPAC //GameObject EuclideanCar = null; //GameObject AntCar = null; //GameObject MPACCar = null; // Use this for initialization void Start() { nodeCount = nodeGrid * nodeGrid; algoEuclidean = gameObject.GetComponent <Euclidean> (); algoAntColony = gameObject.GetComponent <AntColonyController> (); algoMPAC = gameObject.GetComponent <MPAC> (); userSelector = gameObject.GetComponent <UserSelector> (); carGenerator = gameObject.GetComponent <CarGenerator> (); // create the under laying surface GameObject surface; surface = GameObject.CreatePrimitive(PrimitiveType.Quad); surface.transform.Rotate(new Vector3(90, 0, 0)); surface.transform.localScale = new Vector3(2 * boundry, 2 * boundry, 1); surface.GetComponent <MeshRenderer> ().material = groundMat; GenerateGraph(); isMapGenerated = true; resetButton.onClick.AddListener(onClickReset); btnEuclidean.onClick.AddListener(onClickEuclidean); btnAntColony.onClick.AddListener(onClickAntColony); btnMPAC.onClick.AddListener(onClickMPAC); sliderAntSpeed.onValueChanged.AddListener(onSliderValueChange); sliderPheremoneEvaporate.onValueChanged.AddListener(onPheremoneSliderValueChange); btnRefresh.onClick.AddListener(onRefreshButton); toggleHideAnts.onValueChanged.AddListener((value) => { onToggleHideAnts(); }); toggleGenderPref.onValueChanged.AddListener((value) => { onToggleGenderPref(value); }); toggleAgePref.onValueChanged.AddListener((value) => { onToggleAgePref(value); }); Gender_Male.onValueChanged.AddListener((value) => { onToggleGenderMale(value); }); Gender_Female.onValueChanged.AddListener((value) => { onToggleGenderFemale(value); }); Age_30.onValueChanged.AddListener((value) => { onToggleAge30(value); firstAgeCall = true; }); Age_49.onValueChanged.AddListener((value) => { onToggleAge49(value); firstAgeCall = true; }); Age_50.onValueChanged.AddListener((value) => { onToggleAge50(value); firstAgeCall = true; }); SaveButton.onClick.AddListener(onClickSave); carGenerator.Generate(carCount); }
void Start() { //POKEMONES pokemons = GameObject.FindGameObjectsWithTag("Pokemon"); for (int i = 0; i < pokemons.Length; i++)//le sacamos todos los kinetics a los pokes { kinsList.Add(pokemons[i].GetComponent <static_data>().kineticsAgent); } pokemonKins = kinsList.ToArray(); amountPokemon = pokemons.Length; //TRAINER kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; //Inicializamos movimiento (no es necesario pasar el pokemon porque lo haremos por posicion) seek = new Seek(kineticsAgent, kineticsAgent, maxAccel); //Inicializamos grafo y A* graph = graphComponent.graph; pokemonPosition = pokemonKins[0].transform.position; walkable = new string[] { "Earth" }; //sobre que podemos movernos Node start = graph.FindNode(transform.position, walkable); //buscamos el triangulos con nuestra posicion actual Node goal = graph.FindNode(pokemonPosition, walkable); //buscamos el triangulo donde esta el primer pokemon if (goal is null) //si no hay un triangulo para el goal vamos a donde estamos parados { goal = start; } Euclidean euclidean = new Euclidean(goal); aStar = new PathFindAStar(graph, start, goal, euclidean, walkable); currentPath = aStar.GetPath(); currentTarget = currentPath[0]; utilities.DrawPath(currentPath, 40f); }
static void Main(string[] args) { IDistance distanceType = new Euclidean();; var numbOfIterations = 50; var MAXclusterIterations = 30; var data = new DataReader().Read(); List <Tuple <int, double> > listBestSSE = new List <Tuple <int, double> >(); /* ITERATE FROM 1 TO MAX AMOUNT OF CLUSTER TO FIND THE LOWEST SSE AND HIGHEST SILLOUETTE */ Console.WriteLine("::::::::::DIFFERENT NUMBERS OF CLUSTERS RESULTS::::::::::"); for (int clusters = 2; clusters < MAXclusterIterations + 1; clusters++) { var kmeans2 = new KmeansClustering(numbOfIterations, clusters, data, distanceType); Console.WriteLine("for " + clusters + " clusters -> SSE: " + kmeans2.SSE); // PRINT THE SSE AND SILHOUETTE FOR EACH AMOUNT OF K(CLUSTERS) listBestSSE.Add(new Tuple <int, double>(clusters, kmeans2.SSE)); } var lowestSSE = listBestSSE.Min(x => x.Item2); Console.WriteLine("________________________________________"); Console.WriteLine("number of clusters: " + listBestSSE.Where(x => x.Item2.Equals(lowestSSE)).First().Item1); Console.WriteLine("Lowest SSE: " + lowestSSE); Console.WriteLine("________________________________________"); /* ITERATE WITH THE NUMBER OF CLUSTER WITH THE BEST SSE */ var data2 = new DataReader().Read(); var k_with_lowest_SSE = listBestSSE.Where(x => x.Item2.Equals(lowestSSE)).First().Item1; var kmeans = new KmeansClustering(numbOfIterations, k_with_lowest_SSE, data2, distanceType); var sill = new Sillhouette(kmeans.Centroids, data2, distanceType); Console.WriteLine("sillhouette: " + sill.AGVSillouette); kmeans.PrintAll(); var MINamountOfBoughtWine = 0; //TOP DEALS new TopDeal().getTopDeal(kmeans.Centroids, MINamountOfBoughtWine); Console.ReadLine(); Console.ReadLine(); }
static void Main(string[] args) { // var dataLoader = new DataLoader(); // dataLoader.Load("../../../WineKMC.xlsx", "../../../PivotSnippet.csv"); // Console.WriteLine(dataLoader); // var customerInfo = new CustomerInfo("42069", "Henk Pieterse","123445"); // var cosine = new Cosine(); var euclidean = new Euclidean(); // var randomNumbers = new RandomNumbers(); var kmeans = new KMeans(); kmeans.InitializeCentroids(4, 32); kmeans.InitializePoints("../../../PivotSnippet.csv", 32); kmeans.ComparePoints(); }
public void Gcd() { for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 200; j++) { Test(i, j); } } void Test(int x, int y) { var actual = Euclidean.Gcd(x, y); Assert.IsTrue(x % actual == 0 && y % actual == 0); for (int i = Math.Min(x, y); i > actual; i--) { Assert.IsFalse(x % i == 0 && y % i == 0); } } }
public void ExtendedEuclid() { for (int i = 1; i <= 100; i++) { for (int j = i + 1; j <= 100; j++) { Test(i, j); } } void Test(long a, long b) { var g = Euclidean.Gcd(a, b); a /= g; b /= g; var(x, y) = Euclidean.ExtendedEuclid(a, b); Assert.IsTrue(Math.Abs(x) <= b); Assert.IsTrue(Math.Abs(y) <= a); Assert.AreEqual(1, a * x + b * y); } }
public void Lcm() { for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 150; j++) { Test(i, j); } } void Test(int x, int y) { var actual = Euclidean.Lcm(x, y); Assert.IsTrue(actual % x == 0 && actual % y == 0); for (int i = Math.Max(x, y); i < actual; i++) { Assert.IsFalse(i % x == 0 && i % y == 0); } } }