public List <string> GetProbabilitiesAllTrees() { if (probabilities.Count == 0) { foreach (string countryName in countries.Keys) { string simulationLine = countryName + ";"; if (!treesByCountry.ContainsKey(countryName)) { List <Record> records = RecordsByCountry(countryName); List <Dictionary <string, object> > setToTraining = new List <Dictionary <string, object> >(); for (int i = 0; i < records.Count; i++) { setToTraining.Add(records[i].getData()); } Dictionary <string, int> variables = new Dictionary <string, int>(); variables.Add("Year", 0); variables.Add("Sex", 1); variables.Add("Generation", 1); Tree myTree = new Tree(variables, "Risk"); myTree.training(setToTraining); treesByCountry.Add(countryName, myTree); } simulationLine += Math.Round((treesByCountry[countryName].Error()), 4) + ";"; if (!treesByCountryWithAccord.ContainsKey(countryName)) { DataTable data = RecordsInDataTable(countryName); AccordAdapter newAccordAdapter = new AccordAdapter(countryName, data); newAccordAdapter.Learn(); treesByCountryWithAccord.Add(countryName, newAccordAdapter); } simulationLine += Math.Round((treesByCountryWithAccord[countryName].Error()), 4); probabilities.Add(simulationLine); } } return(probabilities); }
public string simulateSuicideRisk_AccordImplementation(string countryName, int year, string generation, string sex) { if (!treesByCountryWithAccord.ContainsKey(countryName)) { DataTable data = RecordsInDataTable(countryName); AccordAdapter newAccordAdapter = new AccordAdapter(countryName, data); newAccordAdapter.Learn(); treesByCountryWithAccord.Add(countryName, newAccordAdapter); } string answer = "Simulation with external library\n"; answer += treesByCountryWithAccord[countryName].simulate(year, generation, sex); answer += "\n Simulation error: " + Math.Round((treesByCountryWithAccord[countryName].Error() * 100), 4) + "%"; return(answer); }