public static TyStateWeights GetMutatedWeights(TyStateWeights lhs, System.Random random, float deviation)
        {
            var weights = new TyStateWeights();

            for (int i = 0; i < (int)TyStateWeights.WeightType.Count; i++)
            {
                var   factorType = (TyStateWeights.WeightType)i;
                float factor     = lhs.GetWeight(factorType) + random.RandFloat(-0.5f * deviation, 0.5f * deviation);
                weights.SetWeight(factorType, factor);
            }

            return(weights);
        }
        /// <summary>
        /// Chooses weighted (by fitness) random weights from either A or B
        /// </summary>
        public static TyStateWeights GetCrossedWeights(TyWeightsLearner lhs, TyWeightsLearner rhs, System.Random rand)
        {
            TyStateWeights newWeights = new TyStateWeights();

            for (int i = 0; i < (int)TyStateWeights.WeightType.Count; i++)
            {
                var   factorType = (TyStateWeights.WeightType)i;
                float weight     = rhs._weights.GetWeight(factorType);

                float chanceLhs = lhs.Fitness / (lhs.Fitness + rhs.Fitness);

                if (rand.RandFloat() < chanceLhs)
                {
                    weight = lhs._weights.GetWeight(factorType);
                }

                newWeights.SetWeight(factorType, weight);
            }

            return(newWeights);
        }
 public TyWeightsLearner(TyStateWeights p, int generation, int id)
 {
     _id             = id;
     _weights        = p;
     _generationBorn = generation;
 }