Exemple #1
0
        public static DenormalizedProbability <int> Get(int lb, int ub)
        {
#if DEBUG
            if (lb > ub)
            {
                throw new InvalidOperationException("lb > ub");
            }
#endif
            if (lb == ub)
            {
                return(ConstantDistribution <int> .Get(lb));
            }
            var index = new KeyValuePair <int, int>(lb, ub);
            if (_cache.TryGetValue(index, out var val))
            {
                return(new DenormalizedProbability <int>(val));
            }
            var raw = new Dictionary <int, float>();
            for (int x = lb; x <= ub; x++)
            {
                raw[x] = 1;
            }
            var ret = new DenormalizedProbability <int>(raw);
            ret.Normalize();
            _cache[index] = new DenormalizedProbability <int>(ret);
            return(ret);
        }
Exemple #2
0
        static public float LessThan(this int lhs, DenormalizedProbability <int> rhs)
        {
            DenormalizedProbability <int> LHS = ConstantDistribution <int> .Get(lhs);

            DenormalizedProbability <int> ret_src = DenormalizedProbability <int> .Apply(LHS *rhs, _less_than);

            return(ret_src[1]);
        }