QLNet.GeneralStatistics.expectationValue C# (CSharp) Метод

expectationValue() публичный Метод

public expectationValue ( double>.Func f, double>.Func inRange ) : int>.KeyValuePair
f double>.Func
inRange double>.Func
Результат int>.KeyValuePair
        public KeyValuePair<double, int> expectationValue(Func<KeyValuePair<double, double>, double> f,
            Func<KeyValuePair<double, double>, bool> inRange)
        {
            double num = 0.0, den = 0.0;
            int N = 0;

            foreach(KeyValuePair<double,double> x in samples_.Where<KeyValuePair<double,double>>(x => inRange(x))) {
                num += f(x)*x.Value;
                den += x.Value;
                N += 1;
            }

            if (N == 0) return new KeyValuePair<double,int>(0,0);
            else return new KeyValuePair<double,int>(num/den,N);
        }