Example #1
0
 private void butPareto_Click(object sender, RoutedEventArgs e)
 {
     Reset(ChartType.Pareto);
     modelChart            = Pareto.Create();
     controller.ChartModel = modelChart;
     RenderChart();
 }
Example #2
0
        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());
        }
Example #3
0
        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);
        }
Example #4
0
        public void CanSampleSequence()
        {
            var n   = new Pareto(1.0, 1.0);
            var ied = n.Samples();

            ied.Take(5).ToArray();
        }
Example #5
0
        /// <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);
        }
Example #6
0
        public void CanCreatePareto(double scale, double shape)
        {
            var n = new Pareto(scale, shape);

            Assert.AreEqual(scale, n.Scale);
            Assert.AreEqual(shape, n.Shape);
        }
Example #7
0
        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);
        }
Example #8
0
        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));
        }
Example #9
0
        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);
        }
Example #10
0
        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);
            }
        }
Example #11
0
        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));
        }
Example #12
0
        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);
            }
        }
Example #13
0
        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));
        }
Example #14
0
        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));
        }
Example #15
0
        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);
        }
Example #17
0
        // 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)));
        }
Example #18
0
        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);
            }
        }
Example #19
0
        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();
            }
        }
Example #20
0
        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;
        }
Example #21
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 ValidateMean(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     if (shape > 1)
     {
         Assert.AreEqual(shape * scale / (shape - 1.0), n.Mean);
     }
 }
Example #26
0
        public void ValidateToString()
        {
            var n = new Pareto(1d, 2d);

            Assert.AreEqual("Pareto(xm = 1, α = 2)", n.ToString());
        }
Example #27
0
 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);
 }
Example #28
0
        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));
 }
Example #30
0
 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));
 }
Example #31
0
 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));
 }
Example #32
0
 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));
 }
Example #33
0
 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 ValidateMaximum()
 {
     var n = new Pareto(1.0, 1.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
Example #35
0
 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 CanSampleSequence()
 {
     var n = new Pareto(1.0, 1.0);
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
Example #37
0
 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 CanCreatePareto(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(scale, n.Scale);
     Assert.AreEqual(shape, n.Shape);
 }
Example #39
0
 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);
 }
Example #42
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 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);
     }
 }
Example #44
0
        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);
 }
Example #46
0
        public void ValidateMaximum()
        {
            var n = new Pareto(1.0, 1.0);

            Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
        }
 public void ValidateMode(double scale, double shape)
 {
     var n = new Pareto(scale, shape);
     Assert.AreEqual(scale, n.Mode);
 }
Example #48
0
 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 ValidateMinimum(double scale)
 {
     var n = new Pareto(scale, 1.0);
     Assert.AreEqual(scale, n.Minimum);
 }
Example #50
0
 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 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));
 }
Example #52
0
 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 CanSample()
 {
     var n = new Pareto(1.0, 1.0);
     n.Sample();
 }
Example #54
0
        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 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));
 }
Example #56
0
        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 ParetoCreateFailsWithBadParameters(double scale, double shape)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); });
 }
Example #58
0
        public void ValidateMode(double scale, double shape)
        {
            var n = new Pareto(scale, shape);

            Assert.AreEqual(scale, n.Mode);
        }
Example #59
0
        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);
        }
Example #60
0
 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);
     }
 }