void ValidationTests(String cardsJson, String combosFile, int k) { HSCardsParser parser = new HSCardsParser(cardsJson); HoningStoneBuilder builder = new HoningStoneBuilder(); Dictionary <String, CardObject> cardTable = new Dictionary <string, CardObject>(); HSCardOperator op = new HSCardOperator(); HSCardsParser fullParser = new HSCardsParser("allCardsWithAbility.json", 0); Dictionary <String, int> dataID; Dictionary <String, double[]> cardDatasetFull = op.generateCardVectors(fullParser, out dataID); // Populate all card table foreach (string key in parser.objects.Keys) { List <CardObject> cards_objects = parser.objects[key]; builder.GenCardTableObject(ref cards_objects, ref cardTable); } HSCombosParser combosParser = new HSCombosParser(); //combosParser.PopulateFromHoningNetwork(ref decksParser, ref cardTable, 5); combosParser.PopulateFromJson(combosFile); Random rand = new Random(); List <CardObject> neutral = parser.objects["Neutral"]; String currentDirectory = "results"; bool exists = System.IO.Directory.Exists(currentDirectory); if (!exists) { System.IO.Directory.CreateDirectory(currentDirectory); } // boxplot files System.IO.StreamWriter Fitness = new System.IO.StreamWriter(currentDirectory + "//fit.txt"); System.IO.StreamWriter Efficiency = new System.IO.StreamWriter(currentDirectory + "//eff.txt"); System.IO.StreamWriter Surprise = new System.IO.StreamWriter(currentDirectory + "//sur.txt"); System.IO.StreamWriter Creativity = new System.IO.StreamWriter(currentDirectory + "//crea.txt"); System.IO.StreamWriter fileNormEfficiency = new System.IO.StreamWriter(currentDirectory + "//norm_eff.txt"); System.IO.StreamWriter fileNormSurprise = new System.IO.StreamWriter(currentDirectory + "//norm_sur.txt"); System.IO.StreamWriter fileNormCreativity = new System.IO.StreamWriter(currentDirectory + "//norm_crea.txt"); Fitness.WriteLine("Hero Algorithm Value"); Efficiency.WriteLine("Hero Algorithm Value"); Surprise.WriteLine("Hero Algorithm Value"); Creativity.WriteLine("Hero Algorithm Value"); fileNormEfficiency.WriteLine("Hero Algorithm Value"); fileNormSurprise.WriteLine("Hero Algorithm Value"); fileNormCreativity.WriteLine("Hero Algorithm Value"); foreach (String hero in parser.objects.Keys) { if (hero == "Neutral") { continue; } List <String> honingCombo; HoningNetwork <String> net = new HoningNetwork <string>(); List <CardObject> heroCards = parser.objects[hero]; builder.PopulateFromCardData(ref net, ref heroCards); builder.BuildThirdLevel(ref net, ref heroCards); builder.PopulateFromCardData(ref net, ref neutral); builder.BuildThirdLevel(ref net, ref neutral); HSHoningBayes fixedBayes = new HSHoningBayes(hero.ToLower(), ref combosParser, ref net, ref cardDatasetFull, ref cardTable, 100000); fixedBayes.SaveKNNDataset(hero + "_data.dataset"); Dataset fixedDataset = new Dataset(hero + "_data.dataset", ','); KNNEfficiency fixedKNN = new KNNEfficiency(fixedDataset); Dictionary <String, HoningNode <String> > dic = net.getNetwork(); Dictionary <String, String> selfAbilityFilter = op.GenerateAbilityFilter(); Dictionary <String, String> TerminalsDic = op.GetComboPotential(ref dic, ref cardTable, ref selfAbilityFilter, 10); List <String> Terminals = TerminalsDic.Keys.ToList(); // Tests i, ii, iii, iv, v control variables int mana = 10; double surprise; double efficiency; double fitness; double creativity; double normCreativity; double normSurprise; double normEfficiency; List <String> combo = new List <string>(); double highSurp = 0.0; double minSurp = double.MaxValue; double highEff = 0.0; double minEff = double.MaxValue; // Tests i, ii, iii, iv, v control variables String seed = ""; Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("- Loading calibrated surprise! -"); string[] lines = System.IO.File.ReadAllLines(hero + "_calibration.cal"); char[] delim = new char[1]; delim[0] = ' '; String highSurprise = lines[0].Split(delim).Last(); String minSurprise = lines[1].Split(delim).Last(); String highEfficiency = lines[2].Split(delim).Last(); String minEfficiency = lines[3].Split(delim).Last(); double.TryParse(highSurprise, out highSurp); double.TryParse(minSurprise, out minSurp); double.TryParse(highEfficiency, out highEff); double.TryParse(minEfficiency, out minEff); int seedCount = 1; int totalTestsPerSeed = 10; // Foreach percentage for (int percentage = 20; percentage <= 100; percentage += 20) { // To write results System.IO.StreamWriter resultFile = new System.IO.StreamWriter(currentDirectory + "//" + hero + "_results_II_" + percentage + ".dat"); // To calculate statistics List <result> listres = new List <result>(); foreach (String c in Terminals) { //String c = Terminals.First(); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("Hero: " + hero); Console.WriteLine("Seed: " + c); Console.WriteLine("Seed " + seedCount + " of " + Terminals.Count); Console.WriteLine(); // Test all reacheable seeds seed = c; for (int i = 0; i < totalTestsPerSeed; i++) { // (iii)honing novo (E+S) honingCombo = op.GenerateCardCluster( c, ref cardTable, ref net, ref selfAbilityFilter, ref fixedBayes, ref fixedKNN, ref cardDatasetFull, mana, k, percentage, false, ref highSurp, ref minSurp, ref highEff, ref minEff, out fitness, out surprise, out efficiency, out normSurprise, out normEfficiency).Keys.ToList(); creativity = surprise + efficiency; normCreativity = normSurprise + normEfficiency; result res = new result(honingCombo, fitness, creativity, normCreativity, surprise, normSurprise, efficiency, normEfficiency, highSurp, minSurp, highEff, minEff); listres.Add(res); } seedCount++; } // Renormalize and recalibrate limits List <result> renormalizedResults = renormalizeSimple(listres, ref highSurp, ref minSurp, ref minEff, ref highEff); // Write to file foreach (result r in renormalizedResults) { r.writeIntoFile(resultFile); } //extractViableSeeds(op, hero, 0, 1, meanFitness, meanEfficiency, meanSurprise, meanCreativity); writeForBoxPlot(hero, renormalizedResults, "II" + percentage, Fitness, Efficiency, Surprise, Creativity, fileNormEfficiency, fileNormSurprise, fileNormCreativity); resultFile.Close(); } // end statistics } // end hero // boxplot closing Fitness.Close(); Efficiency.Close(); Surprise.Close(); Creativity.Close(); fileNormCreativity.Close(); fileNormEfficiency.Close(); fileNormSurprise.Close(); }
public void calculateStatistics(List <result> input, out result sum, out result mean, out result variance, out result deviation, out result median, out result higher, out result lower) { List <result> op = new List <result>(); op.AddRange(input); sum = new result(); mean = new result(); variance = new result(); deviation = new result(); median = new result(); higher = new result(); lower = new result(); if (input.Count == 0) { return; } lower.creativity = double.MaxValue; lower.efficiency = double.MaxValue; lower.fitness = double.MaxValue; lower.surprise = double.MaxValue; lower.normCreativity = double.MaxValue; lower.normSurprise = double.MaxValue; lower.normEfficiency = double.MaxValue; foreach (result r in op) { if (r.creativity > higher.creativity) { higher.creativity = r.creativity; } if (r.efficiency > higher.efficiency) { higher.efficiency = r.efficiency; } if (r.fitness > higher.fitness) { higher.fitness = r.fitness; } if (r.surprise > higher.surprise) { higher.surprise = r.surprise; } if (r.normCreativity > higher.normCreativity) { higher.normCreativity = r.normCreativity; } if (r.normSurprise > higher.normSurprise) { higher.normSurprise = r.normSurprise; } if (r.normEfficiency > higher.normEfficiency) { higher.normEfficiency = r.normEfficiency; } if (r.creativity < lower.creativity) { lower.creativity = r.creativity; } if (r.efficiency < lower.efficiency) { lower.efficiency = r.efficiency; } if (r.fitness < lower.fitness) { lower.fitness = r.fitness; } if (r.surprise < lower.surprise) { lower.surprise = r.surprise; } if (r.normCreativity < lower.normCreativity) { lower.normCreativity = r.normCreativity; } if (r.normSurprise < lower.normSurprise) { lower.normSurprise = r.normSurprise; } if (r.normEfficiency < lower.normEfficiency) { lower.normEfficiency = r.normEfficiency; } sum.creativity += r.creativity; sum.efficiency += r.efficiency; sum.fitness += r.fitness; sum.surprise += r.surprise; sum.normCreativity += r.normCreativity; sum.normSurprise += r.normSurprise; sum.normEfficiency += r.normEfficiency; } mean.creativity = sum.creativity / op.Count; mean.efficiency = sum.efficiency / op.Count; mean.fitness = sum.fitness / op.Count; mean.surprise = sum.surprise / op.Count; mean.normCreativity = sum.normCreativity / op.Count; mean.normSurprise = sum.normSurprise / op.Count; mean.normEfficiency = sum.normEfficiency / op.Count; for (int i = 0; i < op.Count; i++) { variance.creativity += Math.Pow(op[i].creativity - mean.creativity, 2.0); variance.efficiency += Math.Pow(op[i].efficiency - mean.efficiency, 2.0); variance.surprise += Math.Pow(op[i].surprise - mean.surprise, 2.0); variance.fitness += Math.Pow(op[i].fitness - mean.fitness, 2.0); variance.normCreativity += Math.Pow(op[i].normCreativity - mean.normCreativity, 2.0); variance.normSurprise += Math.Pow(op[i].normSurprise - mean.normSurprise, 2.0); variance.normEfficiency += Math.Pow(op[i].normEfficiency - mean.normEfficiency, 2.0); } variance.creativity /= op.Count; variance.efficiency /= op.Count; variance.surprise /= op.Count; variance.fitness /= op.Count; variance.normCreativity /= op.Count; variance.normSurprise /= op.Count; variance.normEfficiency /= op.Count; deviation.creativity = Math.Sqrt(variance.creativity); deviation.efficiency = Math.Sqrt(variance.efficiency); deviation.fitness = Math.Sqrt(variance.fitness); deviation.surprise = Math.Sqrt(variance.surprise); deviation.normCreativity = Math.Sqrt(variance.normCreativity); deviation.normSurprise = Math.Sqrt(variance.normSurprise); deviation.normEfficiency = Math.Sqrt(variance.normEfficiency); int inputPos = 0; if (op.Count % 2 == 0) { inputPos = op.Count / 2; op.Sort(delegate(result A, result B) { return(A.creativity.CompareTo(B.creativity)); }); median.creativity = (op[inputPos].creativity + op[inputPos + 1].creativity) / 2; op.Sort(delegate(result A, result B) { return(A.efficiency.CompareTo(B.efficiency)); }); median.efficiency = (op[inputPos].efficiency + op[inputPos + 1].efficiency) / 2; op.Sort(delegate(result A, result B) { return(A.surprise.CompareTo(B.surprise)); }); median.surprise = (op[inputPos].surprise + op[inputPos + 1].surprise) / 2; op.Sort(delegate(result A, result B) { return(A.fitness.CompareTo(B.fitness)); }); median.fitness = (op[inputPos].fitness + op[inputPos + 1].fitness) / 2; op.Sort(delegate(result A, result B) { return(A.normCreativity.CompareTo(B.normCreativity)); }); median.normCreativity = (op[inputPos].normCreativity + op[inputPos + 1].normCreativity) / 2; op.Sort(delegate(result A, result B) { return(A.normSurprise.CompareTo(B.normSurprise)); }); median.normSurprise = (op[inputPos].normSurprise + op[inputPos + 1].normSurprise) / 2; op.Sort(delegate(result A, result B) { return(A.normEfficiency.CompareTo(B.normEfficiency)); }); median.normEfficiency = (op[inputPos].normEfficiency + op[inputPos + 1].normEfficiency) / 2; } else { inputPos = op.Count / 2; op.Sort(delegate(result A, result B) { return(A.creativity.CompareTo(B.creativity)); }); median.creativity = (op[inputPos].creativity); op.Sort(delegate(result A, result B) { return(A.efficiency.CompareTo(B.efficiency)); }); median.efficiency = (op[inputPos].efficiency); op.Sort(delegate(result A, result B) { return(A.surprise.CompareTo(B.surprise)); }); median.surprise = (op[inputPos].surprise); op.Sort(delegate(result A, result B) { return(A.fitness.CompareTo(B.fitness)); }); median.fitness = (op[inputPos].fitness); op.Sort(delegate(result A, result B) { return(A.normCreativity.CompareTo(B.normCreativity)); }); median.normCreativity = (op[inputPos].normCreativity); op.Sort(delegate(result A, result B) { return(A.normSurprise.CompareTo(B.normSurprise)); }); median.normSurprise = (op[inputPos].normSurprise); op.Sort(delegate(result A, result B) { return(A.normEfficiency.CompareTo(B.normEfficiency)); }); median.normEfficiency = (op[inputPos].normEfficiency); } }
void recalibrateResults(String file, out List <result> results, ref Double maxSurp, ref Double minSurp, ref Double maxEff, ref Double minEff, double threshold) { string[] lines = System.IO.File.ReadAllLines(file); results = new List <result>(); // 0 -- 18 lista de objetos int lineCount = lines.Length; int resultCount = 66; int step = 15; int currentLine = 0; int linerCount = 0; while (currentLine <= lineCount - resultCount) { result res = new result(); char[] delim = new char[1]; delim[0] = ' '; String Fitness = lines[currentLine + 0].Split(delim).Last(); String RawCreativity = lines[currentLine + 1].Split(delim).Last(); String NormCreativity = lines[currentLine + 2].Split(delim).Last(); String Surprise = lines[currentLine + 3].Split(delim).Last(); String NormSurprise = lines[currentLine + 4].Split(delim).Last(); String Efficiency = lines[currentLine + 5].Split(delim).Last(); String NormEfficiency = lines[currentLine + 6].Split(delim).Last(); String highSurprise = lines[currentLine + 7].Split(delim).Last(); String minSurprise = lines[currentLine + 8].Split(delim).Last(); String highEfficiency = lines[currentLine + 9].Split(delim).Last(); String minEfficiency = lines[currentLine + 10].Split(delim).Last(); delim[0] = ')'; String[] cards = lines[currentLine + 14].Split(delim); double creativity, surprise, efficiency, fitness; double.TryParse(Fitness, out fitness); double.TryParse(RawCreativity, out creativity); double.TryParse(Surprise, out surprise); double.TryParse(Efficiency, out efficiency); if (surprise > maxSurp) { maxSurp = surprise; } if (surprise < minSurp) { minSurp = surprise; } if (efficiency > maxEff) { maxEff = efficiency; } if (efficiency < minEff) { minEff = efficiency; } foreach (string s in cards) { String rawCard = s.Replace("(", ""); rawCard = rawCard.Replace(" ", ""); //rawCard = rawCard.Replace(")", ""); if (rawCard == "") { continue; } res.cards.Add(rawCard); } res.creativity = creativity; res.surprise = surprise; res.efficiency = efficiency; if (fitness > threshold) { results.Add(res); } currentLine += step; linerCount += step; } }