コード例 #1
0
    private static void normal_truncated_a_cdf_test()

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

        const double a    = 50.0;
        const double mu   = 100.0;
        const double s    = 25.0;
        int          seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_TRUNCATED_A_CDF_TEST");
        Console.WriteLine("  NORMAL_TRUNCATED_A_CDF evaluates the Normal Truncated A CDF.");
        Console.WriteLine("  NORMAL_TRUNCATED_A_CDF_INV inverts the Normal Truncated A CDF.");
        Console.WriteLine("  NORMAL_TRUNCATED_A_PDF evaluates the Normal Truncated A 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 [" + a + ",+oo]");

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

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

            double pdf = Truncated.normal_truncated_a_pdf(x, mu, s, a);

            double cdf = CDF.normal_truncated_a_cdf(x, mu, s, a);

            double x2 = CDF.normal_truncated_a_cdf_inv(cdf, mu, s, a);

            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) + "");
        }
    }
コード例 #2
0
    private static void normal_truncated_a_sample_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_A_SAMPLE_TEST tests NORMAL_TRUNCATED_A_SAMPLE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       i;
        const int sample_num = 1000;

        double[] x = new double[sample_num];

        const double a    = 50.0;
        const double mu   = 100.0;
        const double s    = 25.0;
        int          seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_TRUNCATED_A_SAMPLE_TEST");
        Console.WriteLine("  NORMAL_TRUNCATED_A_MEAN computes the Normal Truncated A mean;");
        Console.WriteLine("  NORMAL_TRUNCATED_A_SAMPLE samples the Normal Truncated A distribution;");
        Console.WriteLine("  NORMAL_TRUNCATED_A_VARIANCE computes the Normal Truncated A variance.");
        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 [" + a + ",+oo]");

        double mean = Truncated.normal_truncated_a_mean(mu, s, a);

        double variance = Truncated.normal_truncated_a_variance(mu, s, a);

        Console.WriteLine("");
        Console.WriteLine("  PDF mean      =               " + mean + "");
        Console.WriteLine("  PDF variance =                " + variance + "");

        for (i = 0; i < sample_num; i++)
        {
            x[i] = Truncated.normal_truncated_a_sample(mu, s, a, ref seed);
        }

        mean     = typeMethods.r8vec_mean(sample_num, x);
        variance = typeMethods.r8vec_variance(sample_num, x);
        double xmax = typeMethods.r8vec_max(sample_num, x);
        double xmin = typeMethods.r8vec_min(sample_num, x);

        Console.WriteLine("");
        Console.WriteLine("  Sample size =     " + sample_num + "");
        Console.WriteLine("  Sample mean =     " + mean + "");
        Console.WriteLine("  Sample variance = " + variance + "");
        Console.WriteLine("  Sample maximum =  " + xmax + "");
        Console.WriteLine("  Sample minimum =  " + xmin + "");
    }