int GetInterval(double value, ExpertEstimate estimates, double[] quantiles) { if (value <= estimates.GetQuantile(quantiles[0])) { return(0); } int i; for (i = 0; i < quantiles.Length - 1; i++) { if (estimates.GetQuantile(quantiles[i]) <= value && value <= estimates.GetQuantile(quantiles[i + 1])) { return(i + 1); } } if (estimates.GetQuantile(quantiles[i]) <= value) { return(i + 1); } throw new InvalidOperationException(); }
double[] GetInterpolatedDistribution(CalibrationVariable v, ExpertEstimate estimate, double[] quantiles) { var res = new List <double> (); double lowerBound, upperBound; GetBounds(v, out lowerBound, out upperBound); Func <double, double, double> interpolate = (x, y) => 1.0d * (y - x) / (upperBound - lowerBound); res.Add(interpolate(lowerBound, estimate.GetQuantile(quantiles[0]))); var quantilesCount = quantiles.Count(); for (int i = 1; i < quantilesCount; i++) { var l0 = estimate.GetQuantile(quantiles[i - 1]); var l1 = estimate.GetQuantile(quantiles[i]); res.Add(interpolate(l0, l1)); } var lastQuantile = quantiles[quantilesCount - 1]; res.Add(interpolate(estimate.GetQuantile(lastQuantile), upperBound)); return(res.ToArray()); }
/// <summary> /// Adds the estimate for the specified variable <c>variable</c>. /// </summary> /// <param name="variable">Variable.</param> /// <param name="estimates">Estimates.</param> public void AddEstimate(ExpertVariable variable, ExpertEstimate estimate) { Estimates.Add(variable, estimate); }