Пример #1
0
    // Use this for initialization
    void Start()
    {
        num_neurons = 10;
        double[] p_list = new double[120] {
            7.513874, -13.31366, -5.891386, 3.89313, -13.35374, -5.470473, -28.48326, -0.8950226, 1.676227, -7.829721, 3.001554, 0.9742008, 6.85763, 12.07218, -1.542749, 6.42987, -6.777609, -12.28891, -11.6297, -3.275043, -0.3349386, 13.02803, -3.171752, 2.909704, 7.935295, 2.154472, 5.825492, 6.763169, 6.5986, 0.846593, 6.619426, 0.1207947, 7.378351, 5.546535, -0.8831579, -3.48157, 2.024852, -5.732147, 16.51345, -11.30504, -4.979899, 0.1936812, -7.330712, -2.363033, -5.555974, -11.48479, 6.027504, -0.5046204, -5.604547, 6.99612, 8.643599, -0.5479781, 1.765478, 12.20771, -14.86998, -10.28358, 1.827907, -1.541205, 8.282341, 14.34195, 0.6747534, 8.42286, -10.29843, -0.5448059, 6.860302, -7.558879, -3.571216, -3.13385, 12.60011, -0.07997914, -4.452103, 1.369113, 7.464754, -8.164039, -4.246214, -7.685563, -1.948951, 15.26882, -5.696559, -1.464601, 1.735656, 13.39631, 12.12768, -10.33641, 1.26995, 6.143419, -3.200521, -6.426282, -4.033798, -9.858385, 3.240334, 5.088798, -8.307716, 4.577082, 9.247719, -4.710557, 11.59537, 1.740587, 1.173246, 5.654369, -0.01115066, 3.742572, 0.01587177, 5.836065, -1.146728, -0.4543813, -0.09580191, -3.896233, -1.911579, 4.912868, -0.4526708, 3.798782, 4.286755, 2.614983, 3.773993, -1.182102, 3.293242, 3.547439, 4.012696, 0.9868906,
        };
        float[] param_list = new float[120];
        for (int i = 0; i < 120; i++)
        {
            param_list [i] = (float)p_list [i];
        }

        run          = 1;
        spring_const = 1000;
        damper       = 100;

        //System.IO.File.Delete("C:/UnityLogs/best_costs.txt");

        //Assign joint references
        hip_right  = upper_right.GetComponent <ConfigurableJoint> ();
        knee_right = lower_right.GetComponent <HingeJoint> ();
        hip_left   = upper_left.GetComponent <ConfigurableJoint> ();
        knee_left  = lower_left.GetComponent <HingeJoint> ();

        gen_alg = new GenAlg();
        //net = new RNN (gen_alg.GetCurrentChrom());
        net = new RNN(new Chromosome(param_list));

        Debug.Log("weights: " + net.weights.ToString());
        counter = 0;

        //SetAngles (new float[]{0f, 0f, 0.5f, 0.5f, 0.5f, 0.5f});
        //SetAngles (new float[]{0f, 0f, 0f, 0f, 0f, 0f});
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        genAlg     = GetComponent <GenAlg>();
        timeTicker = timeLeft;

        for (int i = 0; i < noOfLoaders; i++)
        {
            float randomX = Random.Range(-4.5f, 4.5f);
            float randomZ = Random.Range(-4.5f, 4.5f);

            float randomRotationY = Random.Range(0.0f, 360.0f);

            Instantiate(loader, new Vector3(randomX, 0.3f, randomZ), Quaternion.Euler(0.0f, randomRotationY, 0.0f));
        }


        for (int i = 0; i < noOfMines; i++)
        {
            float randomX = Random.Range(-4.5f, 4.5f);
            float randomZ = Random.Range(-4.5f, 4.5f);

            Instantiate(mine, new Vector3(randomX, 0.25f, randomZ), transform.rotation);
        }

        loaders = GameObject.FindGameObjectsWithTag("Loader");

        if (loaders.Length != 0)
        {
            numberOfWeightsInNN = loaders[0].GetComponent <LoaderController>().GetNumberOfWeights();

            genAlg.InitaliseGenAlg(noOfLoaders);

            population = genAlg.GetChromos();

            for (int i = 0; i < noOfLoaders; i++)
            {
                List <float> weights = population[i].GetWeights();
                loaders[i].GetComponent <LoaderController>().InstantiateID(i);
                loaders[i].GetComponent <NeuralNetwork>().PutWeights(ref weights);
            }
        }

        UpdateGenerationText();
    }
Пример #3
0
        public Chromosome(Chromosome father, Chromosome mother, int porcentajeGenesMutar)
        {
            //foreach color, take pixel from father and from mother, add them, and then divide by 2

            Bitmap temp = new Bitmap(father.bm.Width, father.bm.Height);
            Random rand = new Random();

            for (int i = 0; i < temp.Width; i++)
            {
                for (int j = 0; j < temp.Height; j++)
                {
                    if (rand.Next(100) <= porcentajeGenesMutar)
                    {
                        temp.SetPixel(i, j, GenAlg.GenerateRandomColor());
                    }
                    else
                    {
                        Color fatherColor = father.bm.GetPixel(i, j), motherColor = mother.bm.GetPixel(i, j);
                        int   r = (fatherColor.R + motherColor.R) / 2;
                        int   g = (fatherColor.G + motherColor.G) / 2;
                        int   b = (fatherColor.B + motherColor.B) / 2;
                        temp.SetPixel(i, j, Color.FromArgb(r, g, b));

                        /*int r = (int) Math.Sqrt(fatherColor.R * motherColor.R) ;
                        *  int g = (int) Math.Sqrt(fatherColor.G * motherColor.G) ;
                        *  int b = (int) Math.Sqrt(fatherColor.B * motherColor.B) ;*/
                        /*if (rand.Next(2)==0)
                         *  temp.SetPixel(i, j, fatherColor);
                         * else
                         *  temp.SetPixel(i, j, motherColor);*/
                    }
                }
            }

            bm = temp;
        }