private void butPareto_Click(object sender, RoutedEventArgs e) { Reset(ChartType.Pareto); modelChart = Pareto.Create(); controller.ChartModel = modelChart; RenderChart(); }
public void ValidateToString() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var n = new Pareto(1d, 2d); Assert.AreEqual("Pareto(xm = 1, α = 2)", n.ToString()); }
public void CanCreatePareto([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale, n.Scale); Assert.AreEqual(shape, n.Shape); }
public void CanSampleSequence() { var n = new Pareto(1.0, 1.0); var ied = n.Samples(); ied.Take(5).ToArray(); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PowerOp"]/message_doc[@name="XAverageConditional(Pareto, Gamma, double)"]/*'/> public static Gamma XAverageConditional(Pareto pow, Gamma x, double y) { // factor is delta(pow - x^y) // marginal for x is Pareto(x^y; s,L) Ga(x; a,b) // =propto x^(a-1-y(s+1)) exp(-bx) for x >= L^(1/y) // we can compute moments via the incomplete Gamma function. // change variables to: z=bx, dz=b dx // int_LL^inf x^(c-1) exp(-bx) dx = int_(bLL)^inf z^(c-1)/b^c exp(-z) dz = gammainc(c,bLL,inf)/b^c double lowerBound = System.Math.Pow(pow.LowerBound, 1 / y); double b = x.Rate; double c = x.Shape - y * (pow.Shape + 1); double bL = b * lowerBound; double m, m2; if (y > 0) { // note these ratios can be simplified double z = MMath.GammaUpper(c, bL); m = MMath.GammaUpper(c + 1, bL) * c / z / b; m2 = MMath.GammaUpper(c + 2, bL) * c * (c + 1) / z / (b * b); } else { double z = MMath.GammaLower(c, bL); m = MMath.GammaLower(c + 1, bL) * c / z / b; m2 = MMath.GammaLower(c + 2, bL) * c * (c + 1) / z / (b * b); } double v = m2 - m * m; Gamma xPost = Gamma.FromMeanAndVariance(m, v); Gamma result = new Gamma(); result.SetToRatio(xPost, x, true); return(result); }
public void CanCreatePareto(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale, n.Scale); Assert.AreEqual(shape, n.Shape); }
public void ValidateMedian( [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale * Math.Pow(2.0, 1.0 / shape), n.Median); }
public void ValidateCumulativeDistribution(double scale, double shape, double x) { var n = new Pareto(scale, shape); double expected = 1.0 - Math.Pow(scale / x, shape); Assert.AreEqual(expected, n.CumulativeDistribution(x)); Assert.AreEqual(expected, Pareto.CDF(scale, shape, x)); }
public void ValidateInverseCumulativeDistribution(double scale, double shape, double x) { var n = new Pareto(scale, shape); double cdf = 1.0 - Math.Pow(scale / x, shape); Assert.AreEqual(x, n.InverseCumulativeDistribution(cdf), 1e-12); Assert.AreEqual(x, Pareto.InvCDF(scale, shape, cdf), 1e-12); }
public void ValidateMean([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); if (shape > 1) { Assert.AreEqual(shape * scale / (shape - 1.0), n.Mean); } }
public void ValidateCumulativeDistribution( [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape, [Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x) { var n = new Pareto(scale, shape); Assert.AreEqual(1.0 - Math.Pow(scale / x, shape), n.CumulativeDistribution(x)); }
public void ValidateMean(double scale, double shape) { var n = new Pareto(scale, shape); if (shape > 1) { Assert.AreEqual(shape * scale / (shape - 1.0), n.Mean); } }
public void ValidateDensity( [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape, [Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x) { var n = new Pareto(scale, shape); Assert.AreEqual(shape * Math.Pow(scale, shape) / Math.Pow(x, shape + 1.0), n.Density(x)); }
public void ValidateDensityLn( [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape, [Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x) { var n = new Pareto(scale, shape); Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x)); }
public void ValidateDensity(double scale, double shape, double x, double expected) { var dist = new Pareto(scale, shape); Assert.AreEqual(expected, dist.Density(x), 1e-12); Assert.AreEqual(expected, Pareto.PDF(scale, shape, x), 1e-12); Assert.AreEqual(Math.Log(expected), dist.DensityLn(x), 1e-12); Assert.AreEqual(Math.Log(expected), Pareto.PDFLn(scale, shape, x), 1e-12); }
public void TestDistribution(double xm, double a) { var expectedMean = a * xm / (a - 1); var expectedVariance = (xm * xm * a) / ((a - 1) * (a - 1) * (a - 2)); var distribution = new Pareto(xm, a); var list = Enumerable.Range(1, 10000000).Select(x => distribution.Sample()).ToList(); var calculatedMean = Statistics.Mean(list); calculatedMean.ShouldBe(expectedMean, 0.05 * expectedMean); Statistics.Variance(list).ShouldBe(expectedVariance, 0.5 * expectedVariance); }
// Pareto = Pareto ^ y //////////////////////////////////////////////////////////////////// /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PowerOp"]/message_doc[@name="PowAverageConditional(Pareto, double)"]/*'/> public static Pareto PowAverageConditional(Pareto x, double y) { if (y < 0) { throw new NotSupportedException("Pareto raised to a negative power (" + y + ") cannot be represented by a Pareto distribution"); } // p(x) =propto 1/x^(s+1) // z = x^y implies // p(z) = p(x = z^(1/y)) (1/y) z^(1/y-1) // =propto z^(-(s+1)/y+1/y-1) = z^(-s/y-1) return(new Pareto(x.Shape / y, System.Math.Pow(x.LowerBound, y))); }
public void ValidateVariance(double scale, double shape) { var n = new Pareto(scale, shape); if (shape <= 2.0) { Assert.AreEqual(double.PositiveInfinity, n.Variance); } else { Assert.AreEqual(scale * scale * shape / ((shape - 1.0) * (shape - 1.0) * (shape - 2.0)), n.Variance); } }
public static void Main() { // 实例化算例分配引擎 MOCBA mocba = new MOCBA(); // 创建有限解集 var candidates = Enumerable.Range(1, 4) .SelectMany(i => Enumerable.Range(1, 4) .SelectMany(j => Enumerable.Range(1, 4) .Select(k => new StochasticSolution(new double[] { i, j, k })))) .ToDictionary(s => s.Decisions, s => s); // 初始测量 foreach (var sol in candidates.Values) { Exercise_7.Evaluate(sol, nReps: 5); } int h = 0; while (true) { int budgetPerSolution = 2; // Equal Allocation - 平均分配 //foreach (var sol in candidates.Values) Exercise_7.Evaluate(sol, budgetPerSolution); // MOCBA - 依据当前随机解结果分配算力,执行测量 foreach (var alloc in mocba.Alloc(candidates.Count * budgetPerSolution, candidates.Values)) { Exercise_7.Evaluate(candidates[alloc.Key], alloc.Value); } Console.Clear(); Console.WriteLine("Iteration: {0}", h++); // 获取并显示当前帕里多集 foreach (var sol in Pareto.GetParetoSet(candidates.Values, sol => sol.Objectives) .OrderBy(sol => sol.Objectives[0])) { Console.WriteLine(sol); } Console.WriteLine("Total Budget: {0}", candidates.Values.Sum(sol => sol.Observations.Count)); // 显示当前近似正确选择概率 Console.WriteLine("APCS-M: {0:F4}", mocba.APCS_M(candidates.Values)); Console.ReadKey(); } }
public void Initialize(float mean, float coefficientOfVariation) { if (coefficientOfVariation >= 16 || coefficientOfVariation <= 0) { throw new ArgumentOutOfRangeException("coefficientOfVariation", "CoefficientOfVariation should be from range (0,16)"); } double m = mean; double sd = mean * coefficientOfVariation; double v = sd * sd; //double a = 1 + Math.Sqrt(1 + m*m/v); double a = 1 / coefficientOfVariation * 16; double xm = m * (a - 1) / a; Distribution = new Pareto(xm, a); Sum = 0; }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="UniformPlusMinusOp"]/message_doc[@name="LogEvidenceRatio(double, Pareto)"]/*'/> public static double LogEvidenceRatio(double sample, Pareto upperBound) { // factor is 1/(2*upperBound) // result is int_y^inf 1/(2*x)*s*L^s/x^(s+1) dx = 0.5*s*L^s/y^(s+1)/(s+1) // where y = max(sample,L) double x = System.Math.Abs(sample); double result = -MMath.Ln2 + System.Math.Log(upperBound.Shape / (upperBound.Shape + 1)); if (upperBound.LowerBound < x) { result += upperBound.Shape * System.Math.Log(upperBound.LowerBound) - (upperBound.Shape + 1) * System.Math.Log(x); } else { result -= System.Math.Log(upperBound.LowerBound); } return(result); }
public void ValidateMedian(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale * Math.Pow(2.0, 1.0 / shape), n.Median); }
public void ValidateSkewness(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual((2.0 * (shape + 1.0) / (shape - 3.0)) * Math.Sqrt((shape - 2.0) / shape), n.Skewness); }
public void ValidateStdDev(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual((scale * Math.Sqrt(shape)) / ((shape - 1.0) * Math.Sqrt(shape - 2.0)), n.StdDev); }
public void ValidateToString() { var n = new Pareto(1d, 2d); Assert.AreEqual("Pareto(xm = 1, α = 2)", n.ToString()); }
public void ValidateEntropy([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(Math.Log(shape / scale) - (1.0 / shape) - 1.0, n.Entropy); }
public void CanSample() { var n = new Pareto(1.0, 1.0); n.Sample(); }
public void ValidateDensityLn(double scale, double shape, double x) { var n = new Pareto(scale, shape); Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x)); }
public void ValidateMaximum() { var n = new Pareto(1.0, 1.0); Assert.AreEqual(Double.PositiveInfinity, n.Maximum); }
public void ParetoCreateFailsWithBadParameters( [Values(Double.NaN, 1.0, Double.NaN, 1.0, -1.0, -1.0, 0.0, 0.0, 1.0)] double scale, [Values(1.0, Double.NaN, Double.NaN, -1.0, 1.0, -1.0, 0.0, 1.0, 0.0)] double shape) { Assert.Throws<ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); }); }
public void ValidateSkewness([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual((2.0 * (shape + 1.0) / (shape - 3.0)) * Math.Sqrt((shape - 2.0) / shape), n.Skewness); }
public void ParetoCreateFailsWithBadParameters(double scale, double shape) { Assert.Throws <ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); }); }
public void ValidateToString() { var n = new Pareto(1.0, 2.0); Assert.AreEqual("Pareto(Scale = 1, Shape = 2)", n.ToString()); }
public void SetShapeFailsWithNegativeShape() { var n = new Pareto(1.0, 1.0); Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = -1.0); }
public void ValidateStdDev([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual((scale * Math.Sqrt(shape)) / ((shape - 1.0) * Math.Sqrt(shape - 2.0)), n.StdDev); }
public void ValidateMinimum(double scale) { var n = new Pareto(scale, 1.0); Assert.AreEqual(scale, n.Minimum); }
public void ValidateEntropy(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(Math.Log(shape / scale) - (1.0 / shape) - 1.0, n.Entropy); }
public void ValidateMode(double scale, double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale, n.Mode); }
public void ValidateMinimum([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale) { var n = new Pareto(scale, 1.0); Assert.AreEqual(scale, n.Minimum); }
public void ValidateDensity(double scale, double shape, double x) { var n = new Pareto(scale, shape); Assert.AreEqual(shape * Math.Pow(scale, shape) / Math.Pow(x, shape + 1.0), n.Density(x)); }
public void ValidateMode([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape) { var n = new Pareto(scale, shape); Assert.AreEqual(scale, n.Mode); }
public void ValidateCumulativeDistribution(double scale, double shape, double x) { var n = new Pareto(scale, shape); Assert.AreEqual(1.0 - Math.Pow(scale / x, shape), n.CumulativeDistribution(x)); }
public void ParetoCreateFailsWithBadParameters(double scale, double shape) { Assert.Throws<ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); }); }