コード例 #1
0
ファイル: Cartisian.cs プロジェクト: XHLML/Machine-Learning
 public static void DrawBasicFunction(int x, int b)
 {
     for (int i = -Console.LargestWindowHeight / 2; x *i + b < Console.LargestWindowHeight / 2 && i < Console.LargestWindowWidth / 2; i++)
     {
         Cartisian.SetCartCoords(i, x * i + b);
         Console.Write('#');
     }
 }
コード例 #2
0
ファイル: Cartisian.cs プロジェクト: XHLML/Machine-Learning
 public static void DrawSystem()
 {
     for (int i = -Console.LargestWindowWidth / 2; i < Console.LargestWindowWidth / 2; i++)
     {
         Cartisian.SetCartCoords(i, 0);
         Console.Write("#");
     }
     for (int i = -Console.LargestWindowHeight / 2; i < Console.LargestWindowHeight / 2; i++)
     {
         Cartisian.SetCartCoords(0, i);
         Console.Write("#");
     }
 }
コード例 #3
0
        static void Cartisian_x_y_learn()
        {
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            Console.SetWindowPosition(0, 0);

            Cartisian.DrawSystem();
            Cartisian.DrawBasicFunction(7, -8);

            Point[]    points = new Point[100];
            Preceptron p      = new Preceptron(2);

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new Point(true);
                if (points[i].y <= 7 * points[i].x - 8)
                {
                    points[i].lable = 1;
                }
                else
                {
                    points[i].lable = -1;
                }
            }

            foreach (Point poo in points)//shows the state before
            {
                if (1 == poo.lable)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                poo.CartShow();
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.ReadLine();
            Console.Clear();

            Cartisian.DrawSystem();
            Cartisian.DrawBasicFunction(7, -8);

            for (int l = 0; l < 100;)
            {//trains the preceptron
                foreach (Point po in points)
                {
                    l = 0;
                    p.train(new double[] { po.x, po.y }, po.lable);
                    foreach (Point poo in points)//shows after each train
                    {
                        if (p.guess(new double[] { poo.x, poo.y }) == poo.lable)
                        {
                            l++;
                        }
                        if (p.guess(new double[] { poo.x, poo.y }) == 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        poo.CartShow();
                    }

                    Console.WriteLine(p);
                }
            }

            Console.ReadLine();
            Console.WriteLine(p);
            Cartisian.DrawBasicFunction((int)Math.Round(p.GetM()), (int)Math.Round(p.GetB()));
        }
コード例 #4
0
 public void CartShow()
 {
     Cartisian.SetCartCoords(this.x, this.y);
     Console.Write('*');
 }