private static double CalculateHeuristicValue(Dictionary <CharacterFrequencyAnalyzer.Category, double> a, List <double> n) { return(a.Zip(CharacterFrequencyAnalyzer.CalculateRelativeAggregateFrequency(n), (b, c) => { return (Math.Pow((b.Value - c.Value), 2)); }).Sum()); }
public List <HeuristicTuple> Classify(IEnumerable <string> input) { // Check if there are available training values to use for classifcation, otherwise throw InvalidOperationException. if (new List <List <List <double> > >() { qtyClassifierValues, designatorClassifierValues, descriptionClassifierValues, mfgClassifierValues, mpnClassifierValues }.All(list => list.Count == 0)) { throw new InvalidOperationException("No training data has been loaded to allow for classification to occur"); } Dictionary <CharacterFrequencyAnalyzer.Category, double> classifyingInput = CharacterFrequencyAnalyzer.CalculateRelativeAggregateFrequency(input); List <HeuristicTuple> calculatedDeltas = new List <HeuristicTuple>(); try { foreach (List <double> trainingData in qtyClassifierValues) { calculatedDeltas.Add(new HeuristicTuple(ColumnType.Quantity, CalculateHeuristicValue(classifyingInput, trainingData))); } foreach (List <double> trainingData in designatorClassifierValues) { calculatedDeltas.Add(new HeuristicTuple(ColumnType.Designator, CalculateHeuristicValue(classifyingInput, trainingData))); } foreach (List <double> trainingData in descriptionClassifierValues) { calculatedDeltas.Add(new HeuristicTuple(ColumnType.Description, CalculateHeuristicValue(classifyingInput, trainingData))); } foreach (List <double> trainingData in mfgClassifierValues) { calculatedDeltas.Add(new HeuristicTuple(ColumnType.Manufacturer, CalculateHeuristicValue(classifyingInput, trainingData))); } foreach (List <double> trainingData in mpnClassifierValues) { calculatedDeltas.Add(new HeuristicTuple(ColumnType.PartNumber, CalculateHeuristicValue(classifyingInput, trainingData))); } calculatedDeltas.Sort(); } catch { throw; } return(calculatedDeltas); }