public void Test1()
        {
            var pc         = new CDF(_samples);
            var percentile = pc.Calculate(999);

            Assert.Equal(0, percentile);
        }
Пример #2
0
    private static void normal_truncated_b_cdf_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_B_CDF_TEST tests NORMAL_TRUNCATED_B_CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;

        const double b    = 150.0;
        const double mu   = 100.0;
        const double s    = 25.0;
        int          seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_TRUNCATED_B_CDF_TEST");
        Console.WriteLine("  NORMAL_TRUNCATED_B_CDF evaluates the Normal Truncated B CDF.");
        Console.WriteLine("  NORMAL_TRUNCATED_B_CDF_INV inverts the Normal Truncated B CDF.");
        Console.WriteLine("  NORMAL_TRUNCATED_B_PDF evaluates the Normal Truncated B PDF.");
        Console.WriteLine("");
        Console.WriteLine("  The parent normal distribution has");
        Console.WriteLine("    mean =               " + mu + "");
        Console.WriteLine("    standard deviation = " + s + "");
        Console.WriteLine("  The parent distribution is truncated to");
        Console.WriteLine("  the interval [-oo," + b + "]");

        Console.WriteLine("");
        Console.WriteLine("       X            PDF           CDF            CDF_INV");
        Console.WriteLine("");

        for (i = 1; i <= 10; i++)
        {
            double x = Truncated.normal_truncated_b_sample(mu, s, b, ref seed);

            double pdf = Truncated.normal_truncated_b_pdf(x, mu, s, b);

            double cdf = CDF.normal_truncated_b_cdf(x, mu, s, b);

            double x2 = CDF.normal_truncated_b_cdf_inv(cdf, mu, s, b);

            Console.WriteLine("  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + x2.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Пример #3
0
        public IActionResult OnGet()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var samples = GetSamples();

            var cdf = new CDF(samples);

            Percentile = cdf.Calculate(GetRandomVariable());

            var cdfInv = new InverseCDF(samples);

            const double eps = .0001;

            for (var perc = 0.0; perc <= .95 + eps; perc += .05)
            {
                var inv = cdfInv.Calculate(perc);
                Percentiles.Add(inv);
                XAxis.Add(Convert.ToInt32(perc * 100));
            }

            return(Page());
        }
        public void Test3()
        {
            var pc         = new CDF(_samples);
            var percentile = pc.Calculate(1001);

            Assert.Equal(1, percentile);
        }
Пример #5
0
    public static double log_normal_truncated_ab_mean(double mu, double sigma, double a,
                                                      double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_TRUNCATED_AB_MEAN: mean of the Log Normal truncated AB PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 March 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, SIGMA, the parameters of the PDF.
    //    0.0 < SIGMA.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //    A < B.
    //
    //    Output, double LOG_NORMAL_TRUNCATED_AB_MEAN, the mean of the PDF.
    //
    {
        bool check = log_normal_truncated_ab_check(mu, sigma, a, b);

        switch (check)
        {
        case false:
            Console.WriteLine("");
            Console.WriteLine("LOG_NORMAL_TRUNCATED_AB_MEAN - Fatal error!");
            Console.WriteLine("  Parameters are not legal.");
            return(1);
        }

        double a0 = (Math.Log(a) - mu) / sigma;
        double b0 = (Math.Log(b) - mu) / sigma;

        double c1 = CDF.normal_01_cdf(sigma - a0);
        double c2 = CDF.normal_01_cdf(sigma - b0);
        double c3 = CDF.normal_01_cdf(+a0);
        double c4 = CDF.normal_01_cdf(+b0);

        double ln_mean = Math.Exp(mu + 0.5 * sigma * sigma);

        double mean = ln_mean * (c1 - c2) / (c4 - c3);

        return(mean);
    }
Пример #6
0
    public static double log_normal_truncated_ab_sample(double mu, double sigma, double a,
                                                        double b, ref int seed)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_TRUNCATED_AB_SAMPLE samples the Log Normal truncated AB PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 March 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, SIGMA, the parameters of the PDF.
    //    0.0 < SIGMA.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //    A < B.
    //
    //    Input/output, int &SEED, a seed for the random number generator.
    //
    //    Output, double LOG_NORMAL_TRUNCATED_AB_SAMPLE, a sample of the PDF.
    //
    {
        bool check = log_normal_truncated_ab_check(mu, sigma, a, b);

        switch (check)
        {
        case false:
            Console.WriteLine("");
            Console.WriteLine("LOG_NORMAL_TRUNCATED_AB_SAMPLE - Fatal error!");
            Console.WriteLine("  Parameters are not legal.");
            return(1);
        }

        double lncdf_a = CDF.log_normal_cdf(a, mu, sigma);
        double lncdf_b = CDF.log_normal_cdf(b, mu, sigma);

        double cdf = UniformRNG.r8_uniform_ab(lncdf_a, lncdf_b, ref seed);

        double x = CDF.log_normal_cdf_inv(cdf, mu, sigma);

        return(x);
    }
 public ActionResult TestCDF()
 {
     try
     {
         var fi  = new FileInfo(@"E:\video\191006-20.D02");
         var CDF = new CDF(fi);
     }
     catch (Exception ex)
     {
     }
     return(View("All"));
 }
Пример #8
0
    public static void normal_01_cdf_inverse_test( )

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_01_CDF_INVERSE_TEST tests NORMAL_01_CDF_INVERSE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 February 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx     = 0;
        int    n_data = 0;
        double x      = 0;
        double x2     = 0;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_01_CDF_INVERSE_TEST:");
        Console.WriteLine("  NORMAL_01_CDF_INVERSE inverts the normal 01 CDF.");
        Console.WriteLine("");
        Console.WriteLine("    FX      X    NORMAL_01_CDF_INVERSE(FX)");
        Console.WriteLine("");

        n_data = 0;

        for ( ; ;)
        {
            Burkardt.Values.Normal.normal_01_cdf_values(ref n_data, ref x, ref fx);

            if (n_data == 0)
            {
                break;
            }

            x2 = CDF.normal_01_cdf_inv(fx);

            Console.WriteLine("  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + x2.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Пример #9
0
    public static double normal_truncated_a_pdf(double x, double mu, double sigma, double a)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRUNCATED_NORMAL_A_PDF evaluates the lower truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    24 January 2017
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double X, the argument of the PDF.
    //
    //    Input, double MU, SIGMA, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double A, the lower truncation limit.
    //
    //    Output, double TRUNCATED_NORMAL_A_PDF, the value of the PDF.
    //
    {
        double pdf;

        if (x < a)
        {
            pdf = 0.0;
        }
        else
        {
            double alpha = (a - mu) / sigma;
            double xi    = (x - mu) / sigma;

            double alpha_cdf = CDF.normal_01_cdf(alpha);
            double xi_pdf    = Normal.normal_01_pdf(xi);

            pdf = xi_pdf / (1.0 - alpha_cdf) / sigma;
        }

        return(pdf);
    }
Пример #10
0
    public static double log_normal_cdf(double x, double a, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_CDF evaluates the Lognormal CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 September 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double X, the argument of the PDF.
    //    0.0 < X.
    //
    //    Input, double A, B, the parameters of the PDF.
    //    0.0 < B.
    //
    //    Output, double CDF, the value of the CDF.
    //
    {
        double cdf;

        switch (x)
        {
        case <= 0.0:
            cdf = 0.0;
            break;

        default:
        {
            double logx = Math.Log(x);

            cdf = CDF.normal_cdf(logx, a, b);
            break;
        }
        }

        return(cdf);
    }
Пример #11
0
    public static double normal_truncated_ab_sample(double mu, double s, double a, double b,
                                                    ref int seed)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_AB_SAMPLE samples the truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, S, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //
    //    Input/output, int &SEED, a seed for the random number
    //    generator.
    //
    //    Output, double NORMAL_TRUNCATED_AB_SAMPLE, a sample of the PDF.
    //
    {
        double alpha = (a - mu) / s;
        double beta  = (b - mu) / s;

        double alpha_cdf = CDF.normal_01_cdf(alpha);
        double beta_cdf  = CDF.normal_01_cdf(beta);

        double u      = UniformRNG.r8_uniform_01(ref seed);
        double xi_cdf = alpha_cdf + u * (beta_cdf - alpha_cdf);
        double xi     = CDF.normal_01_cdf_inv(xi_cdf);

        double x = mu + s * xi;

        return(x);
    }
Пример #12
0
    public static double half_normal_cdf_inv(double cdf, double a, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HALF_NORMAL_CDF_INV inverts the Half Normal CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    17 October 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double CDF, the value of the CDF.
    //    0.0 <= CDF <= 1.0.
    //
    //    Input, double A, B, the parameters of the PDF.
    //    0.0 < B.
    //
    //    Output, double HALF_NORMAL_CDF_INV, the corresponding argument.
    //
    {
        switch (cdf)
        {
        case < 0.0:
        case > 1.0:
            Console.WriteLine(" ");
            Console.WriteLine("HALF_NORMAL_CDF_INV - Fatal error!");
            Console.WriteLine("  CDF < 0 or 1 < CDF.");
            return(1);
        }

        double cdf2 = 0.5 * (cdf + 1.0);

        double x = CDF.normal_cdf_inv(cdf2, a, b);

        return(x);
    }
Пример #13
0
    public static double normal_truncated_ab_pdf(double x, double mu, double s, double a,
                                                 double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_AB_PDF evaluates the truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double X, the argument of the PDF.
    //
    //    Input, double MU, S, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //
    //    Output, double NORMAL_TRUNCATED_AB_PDF, the value of the PDF.
    //
    {
        double alpha = (a - mu) / s;
        double beta  = (b - mu) / s;
        double xi    = (x - mu) / s;

        double alpha_cdf = CDF.normal_01_cdf(alpha);
        double beta_cdf  = CDF.normal_01_cdf(beta);
        double xi_pdf    = Normal.normal_01_pdf(xi);

        double pdf = xi_pdf / (beta_cdf - alpha_cdf) / s;

        return(pdf);
    }
Пример #14
0
    public static double normal_truncated_ab_variance(double mu, double s, double a, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_AB_VARIANCE returns the variance of the truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, S, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //
    //    Output, double NORMAL_TRUNCATED_AB_VARIANCE, the variance of the PDF.
    //
    {
        double alpha = (a - mu) / s;
        double beta  = (b - mu) / s;

        double alpha_pdf = Normal.normal_01_pdf(alpha);
        double beta_pdf  = Normal.normal_01_pdf(beta);

        double alpha_cdf = CDF.normal_01_cdf(alpha);
        double beta_cdf  = CDF.normal_01_cdf(beta);

        double variance = s * s * (1.0
                                   + (alpha * alpha_pdf - beta * beta_pdf) / (beta_cdf - alpha_cdf)
                                   - Math.Pow((alpha_pdf - beta_pdf) / (beta_cdf - alpha_cdf), 2));

        return(variance);
    }
Пример #15
0
    public static double half_normal_cdf(double x, double a, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HALF_NORMAL_CDF evaluates the Half Normal CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    17 October 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double X, the argument of the CDF.
    //
    //    Input, double A, B, the parameters of the PDF.
    //    0.0 < B.
    //
    //    Output, double HALF_NORMAL_CDF, the value of the CDF.
    //
    {
        double cdf;

        if (x <= a)
        {
            cdf = 0.0;
        }
        else
        {
            double cdf2 = CDF.normal_cdf(x, a, b);
            cdf = 2.0 * cdf2 - 1.0;
        }

        return(cdf);
    }
Пример #16
0
    public static double normal_truncated_b_mean(double mu, double s, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_B_MEAN returns the mean of the upper truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, S, the mean and standard deviatione of the
    //    parent Normal distribution.
    //
    //    Input, double B, the upper truncation limit.
    //
    //    Output, double NORMAL_TRUNCATED_B_MEAN, the mean of the PDF.
    //
    {
        double beta = (b - mu) / s;

        double beta_cdf = CDF.normal_01_cdf(beta);

        double beta_pdf = Normal.normal_01_pdf(beta);

        double mean = mu - s * beta_pdf / beta_cdf;

        return(mean);
    }
Пример #17
0
    public static double log_normal_sample(double mu, double sigma, ref int seed)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_SAMPLE samples the Log Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 September 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, SIGMA, the parameters of the PDF.
    //    0.0 < SIGMA.
    //
    //    Input/output, int &SEED, a seed for the random number generator.
    //
    //    Output, double LOG_NORMAL_SAMPLE, a sample of the PDF.
    //
    {
        double cdf = UniformRNG.r8_uniform_01(ref seed);

        double x = CDF.log_normal_cdf_inv(cdf, mu, sigma);

        return(x);
    }
Пример #18
0
    public static double normal_truncated_ab_moment(int order, double mu, double sigma,
                                                    double a, double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRUNCATED_NORMAL_AB_MOMENT: moments of the truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 September 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Phoebus Dhrymes,
    //    Moments of Truncated Normal Distributions,
    //    May 2005.
    //
    //  Parameters:
    //
    //    Input, int ORDER, the order of the moment.
    //    0 <= ORDER.
    //
    //    Input, double MU, SIGMA, the mean and standard deviation of the
    //    parent Normal distribution.
    //    0.0 < S.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //    A < B.
    //
    //    Output, double TRUNCATED_NORMAL_AB_MOMENT, the moment of the PDF.
    //
    {
        int r;

        switch (order)
        {
        case < 0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_AB_MOMENT - Fatal error!");
            Console.WriteLine("  ORDER < 0.");
            return(1);
        }

        switch (sigma)
        {
        case <= 0.0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_AB_MOMENT - Fatal error!");
            Console.WriteLine("  SIGMA <= 0.0.");
            return(1);
        }

        if (b <= a)
        {
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_AB_MOMENT - Fatal error!");
            Console.WriteLine("  B <= A.");
            return(1);
        }

        double a_h   = (a - mu) / sigma;
        double a_pdf = Normal.normal_01_pdf(a_h);
        double a_cdf = CDF.normal_01_cdf(a_h);

        switch (a_cdf)
        {
        case 0.0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_AB_MOMENT - Fatal error!");
            Console.WriteLine("  PDF/CDF ratio fails, because A_CDF too small.");
            Console.WriteLine("  A_PDF = " + a_pdf + "");
            Console.WriteLine("  A_CDF = " + a_cdf + "");
            return(1);
        }

        double b_h   = (b - mu) / sigma;
        double b_pdf = Normal.normal_01_pdf(b_h);
        double b_cdf = CDF.normal_01_cdf(b_h);

        switch (b_cdf)
        {
        case 0.0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_AB_MOMENT - Fatal error!");
            Console.WriteLine("  PDF/CDF ratio fails, because B_CDF too small.");
            Console.WriteLine("  B_PDF = " + b_pdf + "");
            Console.WriteLine("  B_CDF = " + b_cdf + "");
            return(1);
        }

        double moment = 0.0;
        double irm2   = 0.0;
        double irm1   = 0.0;

        for (r = 0; r <= order; r++)
        {
            double ir = r switch
            {
                0 => 1.0,
                1 => - (b_pdf - a_pdf) / (b_cdf - a_cdf),
                _ => (r - 1) * irm2 - (Math.Pow(b_h, r - 1) * b_pdf - Math.Pow(a_h, r - 1) * a_pdf) / (b_cdf - a_cdf)
            };

            moment += typeMethods.r8_choose(order, r) * Math.Pow(mu, order - r)
                      * Math.Pow(sigma, r) * ir;

            irm2 = irm1;
            irm1 = ir;
        }

        return(moment);
    }
Пример #19
0
    private static void log_normal_truncated_ab_cdf_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_TRUNCATED_AB_CDF_TEST tests LOG_NORMAL_TRUNCATED_AB_CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 March 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;
        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("LOG_NORMAL_TRUNCATED_AB_CDF_TEST");
        Console.WriteLine("  LOG_NORMAL_TRUNCATED_AB_CDF evaluates the Log Normal Truncated AB CDF;");
        Console.WriteLine("  LOG_NORMAL_TRUNCATED_AB_CDF_INV inverts the Log Normal Truncated AB CDF.");
        Console.WriteLine("  LOG_NORMAL_TRUNCATED_AB_PDF evaluates the Log Normal Truncated AB PDF;");

        double mu    = 0.5;
        double sigma = 3.0;
        double a     = Math.Exp(mu);
        double b     = Math.Exp(mu + 2.0 * sigma);

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter MU =     " + mu + "");
        Console.WriteLine("  PDF parameter SIGMA =  " + sigma + "");
        Console.WriteLine("  PDF parameter A =      " + a + "");
        Console.WriteLine("  PDF parameter B =      " + b + "");

        if (!PDF.log_normal_truncated_ab_check(mu, sigma, a, b))
        {
            Console.WriteLine("");
            Console.WriteLine("LOG_NORMAL_TRUNCATED_AB_CDF_TEST - Fatal error!");
            Console.WriteLine("  The parameters are not legal.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("       X            PDF           CDF            CDF_INV");
        Console.WriteLine("");

        for (i = 1; i <= 10; i++)
        {
            double x   = PDF.log_normal_truncated_ab_sample(mu, sigma, a, b, ref seed);
            double pdf = PDF.log_normal_truncated_ab_pdf(x, mu, sigma, a, b);
            double cdf = CDF.log_normal_truncated_ab_cdf(x, mu, sigma, a, b);
            double x2  = CDF.log_normal_truncated_ab_cdf_inv(cdf, mu, sigma, a, b);

            Console.WriteLine("  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(12)
                              + "  " + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(12)
                              + "  " + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(12)
                              + "  " + x2.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
Пример #20
0
        private XmlElement ConvertToXML()
        {
            XmlDocument doc = new System.Xml.XmlDocument();

            return(CDF.ToXml(doc));
        }
Пример #21
0
    public static double normal_truncated_b_moment(int order, double mu, double sigma, double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRUNCATED_NORMAL_B_MOMENT: moments of the upper truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 September 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Phoebus Dhrymes,
    //    Moments of Truncated Normal Distributions,
    //    May 2005.
    //
    //  Parameters:
    //
    //    Input, int ORDER, the order of the moment.
    //    0 <= ORDER.
    //
    //    Input, double MU, SIGMA, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double B, the upper truncation limit.
    //
    //    Output, double TRUNCATED_NORMAL_B_MOMENT, the moment of the PDF.
    //
    {
        int r;

        switch (order)
        {
        case < 0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_B_MOMENT - Fatal error!");
            Console.WriteLine("  ORDER < 0.");
            return(1);
        }

        double h     = (b - mu) / sigma;
        double h_pdf = Normal.normal_01_pdf(h);
        double h_cdf = CDF.normal_01_cdf(h);

        switch (h_cdf)
        {
        case 0.0:
            Console.WriteLine("");
            Console.WriteLine("TRUNCATED_NORMAL_B_MOMENT - Fatal error!");
            Console.WriteLine("  CDF((B-MU)/SIGMA) = 0.");
            return(1);
        }

        double f = h_pdf / h_cdf;

        double moment = 0.0;
        double irm2   = 0.0;
        double irm1   = 0.0;

        for (r = 0; r <= order; r++)
        {
            double ir = r switch
            {
                0 => 1.0,
                1 => - f,
                _ => - Math.Pow(h, r - 1) * f + (r - 1) * irm2
            };

            moment += typeMethods.r8_choose(order, r) * Math.Pow(mu, order - r)
                      * Math.Pow(sigma, r) * ir;

            irm2 = irm1;
            irm1 = ir;
        }

        return(moment);
    }
Пример #22
0
    private static void normal_cdf_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_CDF_TEST tests NORMAL_CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;
        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_CDF_TEST");
        Console.WriteLine("  NORMAL_CDF evaluates the Normal CDF;");
        Console.WriteLine("  NORMAL_CDF_INV inverts the Normal CDF.");
        Console.WriteLine("  NORMAL_PDF evaluates the Normal PDF;");

        const double mu    = 100.0;
        const double sigma = 15.0;

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter MU =    " + mu + "");
        Console.WriteLine("  PDF parameter SIGMA = " + sigma + "");

        if (!Normal.normal_check(mu, sigma))
        {
            Console.WriteLine("");
            Console.WriteLine("NORMAL_CDF_TEST - Fatal error!");
            Console.WriteLine("  The parameters are not legal.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("       X            PDF           CDF            CDF_INV");
        Console.WriteLine("");

        for (i = 1; i <= 10; i++)
        {
            double x   = Normal.normal_sample(mu, sigma, ref seed);
            double pdf = Normal.normal_pdf(x, mu, sigma);
            double cdf = CDF.normal_cdf(x, mu, sigma);
            double x2  = CDF.normal_cdf_inv(cdf, mu, sigma);

            Console.WriteLine("  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + x2.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
Пример #23
0
    public static double log_normal_truncated_ab_pdf(double x, double mu, double sigma,
                                                     double a, double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_TRUNCATED_AB_PDF evaluates the Log Normal truncated AB PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 March 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double X, the argument of the PDF.
    //    0.0 < X
    //
    //    Input, double MU, SIGMA, the parameters of the PDF.
    //    0.0 < SIGMA.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //    A < B.
    //
    //    Output, double LOG_NORMAL_TRUNCATED_AB_PDF, the value of the PDF.
    //
    {
        double pdf;

        bool check = log_normal_truncated_ab_check(mu, sigma, a, b);

        switch (check)
        {
        case false:
            Console.WriteLine("");
            Console.WriteLine("LOG_NORMAL_TRUNCATED_AB_PDF - Fatal error!");
            Console.WriteLine("  Parameters are not legal.");
            return(1);
        }

        if (x <= a)
        {
            pdf = 0.0;
        }
        else if (b <= x)
        {
            pdf = 0.0;
        }
        else
        {
            double lncdf_a = CDF.log_normal_cdf(a, mu, sigma);
            double lncdf_b = CDF.log_normal_cdf(b, mu, sigma);
            double lnpdf_x = log_normal_pdf(x, mu, sigma);

            pdf = lnpdf_x / (lncdf_b - lncdf_a);
        }

        return(pdf);
    }