Example #1
0
        CalculateMatchingScoresPerLabelPerPunchedCard(
            IDictionary <string, IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > >
            punchedCardsCollection,
            IBitVector input,
            IPuncher <string, IBitVector, IBitVector> puncher,
            IDictionary <int, IAdjacencyMatrix> adjacencyMatrices)
        {
            var matchingScoresPerLabelPerPunchedCard = new Dictionary <IBitVector, IDictionary <string, double> >();

            foreach (var punchedCardsCollectionItem in punchedCardsCollection)
            {
                var punchedInput = puncher.Punch(punchedCardsCollectionItem.Key, input).Input;
                foreach (var label in punchedCardsCollectionItem.Value)
                {
                    ProcessTheSpecificLabel(
                        matchingScoresPerLabelPerPunchedCard,
                        punchedCardsCollectionItem.Key,
                        label.Key,
                        label.Value.Count,
                        adjacencyMatrices[GetAdjacencyMatrixKey(punchedCardsCollectionItem.Key, label.Key)],
                        punchedInput);
                }
            }

            return(matchingScoresPerLabelPerPunchedCard);
        }
        CalculateLossPerLabelPerPunchedCard(
            IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsCollection,
            IBitVector input,
            IPuncher <string, IBitVector, IBitVector> puncher,
            IReadOnlyDictionary <string, IExpert> experts)
        {
            var lossPerLabelPerPunchedCard = new Dictionary <IBitVector, IReadOnlyDictionary <string, double> >();

            foreach (var punchedCardsCollectionItem in punchedCardsCollection)
            {
                var expert       = experts[punchedCardsCollectionItem.Key];
                var punchedInput = puncher.Punch(punchedCardsCollectionItem.Key, input).Input;
                var losses       = expert.CalculateLosses(punchedInput);
                foreach (var label in punchedCardsCollectionItem.Value)
                {
                    if (!lossPerLabelPerPunchedCard.TryGetValue(label.Key, out var dictionary))
                    {
                        dictionary = new Dictionary <string, double>();
                        lossPerLabelPerPunchedCard.Add(label.Key, dictionary);
                    }

                    ((Dictionary <string, double>)dictionary).Add(punchedCardsCollectionItem.Key, losses[label.Key]);
                }
            }

            return(lossPerLabelPerPunchedCard);
        }
        CalculateMatchingScoresPerLabelPerPunchedCard(
            IDictionary <string, IDictionary <IBitVector, IReadOnlyCollection <Tuple <IBitVector, int> > > >
            punchedCardsCollection,
            IBitVector input,
            IPuncher <string, IBitVector, IBitVector> puncher)
        {
            var matchingScoresPerLabelPerPunchedCard = new Dictionary <IBitVector, IDictionary <string, double> >();

            foreach (var punchedCardsCollectionItem in punchedCardsCollection)
            {
                var punchedInput = puncher.Punch(punchedCardsCollectionItem.Key, input).Input;
                foreach (var label in punchedCardsCollectionItem.Value)
                {
                    ProcessTheSpecificLabel(matchingScoresPerLabelPerPunchedCard, punchedCardsCollectionItem.Key,
                                            label, punchedInput);
                }
            }

            return(matchingScoresPerLabelPerPunchedCard);
        }
Example #4
0
        GetPunchedCardsPerKeyPerLabel(
            IList <Tuple <IBitVector, IBitVector> > trainingData,
            IPuncher <string, IBitVector, IBitVector> puncher)
        {
            var count = trainingData[0].Item1.Count;

            var punchedCardsPerKeyPerLabel = new Dictionary <
                string,
                IDictionary <IBitVector, IReadOnlyCollection <IBitVector> > >();

            puncher
            .GetKeys(count)
            .AsParallel()
            .ForAll(key =>
            {
                punchedCardsPerKeyPerLabel.Add(key,
                                               GetPunchedCardsPerLabel(trainingData.Select(trainingDataItem =>
                                                                                           new Tuple <IPunchedCard <string, IBitVector>, IBitVector>(
                                                                                               puncher.Punch(key, trainingDataItem.Item1),
                                                                                               trainingDataItem.Item2))
                                                                       .Where(punchedCardInput => punchedCardInput.Item1.Input.ActiveBitIndices.Count > 0)));
            });
            return(punchedCardsPerKeyPerLabel);
        }
Example #5
0
        GetPunchedCardsPerKeyPerLabel(
            IReadOnlyList <Tuple <IBitVector, IBitVector> > trainingData,
            IPuncher <string, IBitVector, IBitVector> puncher)
        {
            var count = trainingData[0].Item1.Count;

            return(puncher
                   .GetKeys(count)
                   .AsParallel()
                   .Select(key => Tuple.Create(
                               key,
                               GetPunchedCardsPerLabel(trainingData.Select(trainingDataItem =>
                                                                           Tuple.Create(puncher.Punch(key, trainingDataItem.Item1), trainingDataItem.Item2)))))
                   .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2));
        }