private static void AddSpielNominee(List <DataLine> data) { List <DataLine> nominees = DataLine.ParseInferred(CSVParser.ReadDataFile("spiel_des_jahres.csv", ";", null)); foreach (DataLine game in data) { bool isNom = nominees.Any(n => n.hashDoubles["game_id"].Equals(game.hashDoubles["id"])); game.hashBooleans["spiel_nominee"] = isNom; } }
public static void BackPropagation(List <DataLine> historicalData) { // Normalization of historical data DataLine[][] years = NormalizeHistorical(historicalData); List <DataLine> spiel = DataLine.ParseInferred(CSVParser.ReadDataFile("spiel_des_jahres.csv", ";", null)); //int[] nominees = new[] { 98778, 131260, 137297, 107529, 117959, 90009, 25669, 65244, 72991, 39856, 66188, 37380, 217, 22348, 36218, 35497, 40628, 40393, 30549, 34585, 34227, 34635, 29223, 34084, 27588, 22278, 25643, 13883, 22345, 21790, 20080, 21882, 17534, 22287 }; Console.WriteLine(years[0][0]); // Training of NN var trainingset = years[1].Union(years[2]).Union(years[3]).Union(years[4]).Union(years[5]); NeuralNetwork nn = new NeuralNetwork(30, 1, 5, 1); DataLine[] years0 = CreateOversampling(trainingset.ToArray(), spiel).ToList().Shuffle(1337).ToArray(); double[] year0nominees = years0.Select(g => IsGameNominee(g, spiel) ? 1.0 : 0.0).ToArray(); Console.WriteLine(string.Join(",", year0nominees)); TrainNetwork(nn, years0, year0nominees); // Verification int true_positive = 0; int false_positive = 0; int true_negative = 0; int false_negative = 0; foreach (DataLine g in years[0]) { double[] input = PrepareInput(g); bool result = nn.CalculateOutput(input)[0] > 0.5; bool reality = IsGameNominee(g, spiel); if (result && reality) { true_positive++; } else if (result && !reality) { false_positive++; } else if (!result && !reality) { true_negative++; } else { false_negative++; } } Console.WriteLine("\nTP: {0}\nFP: {1}\nTN: {2}\nFN: {3}", true_positive, false_positive, true_negative, false_negative); }