Exemple #1
0
 public Simulator(MinCogPhenotype phenotype)
 {
     InitializeComponent();
     _random = new Random();
     sim = new MinCogSimulator(phenotype);
     foreach (var h in phenotype.HiddenNodes)
     {
         System.Diagnostics.Debug.WriteLine("Hidden");
         System.Diagnostics.Debug.WriteLine("g:" + h.Gain);
         System.Diagnostics.Debug.WriteLine("t:" + h.TimeConstant);
         foreach (var v in h.UpstreamConnections)
         {
             System.Diagnostics.Debug.WriteLine(v.left.Name + " : " + v.right);
         }
     }
     foreach (var h in phenotype.OutputNodes)
     {
         System.Diagnostics.Debug.WriteLine("Output");
         System.Diagnostics.Debug.WriteLine("g:" + h.Gain);
         System.Diagnostics.Debug.WriteLine("t:" + h.TimeConstant);
         foreach (var v in h.UpstreamConnections)
         {
             System.Diagnostics.Debug.WriteLine(v.left.Name + " : " + v.right);
         }
     }
     testNet(phenotype);
 }
Exemple #2
0
        public MinCogAgent(MinCogPhenotype pheno)
        {
            Pheno = pheno;
            foreach (Node hiddenNode in pheno.HiddenNodes)
            {
                hiddenNode.InternalState = 0;
                hiddenNode.Output = 0;
            }

            foreach (Node motorNode in pheno.OutputNodes)
            {
                motorNode.InternalState = 0;
                motorNode.Output = 0;
            }
            Debug.Assert(pheno.HiddenNodes[0].InternalState == 0);
            CurrentPosition = 0;
        }
Exemple #3
0
 public MinCogSimulator(MinCogPhenotype phenotype)
 {
     GoodHits = 0;
     BadHits = 0;
     Avoid = 0;
     Big = 0;
     Round = 0;
     Agent = new MinCogAgent(phenotype);
     CurrentBlockSize = 0;
     for (int i = 0; i < Board.GetLength(0); i++)
     {
         for (int j = 0; j < Board.GetLength(1); j++)
         {
             Board[i, j] = 0;
         }
     }
     _random = new Random();
 }
Exemple #4
0
        public override AbstractPhenotype Translate(BitVector genom)
        {
            Network network = new Network();
            network.createGraph();
            int index = 0;

            foreach (Node hiddenNode in network.HiddenNodes)
            {
                foreach (var neighbour in hiddenNode.UpstreamConnections)
                {
                    if (neighbour.left == network.BiasNode)
                        neighbour.right = binaryToDoubleRange(genom.GetRange(index++*8, 8), -10.0, 0.0);
                    else
                        neighbour.right = binaryToDoubleRange(genom.GetRange(index++*8, 8), -5.0, 5.0);
                }
                hiddenNode.Gain = binaryToDoubleRange(genom.GetRange(index++*8, 8), 1.0, 5.0);
                hiddenNode.TimeConstant = binaryToDoubleRange(genom.GetRange(index++*8, 8), 1.0, 2.0);
            }
            foreach (Node outputNode in network.OutputNodes)
            {
                foreach (var neighbour in outputNode.UpstreamConnections)
                {
                    if (neighbour.left == network.BiasNode)
                        neighbour.right = binaryToDoubleRange(genom.GetRange(index++*8, 8), -10.0, 0.0);
                    else
                        neighbour.right = binaryToDoubleRange(genom.GetRange(index++*8, 8), -5.0, 5.0);
                }
                outputNode.Gain = binaryToDoubleRange(genom.GetRange(index++*8, 8), 1.0, 5.0);
                outputNode.TimeConstant = binaryToDoubleRange(genom.GetRange(index++*8, 8), 1.0, 2.0);
            }

            MinCogPhenotype pheno = new MinCogPhenotype(network.InputNodes, network.HiddenNodes, network.OutputNodes, network.BiasNode)
            {
                Genotype = genom,
                Fitness = 0.0,
                RouletteProportion = 0.0
            };
            return pheno;
        }
Exemple #5
0
        public override void EvolutionLoop()
        {
            for (int i = 0; i < Generations; i++)
            {

                Evolve();
                System.Diagnostics.Debug.WriteLine("Generation:" + i);
                System.Diagnostics.Debug.WriteLine("High:" + High);
                System.Diagnostics.Debug.WriteLine("AVG:" + Average);
                System.Diagnostics.Debug.WriteLine("SD:" + SD);
                System.Diagnostics.Debug.WriteLine("Best:" + BestOfRun.Fitness);
                if (TheOneAndOnly == null)
                {
                    TheOneAndOnly = BestOfRun;
                }

                if (BestOfRun.Fitness > TheOneAndOnly.Fitness)
                {
                    TheOneAndOnly = BestOfRun;
                }
            }
        }
Exemple #6
0
        public void testNet(MinCogPhenotype pheno)
        {
            MinCogAgent agent = new MinCogAgent(pheno);
            List<bool[]> testInputs = new List<bool[]>();
            bool[] input = new bool[5];
            input[0] = true;
            input[1] = true;
            input[2] = true;
            input[3] = true;
            input[4] = true;
            testInputs.Add(input);

            bool[] input2 = new bool[5];
            input[0] = false;
            input[1] = false;
            input[2] = false;
            input[3] = false;
            input[4] = false;
            testInputs.Add(input2);

            bool[] input3 = new bool[5];
            input[0] = true;
            input[1] = true;
            input[2] = false;
            input[3] = false;
            input[4] = false;
            testInputs.Add(input3);

            bool[] input4 = new bool[5];
            input[0] = false;
            input[1] = true;
            input[2] = true;
            input[3] = false;
            input[4] = false;
            testInputs.Add(input4);

            bool[] input5 = new bool[5];
            input[0] = false;
            input[1] = false;
            input[2] = false;
            input[3] = true;
            input[4] = true;
            testInputs.Add(input5);

            bool[] input6 = new bool[5];
            input[0] = false;
            input[1] = false;
            input[2] = true;
            input[3] = true;
            input[4] = true;
            testInputs.Add(input6);

            bool[] input7 = new bool[5];
            input[0] = false;
            input[1] = true;
            input[2] = true;
            input[3] = true;
            input[4] = true;
            testInputs.Add(input7);

            bool[] input8 = new bool[5];
            input[0] = true;
            input[1] = true;
            input[2] = true;
            input[3] = true;
            input[4] = false;
            testInputs.Add(input8);
            Debug.WriteLine("--------------------- Test -----------------------");
            foreach (bool[] it in testInputs)
            {
                Debug.Write("--------------- Next input --------------------");
                agent.SetNewPosition(input);
            }
        }