internal static IEnumerable <KeyValuePair <IBitVector, int> > CountCorrectRecognitions( IEnumerable <Tuple <IBitVector, IBitVector> > data, IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsCollection, IPuncher <string, IBitVector, IBitVector> puncher, IReadOnlyDictionary <string, IExpert> experts, IBitVectorFactory bitVectorFactory) { var counters = DataHelper.GetLabels(bitVectorFactory).ToDictionary(label => label, label => new int[1]); data .AsParallel() .ForAll(dataItem => { var lossPerLabelPerPunchedCard = CalculateLossPerLabelPerPunchedCard( punchedCardsCollection, dataItem.Item1, puncher, experts); var topLabel = lossPerLabelPerPunchedCard .MinBy(p => p.Value.Sum(keyScore => keyScore.Value)) .Key; if (topLabel.Equals(dataItem.Item2)) { Interlocked.Increment(ref counters[topLabel][0]); } }); return(counters.ToDictionary(p => p.Key, p => p.Value[0])); }
private static IBitVector GetValueBitVector(byte[,] imageData, IBitVectorFactory bitVectorFactory) { const byte height = 28; const byte width = 28; const int pixelRepresentationSizeInBits = 8; return(bitVectorFactory.Create( GetActiveBitIndices(imageData, height, width, pixelRepresentationSizeInBits), height * width * pixelRepresentationSizeInBits)); }
internal static IBitVector GetLabelBitVector(byte label, IBitVectorFactory bitVectorFactory) { return(bitVectorFactory.Create( GetActiveBitIndices(label).Where(i => i >= 4).Select(i => i - 4), 4)); }
private static IEnumerable <Tuple <IBitVector, IBitVector> > ReaData(Func <IEnumerable <Image> > readImagesFunction, IBitVectorFactory bitVectorFactory) { return(readImagesFunction() .Select(image => new Tuple <IBitVector, IBitVector>( GetValueBitVector(image.Data, bitVectorFactory), GetLabelBitVector(image.Label, bitVectorFactory)))); }
internal static IEnumerable <Tuple <IBitVector, IBitVector> > ReadTestData(IBitVectorFactory bitVectorFactory) { return(ReaData(FashionMnistReader.ReadTestData, bitVectorFactory)); }
internal RandomPuncher(int bitCount, IBitVectorFactory bitVectorFactory) { _bitCount = bitCount; _bitVectorFactory = bitVectorFactory; }
private static IBitVector GetLabelBitVector(byte label, IBitVectorFactory bitVectorFactory) { return(bitVectorFactory.Create( GetActiveBitIndices(label).Select(i => 7 - i), 4)); }
internal static IEnumerable <IBitVector> GetLabels(IBitVectorFactory bitVectorFactory) { return(Enumerable.Range(0, LabelCount).Select(labelIndex => GetLabelBitVector((byte)labelIndex, bitVectorFactory))); }
internal static IEnumerable <Tuple <IBitVector, IBitVector> > ReadTrainingData(IBitVectorFactory bitVectorFactory) { return(ReaData(QmnistReader.ReadTrainingData, bitVectorFactory)); }