GetTopPunchedCardsPerLabel( IDictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsPerKeyPerLabel, int topPunchedCardsPerKeyPerLabelCount) { var topPunchedCardsPerKeyPerLabel = new Dictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > >(); for (byte i = 0; i < DataHelper.LabelsCount; i++) { var label = DataHelper.GetLabelBitVector(i, BitVectorFactory); var topPunchedCardsPerSpecificLabel = punchedCardsPerKeyPerLabel .OrderByDescending(punchedCardPerLabel => RecognitionHelper.CalculateBitVectorsScore(punchedCardPerLabel.Value[label])) .Take(topPunchedCardsPerKeyPerLabelCount); foreach (var topPunchedCardPerSpecificLabel in topPunchedCardsPerSpecificLabel) { if (!topPunchedCardsPerKeyPerLabel.TryGetValue(topPunchedCardPerSpecificLabel.Key, out var dictionary)) { dictionary = new Dictionary <IBitVector, IReadOnlyCollection <IBitVector> >(); topPunchedCardsPerKeyPerLabel.Add(topPunchedCardPerSpecificLabel.Key, dictionary); } dictionary.Add(label, topPunchedCardPerSpecificLabel.Value[label]); } } return(topPunchedCardsPerKeyPerLabel); }
private static IDictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > GetGlobalTopPunchedCard( IDictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsPerKeyPerLabel) { var globalTopPunchedCard = punchedCardsPerKeyPerLabel .OrderByDescending(punchedCardPerKeyPerLabel => punchedCardPerKeyPerLabel.Value .AsParallel() .Sum(labelAndInputs => RecognitionHelper.CalculateBitVectorsScore(labelAndInputs.Value))) .First(); return(new Dictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > { { globalTopPunchedCard.Key, globalTopPunchedCard.Value } }); }