예제 #1
0
파일: Program.cs 프로젝트: kapmati/MiW_AiR
 private static double getDistanceBeetwen(Iris inputIris, Iris anotherIris)
 {
     return(Math.Sqrt(Math.Pow((inputIris.getLeafLength() - anotherIris.getLeafLength()), 2)
                      + Math.Pow((inputIris.getLeafWidth() - anotherIris.getLeafWidth()), 2)
                      + Math.Pow((inputIris.getPetalLength() - anotherIris.getPetalLength()), 2)
                      + Math.Pow((inputIris.getPetalWidth() - anotherIris.getPetalWidth()), 2)));
 }
예제 #2
0
파일: Program.cs 프로젝트: kapmati/MiW_AiR
        static void Main(string[] args)
        {
            Console.WriteLine("Metoda K Najbliższych Sąsiadów");
            Console.WriteLine();

            //Wczytanie pliku
            readFile(setOfIrises, "IrisData.txt");

            //Wprowadzenie współrzędnych nowego punktu
            //W przypadku liczby z ułamkiem dziesiętym należy użyć przecinka zamiast kropki
            Console.WriteLine("Wprowadź dane obiektu");
            List <double> inputCoordinates = new List <double>();

            setNewCoordinates(inputCoordinates);
            Iris inputIris = new Iris(inputCoordinates[0], inputCoordinates[1], inputCoordinates[2], inputCoordinates[3]);

            //Wprowadzenie liczby sąsiadów K
            Console.Write("Parametr K: ");
            parameterK = Convert.ToInt32(Console.ReadLine());

            //Stworzenie kolekcji Dictionary<Iris,double> zawierającej obiekty wraz z odległościami od wprowadzonego obiektu
            foreach (Iris singleIris in setOfIrises)
            {
                distances.Add(singleIris, getDistanceBeetwen(inputIris, singleIris));
            }

            //Wyszukanie najbliższych K sąsiadów
            findNeighbours();

            //Zliczenie typów
            countTypes();

            //Prezentacja wyników
            Console.WriteLine();
            Console.WriteLine("Neighbours:");
            foreach (Iris singleNeighbour in nearestNeighbours)
            {
                singleNeighbour.showIris();
            }
            Console.WriteLine();
            Console.WriteLine("Setosa: " + setosa + "  Versicolor: " + versicolor + "  Virginica: " + virginica);
            Console.WriteLine();
            Console.WriteLine("Obiekt o parametrach:");
            Console.WriteLine("leaf-length = " + inputIris.getLeafLength());
            Console.WriteLine("leaf-width = " + inputIris.getLeafWidth());
            Console.WriteLine("petal-length = " + inputIris.getPetalLength());
            Console.WriteLine("petal-width = " + inputIris.getPetalWidth());
            Console.WriteLine("dla parametru K = " + parameterK);
            Console.WriteLine("jest klasy " + getProperType(setosa, versicolor, virginica));
            Console.WriteLine();
            Console.WriteLine("Wcisnij dowolny klawisz aby zakonczyc dzialanie programu.");
            Console.ReadKey();
        }