Example #1
0
    // Use this for initialization
    void Start()
    {
        int[]         size  = { 2, 10, 10, 1 };
        System.IntPtr coeff = LibWrapper.create_MLP(size, 4);

        double[] points = new double[trainningExample.Length * 3];
        for (int i = 0; i < trainningExample.Length; i++)
        {
            points[i * 3]     = (trainningExample[i].position.y > 0)?1:-1;
            points[i * 3 + 1] = trainningExample[i].position.x / 10;
            points[i * 3 + 2] = trainningExample[i].position.z / 10;
        }
        LibWrapper.mlp_train_classification(coeff, points, trainningExample.Length, trainningExample.Length * 3, 800000);

        /*if(ok == 0) {
         *      Debug.Log("KO");
         * } else {
         *      Debug.Log("OK");
         * }*/
        foreach (var sphere in sphereTransforms)
        {
            double[] point  = { sphere.position.x / 10, sphere.position.z / 10 };
            double   result = LibWrapper.mlp_classify(coeff, point, 2);
            //Debug.Log(result);
            if (result < 0)
            {
                sphere.position += Vector3.down;
            }
            else
            {
                sphere.position += Vector3.up;
            }
        }
    }
Example #2
0
 public static void Main()
 {
     try
     {
         Bool bPointInRect = 0;
         Rect myRect       = new Rect();
         myRect.left   = 10;
         myRect.right  = 100;
         myRect.top    = 10;
         myRect.bottom = 100;
         Point myPoint = new Point();
         myPoint.x    = 50;
         myPoint.y    = 50;
         bPointInRect = LibWrapper.PtInRect(ref myRect, myPoint);
         if (bPointInRect == Bool.True)
         {
             Console.WriteLine("Point lies within the Rect");
         }
         else
         {
             Console.WriteLine("Point did not lie within the Rect");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception : " + e.Message);
     }
 }
    // Use this for initialization
    void Start()
    {
        int[]         size  = { 2, 10, 10, 1 };
        System.IntPtr coeff = LibWrapper.create_MLP(size, 4);

        double[] points = new double[trainningExample.Length * 3];
        for (int i = 0; i < trainningExample.Length; i++)
        {
            points[i * 3]     = trainningExample[i].position.y / 10;
            points[i * 3 + 1] = trainningExample[i].position.x / 10;
            points[i * 3 + 2] = trainningExample[i].position.z / 10;
        }
        LibWrapper.mlp_train_regression(coeff, points, trainningExample.Length, trainningExample.Length * 3, 800000);

        /*if(ok == 0) {
         *      Debug.Log("KO");
         * } else {
         *      Debug.Log("OK");
         * }*/
        foreach (var sphere in sphereTransforms)
        {
            double[] point  = { sphere.position.x / 10, sphere.position.z / 10 };
            float    result = (float)LibWrapper.mlp_regress(coeff, point, 2);
            sphere.position += Vector3.up * result * 10;
        }
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        System.IntPtr coeff = LibWrapper.linear_create(3);

        double[] points = new double[trainningExample.Length * 3];
        for (int i = 0; i < trainningExample.Length; i++)
        {
            points[i * 3]     = trainningExample[i].position.y;
            points[i * 3 + 1] = trainningExample[i].position.x;
            points[i * 3 + 2] = trainningExample[i].position.z;
        }
        LibWrapper.linear_train_regression(coeff, points, trainningExample.Length, trainningExample.Length * 3);

        foreach (var sphere in sphereTransforms)
        {
            double[] point  = { sphere.position.x, sphere.position.z };
            float    result = (float)LibWrapper.regress_point(coeff, point, 2);
            sphere.position += Vector3.up * result;
        }
    }
    // Use this for initialization
    void Start()
    {
        int nbinputs = 3;

        System.IntPtr coeff = LibWrapper.linear_create(nbinputs);

        double[] points = new double[trainningExample.Length * 3];
        for (int i = 0; i < trainningExample.Length; i++)
        {
            points[i * 3]     = (trainningExample[i].position.y > 0)?1:-1;
            points[i * 3 + 1] = trainningExample[i].position.x;
            points[i * 3 + 2] = trainningExample[i].position.z;
        }
        int ok = LibWrapper.linear_train_classification(coeff, points, trainningExample.Length, trainningExample.Length * 3);

        if (ok == 0)
        {
            Debug.Log("KO");
        }
        else
        {
            Debug.Log("OK");
        }
        foreach (var sphere in sphereTransforms)
        {
            double[] point  = { sphere.position.x, sphere.position.z };
            double   result = LibWrapper.classify_point(coeff, point, 2);
            //Debug.Log(result);
            if (result < 0)
            {
                sphere.position += Vector3.down;
            }
            else
            {
                sphere.position += Vector3.up;
            }
        }
    }
    private void guessWithMLPClassification(System.IntPtr coeff)
    {
        int nbErrors = 0;
        int nbGood   = 0;

        var maxage  = 90.0;
        var maxprix = 93.5;

        using (var rd = new StreamReader("titanic_test_data.csv"))
        {
            while (!rd.EndOfStream)
            {
                var list   = new List <double>();
                var splits = rd.ReadLine().Split(';');
                var vivant = double.Parse(splits[0], System.Globalization.CultureInfo.InvariantCulture);
                var classe = double.Parse(splits[1], System.Globalization.CultureInfo.InvariantCulture);
                var sex    = splits[2];
                var age    = double.Parse(splits[3], System.Globalization.CultureInfo.InvariantCulture) / maxage;
                var prix   = double.Parse(splits[4], System.Globalization.CultureInfo.InvariantCulture) / maxprix;
                switch ((int)classe)
                {
                case 1:
                    list.Add(1);
                    list.Add(0);
                    list.Add(0);
                    break;

                case 2:
                    list.Add(0);
                    list.Add(1);
                    list.Add(0);
                    break;

                case 3:
                    list.Add(0);
                    list.Add(0);
                    list.Add(1);
                    break;
                }
                if (sex.Equals("male"))
                {
                    list.Add(1);
                    list.Add(0);
                }
                else
                {
                    list.Add(0);
                    list.Add(1);
                }

                list.Add(age);
                list.Add(prix);
                double[] inputs = list.ToArray();
                double   result = LibWrapper.mlp_classify(coeff, inputs, 7);
                vivant = (vivant == 0)?-1:1;
                result = (result < 0)?-1:1;
                if (result == vivant)
                {
                    nbGood++;
                }
                else
                {
                    nbErrors++;
                }
            }
            double success = ((double)nbGood / (nbGood + nbErrors)) * 100;
            Debug.Log("bien trouvé : " + nbGood);
            Debug.Log("Erreur : " + nbErrors);
            Debug.Log("% réussite : " + success + "%");
        }
    }
    private System.IntPtr trainWithMLPClassification()
    {
        var list = new List <double>();

        var maxage  = 90.0;
        var maxprix = 93.5;

        using (var rd = new StreamReader("titanic_train_data.csv"))
        {
            while (!rd.EndOfStream)
            {
                var splits = rd.ReadLine().Split(',');
                var vivant = double.Parse(splits[0], System.Globalization.CultureInfo.InvariantCulture);
                var classe = double.Parse(splits[1], System.Globalization.CultureInfo.InvariantCulture);
                var sex    = splits[2];
                var age    = double.Parse(splits[3], System.Globalization.CultureInfo.InvariantCulture) / maxage;
                var prix   = double.Parse(splits[4], System.Globalization.CultureInfo.InvariantCulture) / maxprix;
                list.Add(vivant == 0?-1:1);
                switch ((int)classe)
                {
                case 1:
                    list.Add(1);
                    list.Add(0);
                    list.Add(0);
                    break;

                case 2:
                    list.Add(0);
                    list.Add(1);
                    list.Add(0);
                    break;

                case 3:
                    list.Add(0);
                    list.Add(0);
                    list.Add(1);
                    break;
                }
                if (sex.Equals("male"))
                {
                    list.Add(1);
                    list.Add(0);
                }
                else
                {
                    list.Add(0);
                    list.Add(1);
                }

                list.Add(age);
                list.Add(prix);
            }
            double[] inputs = list.ToArray();

            int[]         size  = { 8, 50, 50, 1 };
            System.IntPtr coeff = LibWrapper.create_MLP(size, 4);

            LibWrapper.mlp_train_classification(coeff, inputs, inputs.Length / 8, inputs.Length, 800000);

            return(coeff);
        }
    }