예제 #1
0
        public void Delta(Neigbhour point)
        {
            double sum = Sum(point);

            if (point.type == "Iris-setosa")
            {
                while (sum == 0)
                {
                    for (int i = 0; i < weights.Count; i++)
                    {
                        weights[i] += (1 - sum) * learningConst * point.points[i];
                    }
                    thetha += (1 - sum) * learningConst;
                    sum     = Sum(point);
                }
            }
            else
            {
                while (sum == 1)
                {
                    for (int i = 0; i < weights.Count; i++)
                    {
                        weights[i] += -sum * learningConst * point.points[i];
                    }
                    thetha += -sum * learningConst;
                    sum     = Sum(point);
                }
            }
        }
예제 #2
0
        public double Sum(Neigbhour point)
        {
            double sum = 0;

            for (int i = 0; i < point.points.Count; i++)
            {
                sum += point.points[i] * weights[i];
            }
            return(sum >= thetha ? 1 : 0);
        }
예제 #3
0
        static void Main(string[] args)
        {
            string[] trainingContent = File.ReadAllLines("iris_training.txt");
            string[] testContent     = File.ReadAllLines("iris_test.txt");

            var training = new List <Neigbhour>();
            var test     = new List <Neigbhour>();

            for (int i = 0; i < trainingContent.Length; i++)
            {
                training.Add(new Neigbhour(trainingContent[i], true));
            }
            for (int i = 0; i < testContent.Length; i++)
            {
                test.Add(new Neigbhour(testContent[i], true));
            }

            var perceptron = new Perceptron(training[0].points.Count);

            perceptron.StartLearning(training, 10);

            perceptron.RunTest(test);

            Console.WriteLine("Czy chcesz wprowadzić dane? (Y/N):");
            string answer = Console.ReadLine().ToLower().Trim();
            bool   loop   = answer.Equals("y");

            while (loop)
            {
                Console.WriteLine("Podaj dane: ");
                string input = Console.ReadLine();

                var p = new Neigbhour(input, false);

                string pickedType = perceptron.Sum(p) == 1 ? "Iris-setosa" : "nie Iris-setosa";

                Console.WriteLine($"Podany typ to {pickedType}");

                Console.WriteLine("Czy chcesz wprowadzić dane? (Y/N):");
                answer = Console.ReadLine().ToLower().Trim();
                loop   = answer.Equals("y");
            }
        }