Example #1
0
        /// <summary>
        /// Calculates a single items probability of being in set A
        /// </summary>
        /// <param name="Item">Item to calculate</param>
        /// <returns>The probability that the token is from set A</returns>
        protected virtual double CalculateProbabilityOfToken(T Item)
        {
            Contract.Requires <ArgumentNullException>(SetA != null && SetB != null, "Probabilities have not been initialized");
            double Probability = 0;
            int    ACount      = SetA.Contains(Item) ? SetA[Item] * ATokenWeight : 0;
            int    BCount      = SetB.Contains(Item) ? SetB[Item] * BTokenWeight : 0;

            if (ACount + BCount >= MinCountForInclusion)
            {
                double AProbability = ((double)ACount / (double)TotalA).Min(1);
                double BProbability = ((double)BCount / (double)TotalB).Min(1);
                Probability = MinTokenProbability.Max(MaxTokenProbability.Min(AProbability / (AProbability + BProbability)));
            }
            return(Probability);
        }
Example #2
0
        /// <summary>
        /// Calculates a single items probability of being in set A
        /// </summary>
        /// <param name="Item">Item to calculate</param>
        /// <returns>The probability that the token is from set A</returns>
        protected virtual double CalculateProbabilityOfToken(T Item)
        {
            if (SetA == null || SetB == null)
            {
                throw new NullReferenceException("Probabilities have not been initialized");
            }
            double Probability = 0;
            int    ACount      = SetA.Contains(Item) ? SetA[Item] * ATokenWeight : 0;
            int    BCount      = SetB.Contains(Item) ? SetB[Item] * BTokenWeight : 0;

            if (ACount + BCount >= MinCountForInclusion)
            {
                double AProbability = ((double)ACount / (double)TotalA).Min(1);
                double BProbability = ((double)BCount / (double)TotalB).Min(1);
                Probability = MinTokenProbability.Max(MaxTokenProbability.Min(AProbability / (AProbability + BProbability)));
            }
            return(Probability);
        }