Ejemplo n.º 1
0
        public void Analyze(string path)
        {
            StartTime = DateTime.Now;
            Log("Analyze start.");

            List <Profile> profiles = LoadProfiles(path);

            profiles = new List <Profile>(profiles.OrderByDescending(profile => profile.EloRating));

            string resultFile = Path.Combine(path, "analyze.csv");

            using (StreamWriter sw = new StreamWriter(resultFile))
            {
                // Header
                StringBuilder headerSB = new StringBuilder();

                headerSB.Append("Id,Name,EloRating,Generation,ParentA,ParentB,Wins,Losses,Draws");

                MetricWeights.IterateOverWeights((bugType, bugTypeWeight) =>
                {
                    headerSB.AppendFormat(",Start{0}.{1}", bugType, bugTypeWeight);
                    headerSB.AppendFormat(",End{0}.{1}", bugType, bugTypeWeight);
                });

                sw.WriteLine(headerSB.ToString());

                foreach (Profile p in profiles)
                {
                    StringBuilder profileSB = new StringBuilder();

                    profileSB.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8}", p.Id, p.Name, p.EloRating, p.Generation, p.ParentA.HasValue ? p.ParentA.ToString() : "", p.ParentB.HasValue ? p.ParentB.ToString() : "", p.Wins, p.Losses, p.Draws);

                    MetricWeights startNormalized = p.StartMetricWeights.GetNormalized();
                    MetricWeights endNormalized   = p.EndMetricWeights.GetNormalized();

                    MetricWeights.IterateOverWeights((bugType, bugTypeWeight) =>
                    {
                        profileSB.AppendFormat(",{0:0.00}", startNormalized.Get(bugType, bugTypeWeight));
                        profileSB.AppendFormat(",{0:0.00}", endNormalized.Get(bugType, bugTypeWeight));
                    });

                    sw.WriteLine(profileSB.ToString());
                }
            }

            Log("Analyze end.");
        }
Ejemplo n.º 2
0
        private static MetricWeights MixMetricWeights(MetricWeights mwA, MetricWeights mwB, double minMix, double maxMix)
        {
            MetricWeights mw = new MetricWeights();

            MetricWeights.IterateOverWeights((bugType, bugTypeWeight) =>
            {
                double value = 0.5 * (mwA.Get(bugType, bugTypeWeight) + mwB.Get(bugType, bugTypeWeight));
                if (value == 0.0)
                {
                    value = -0.01 + (Random.NextDouble() * 0.02);
                }
                value = value * (minMix + (Random.NextDouble() * Math.Abs(maxMix - minMix)));
                mw.Set(bugType, bugTypeWeight, value);
            });

            return(mw);
        }