// Get dictionary of inputs and the error they produce
public Dictionary <AST.Address, Tuple <string, double> > TopOfKErrors(AST.Address[] terminal_formula_nodes, CellDict inputs, int k, CellDict correct_outputs, Excel.Application app, Excel.Workbook wb, string classification_file, DAG dag)
{
var eg = new ErrorGenerator();
var c = Classification.Deserialize(classification_file);
var max_error_produced_dictionary = new Dictionary <AST.Address, Tuple <string, double> >();
foreach (KeyValuePair <AST.Address, string> pair in inputs)
{
AST.Address addr = pair.Key;
string orig_value = pair.Value;
//Load in the classification's dictionaries
double max_error_produced = 0.0;
string max_error_string = "";
// get k strings, in parallel
string[] errorstrings = eg.GenerateErrorStrings(orig_value, c, k);
for (int i = 0; i < k; i++)
{
CellDict cd = new CellDict();
cd.Add(addr, errorstrings[i]);
//inject the typo
Utility.InjectValues(app, wb, cd);
// save function outputs
CellDict incorrect_outputs = Utility.SaveOutputs(terminal_formula_nodes, dag);
//remove the typo that was introduced
cd.Clear();
cd.Add(addr, orig_value);
Utility.InjectValues(app, wb, cd);
double total_error = Utility.CalculateTotalError(correct_outputs, incorrect_outputs);
//keep track of the largest observed max error
if (total_error > max_error_produced)
{
max_error_produced = total_error;
max_error_string = errorstrings[i];
}
}
//Add entry for this TreeNode in our dictionary with its max_error_produced
max_error_produced_dictionary.Add(addr, new Tuple <string, double>(max_error_string, max_error_produced));
}
return(max_error_produced_dictionary);
}