Ejemplo n.º 1
0
        protected Chromosome(Chromosome c1, Chromosome c2)
        {
            Debug.Assert(c1.Count == c2.Count);

            if (1 == Randomizer.GetRandomIndex(2))
            {
                var temp = c1;
                c1 = c2;
                c2 = temp;
            }

            _weight = new double[c2.Count];

            int crossOverIndex = Randomizer.GetRandomIndex(c2.Count);

            for (int i = 0; i < _weight.Count(); ++i)
            {
                _weight[i] = i < crossOverIndex ? c1[i] : c2[i];
            }

            const double mutationRate = 0.1;

            for (int i = 0; i < _weight.Count(); ++i)
            {
                if (Randomizer.GetRandomProbability() <= mutationRate)
                    _weight[i] = Randomizer.GetRandomWeight();
            }
        }
Ejemplo n.º 2
0
        private static int CompareChromosomes(Chromosome c1, Chromosome c2)
        {
            const double minSelectionrate = 0.25;

            if (c1.SelectionRate < minSelectionrate && c2.SelectionRate > minSelectionrate)
                return 1;

            if (c2.SelectionRate < minSelectionrate && c1.SelectionRate > minSelectionrate)
                return -1;

            if (c1.ROI == c2.ROI)
                return 0;
            else if (c1.ROI > c2.ROI)
                return -1;
            else
                return 1;
        }
Ejemplo n.º 3
0
 internal static Chromosome Clone(Chromosome c1, Chromosome c2)
 {
     return c1.Count == c2.Count ? new Chromosome(c1, c2) : null;
 }
Ejemplo n.º 4
0
        private void TrainChromosome(IEnumerable<List<StarterInfo>> races, Chromosome chromosome, int currentIndex)
        {
            _nn.AssignSynapticWeightsFromChromosome(chromosome);

            double totalAmountBet = 0.0;
            double totalAmountWon = 0.0;

            int numberOfBets = 0;
            int numberOfRaces = 0;

            foreach (var race in races)
            {
                ++numberOfRaces;

                var selectedStarter = _nn.GetWinningNeuron(race).StarterInfo;

                if (null == selectedStarter)
                {
                    // the dummy neuron was selected which means there is no bet at all
                    continue;
                }

                if(selectedStarter != ((OutputNeuron)_nn.OutputLayer[2]).StarterInfo)
                {
                    continue;
                }

                totalAmountBet += 2.0;
                ++numberOfBets;
                if(selectedStarter.FinishPosition == 1)
                {
                    totalAmountWon += (selectedStarter.Odds + 1) * 2;
                }
            }

            double roi = totalAmountBet > 1.0 ? totalAmountWon / totalAmountBet : 0.0;

            double selectionRate = numberOfRaces > 1 ? (double) numberOfBets/numberOfRaces : 0;

            chromosome.ROI = roi;
            chromosome.SelectionRate = selectionRate;

            PrintMessage(string.Format("currentIndex = {0} {1} ", currentIndex, chromosome));
        }
Ejemplo n.º 5
0
        public void AssignSynapticWeightsFromChromosome(Chromosome chromosome)
        {
            Debug.Assert(chromosome.Count == NumberOfSynapses);

            var synapses = Synapses;

            for(int i = 0; i < chromosome.Count; ++i)
            {
                synapses[i].Weight = chromosome[i];
            }
        }