/// <summary>
        /// Create an initial random population.
        /// </summary>
        public void Reset()
        {
            // create the genome factory
            if (IsHyperNEAT)
            {
                CODEC         = new HyperNEATCODEC();
                GenomeFactory = new FactorHyperNEATGenome();
            }
            else
            {
                CODEC         = new NEATCODEC();
                GenomeFactory = new FactorNEATGenome();
            }

            // create the new genomes
            Species.Clear();

            // reset counters
            GeneIdGenerate.CurrentID       = 1;
            InnovationIDGenerate.CurrentID = 1;

            EncogRandom rnd = RandomNumberFactory.Factor();

            // create one default species
            BasicSpecies defaultSpecies = new BasicSpecies();

            defaultSpecies.Population = this;

            // create the initial population
            for (int i = 0; i < PopulationSize; i++)
            {
                NEATGenome genome = GenomeFactory.Factor(rnd, this,
                                                         InputCount, OutputCount,
                                                         InitialConnectionDensity);
                defaultSpecies.Add(genome);
            }
            defaultSpecies.Leader = defaultSpecies.Members[0];
            Species.Add(defaultSpecies);

            // create initial innovations
            Innovations = new NEATInnovationList(this);
        }
        /// <summary>
        /// Create an initial random population.
        /// </summary>
        public void Reset()
        {
            // create the genome factory
            if (IsHyperNEAT)
            {
                CODEC = new HyperNEATCODEC();
                GenomeFactory = new FactorHyperNEATGenome();
            }
            else
            {
                CODEC = new NEATCODEC();
                GenomeFactory = new FactorNEATGenome();
            }

            // create the new genomes
            Species.Clear();

            // reset counters
            GeneIdGenerate.CurrentID = 1;
            InnovationIDGenerate.CurrentID = 1;

            EncogRandom rnd = RandomNumberFactory.Factor();

            // create one default species
            BasicSpecies defaultSpecies = new BasicSpecies();
            defaultSpecies.Population = this;

            // create the initial population
            for (int i = 0; i < PopulationSize; i++)
            {
                NEATGenome genome = GenomeFactory.Factor(rnd, this ,
                        InputCount, OutputCount,
                        InitialConnectionDensity);
                defaultSpecies.Add(genome);
            }
            defaultSpecies.Leader = defaultSpecies.Members[0];
            Species.Add(defaultSpecies);

            // create initial innovations
            Innovations = new NEATInnovationList(this);
        }
        /// <inheritdoc/>
        public IMLMethod Decode(NEATPopulation pop, Substrate.Substrate substrate,
                IGenome genome)
        {
            // obtain the CPPN
            NEATCODEC neatCodec = new NEATCODEC();
            NEATNetwork cppn = (NEATNetwork)neatCodec.Decode(genome);

            List<NEATLink> linkList = new List<NEATLink>();

            IActivationFunction[] afs = new IActivationFunction[substrate.NodeCount];

            IActivationFunction af = new ActivationSteepenedSigmoid();
            // all activation functions are the same
            for (int i = 0; i < afs.Length; i++)
            {
                afs[i] = af;
            }

            double c = this.MaxWeight / (1.0 - this.MinWeight);
            BasicMLData input = new BasicMLData(cppn.InputCount);

            // First create all of the non-bias links.
            foreach (SubstrateLink link in substrate.Links)
            {
                SubstrateNode source = link.Source;
                SubstrateNode target = link.Target;

                int index = 0;
                foreach (double d in source.Location)
                {
                    input.Data[index++] = d;
                }
                foreach (double d in target.Location)
                {
                    input.Data[index++] = d;
                }
                IMLData output = cppn.Compute(input);

                double weight = output[0];
                if (Math.Abs(weight) > this.MinWeight)
                {
                    weight = (Math.Abs(weight) - this.MinWeight) * c
                            * Math.Sign(weight);
                    linkList.Add(new NEATLink(source.ID, target.ID,
                            weight));
                }
            }

            // now create biased links
            input.Clear();
            int d2 = substrate.Dimensions;
            IList<SubstrateNode> biasedNodes = substrate.GetBiasedNodes();
            foreach (SubstrateNode target in biasedNodes)
            {
                for (int i = 0; i < d2; i++)
                {
                    input.Data[d2 + i] = target.Location[i];
                }

                IMLData output = cppn.Compute(input);

                double biasWeight = output[1];
                if (Math.Abs(biasWeight) > this.MinWeight)
                {
                    biasWeight = (Math.Abs(biasWeight) - this.MinWeight) * c
                            * Math.Sign(biasWeight);
                    linkList.Add(new NEATLink(0, target.ID, biasWeight));
                }
            }

            // check for invalid neural network
            if (linkList.Count == 0)
            {
                return null;
            }

            linkList.Sort();

            NEATNetwork network = new NEATNetwork(substrate.InputCount,
                    substrate.OutputCount, linkList, afs);

            network.ActivationCycles = substrate.ActivationCycles;
            return network;
        }