示例#1
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);
    }
示例#2
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);
    }
示例#3
0
    private static void log_normal_cdf_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOG_NORMAL_CDF_TEST tests LOG_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("LOG_NORMAL_CDF_TEST");
        Console.WriteLine("  LOG_NORMAL_CDF evaluates the Log Normal CDF;");
        Console.WriteLine("  LOG_NORMAL_CDF_INV inverts the Log Normal CDF.");
        Console.WriteLine("  LOG_NORMAL_PDF evaluates the Log Normal PDF;");

        const double mu    = 10.0;
        const double sigma = 2.25;

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

        if (!PDF.log_normal_check(mu, sigma))
        {
            Console.WriteLine("");
            Console.WriteLine("LOG_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   = PDF.log_normal_sample(mu, sigma, ref seed);
            double pdf = PDF.log_normal_pdf(x, mu, sigma);
            double cdf = CDF.log_normal_cdf(x, mu, sigma);
            double x2  = CDF.log_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) + "");
        }
    }