예제 #1
0
        protected override double ProbabilityOfFindingExactly(int number, List <MemoryAlignedMatrix> results)
        {
            Debug.Assert(number > 0 && number <= units.Count);
            Debug.Assert(results.Count == units.Count);

            // Build a list of all combinations of units that satisfy the search condition (atLeast)
            var yesno        = Enumerable.Repeat(true, number).Concat(Enumerable.Repeat(false, units.Count - number)).ToArray();
            var permutations = IterTools.Permutations(yesno).Distinct(new IEnumerableComparer <bool>()).ToArray();

            double accumulator = 0;

            foreach (var permutation in permutations)
            {
                Debug.Assert(permutation.Count() == units.Count());

                double multiplier = 1;

                for (int i = 0; i < units.Count; ++i)
                {
                    int    index = results[i].Size - 1;
                    double p     = results[i][0, index];
                    multiplier *= permutation.ElementAt(i) ? p : 1 - p;
                }

                accumulator += multiplier;
            }
            return(accumulator);
        }
예제 #2
0
        protected override double ProbabilityOfFindingExactly(int number, List <MemoryAlignedMatrix> results)
        {
            Debug.Assert(results.Count == 1);
            // Build a list of all combinations of units that satisfy the search condition
            var yesno        = Enumerable.Repeat(true, number).Concat(Enumerable.Repeat(false, units.Count - number)).ToArray();
            var permutations = IterTools.Permutations(yesno).Distinct(new IEnumerableComparer <bool>()).ToArray();

            // For each unique matrix index from the permutations, take the probability and sum it
            return(permutations.SelectMany(p => unitMatrices[0].IndicesForFinding(p)).Distinct().Select(i => results[0][0, i]).Sum());
        }