/// <summary> /// Get the probility of the certain value. /// </summary> private double getProbility(随机变量值域 value) { double result = default(double); 随机变量值域 fommer = default(随机变量值域); 随机变量值域 latter = default(随机变量值域); if (dictionary.Keys.Contains(value)) { dictionary.TryGetValue(value, out result); //Console.WriteLine("Contains value {0} result {1}", value, result); return(result); } if (comparer.Compare(dictionary.Last().Key, value) < 0) { return(1.0); } foreach (var item in dictionary.Keys) { if (comparer.Compare(item, value) > 0) { latter = item; break; } fommer = item; } result = calculateProbability(fommer, latter, value); return(result); }
private double calculateProbability(随机变量值域 former, 随机变量值域 latter, 随机变量值域 value) { var _former = default(double); var _latter = default(double); var result = default(double); dictionary.TryGetValue(former, out _former); dictionary.TryGetValue(latter, out _latter); if (value is int || value is double || value is float || value is decimal) { double _fObject = Convert.ToDouble(former); double _LObject = Convert.ToDouble(latter); double k = (double)((_latter - _former) / (_LObject - _fObject)); double b = _latter - k * _LObject; result = k * Convert.ToDouble(value) + b; //Console.WriteLine("value {0} K {1}, b {2} result {3}",value,k,b,result); } else { result = (double)((_former + _latter) / 2); //Console.WriteLine("value {0} result {1}",value, result); } return(result); }
public void OnNext(随机变量值域 value) { var probility = getProbility(value); base._observer.OnNext(probility); }