private double[] GetDiscretizationSupport() { bool minInfinite = double.IsInfinity(BaseDistribution.Support.Min); bool maxInfinite = double.IsInfinity(BaseDistribution.Support.Max); double tolerance = CommonRandomMath.GetTolerance(InnerSamples); double min = minInfinite ? GetSupport(true, tolerance) : BaseDistribution.Support.Min; double max = maxInfinite ? GetSupport(false, tolerance) : BaseDistribution.Support.Max; min = (min * Coefficient) + Offset; max = (max * Coefficient) + Offset; if (min > max) { double temp = min; min = max; max = temp; } return(new double[] { min, max }); }
private static PrivateCoordinates Resample(PrivateCoordinates coordinates) { var pdf = coordinates.PDFCoordinates; int length = coordinates.XCoordinates.Length; double min = coordinates.XCoordinates[0]; double max = coordinates.XCoordinates[length - 1]; double step = (max - min) / (length - 1); AnalyzeInfinities(pdf, step); Normalize(pdf, step); double[] cdf = GetCDF(pdf, step); double tolerance = CommonRandomMath.GetTolerance(length); var minI = 0; var maxI = length - 1; for (int i = 0; i < length - 1; i++) { var c = cdf[i]; if (c < tolerance) { if (pdf[i] == 0) { minI = i + 1; } else { minI = i; } } if (c > 1 - tolerance) { if (pdf[i] == 0) { maxI = i - 1; } else { maxI = i; } break; } } min = coordinates.XCoordinates[minI]; max = coordinates.XCoordinates[maxI]; int r = maxI - minI + 1; if (r != length) { double[] newX = CommonRandomMath.GenerateXAxis(min, max, length, out _); double[] newY = new double[r]; for (int i = 0; i < r; i++) { newY[i] = coordinates.PDFCoordinates[i + minI]; } newY = CommonRandomMath.Resample(newY, length); return(new PrivateCoordinates { XCoordinates = newX, PDFCoordinates = newY }); } else { return(coordinates); } }