예제 #1
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) + "");
        }
    }
예제 #2
0
    public static void truncated_normal_ab_cdf_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRUNCATED_NORMAL_AB_CDF_VALUES_TEST tests TRUNCATED_NORMAL_AB_CDF_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    13 September 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double a     = 0;
        double b     = 0;
        double fx    = 0;
        double mu    = 0;
        double sigma = 0;
        double x     = 0;

        Console.WriteLine("");
        Console.WriteLine("TRUNCATED_NORMAL_AB_CDF_VALUES_TEST:");
        Console.WriteLine("  TRUNCATED_NORMAL_AB_CDF_VALUES stores values of");
        Console.WriteLine("  the Truncated Normal Cumulative Density Function.");
        Console.WriteLine("");
        Console.WriteLine("        MU     SIGMA       A         B         X        CDF(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Truncated.truncated_normal_ab_cdf_values(ref n_data, ref mu, ref sigma, ref a, ref b, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  " + mu.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + sigma.ToString(CultureInfo.InvariantCulture).PadLeft(8) + sigma
                              + "  " + a.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + b.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
예제 #3
0
            public static uint Decode(Bitstream bitstream, uint m)
            {
                Trace.Assert(m > 0);
                var q = 0U;

                while (bitstream.Read(1) == 1)
                {
                    ++q;
                }
                uint r = Truncated.Decode(bitstream, m);

                return(q * m + r);
            }
예제 #4
0
            /// <summary>
            /// Golomb code, useful for geometric distributions
            ///
            /// encode values using int parameter m
            /// value N is encoded via: q=Floor(N/M),r=N%M,
            /// q 1's, then one 0, then Log2M bits for r
            /// good for geometric distribution
            ///
            /// </summary>
            /// <returns></returns>
            public static void Encode(Bitstream bitstream, uint value, uint m)
            {
                Trace.Assert(m > 0);
                var n = value;
                var q = n / m;
                var r = n % m;

                for (var i = 1; i <= q; ++i)
                {
                    bitstream.Write(1);
                }
                bitstream.Write(0);
                Truncated.Encode(bitstream, r, m);
            }
예제 #5
0
    public static double[] moments_truncated_normal_b(int m, double mu, double sigma,
                                                      double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MOMENTS_TRUNCATED_NORMAL_B: moments of upper truncated Normal.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 September 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int M, the number of moments desired.
    //
    //    Input, double MU, SIGMA, the mean and standard deviation.
    //
    //    Input, double B, the upper truncation limit.
    //    A < B.
    //
    //    Output, double W(0:M-1), the weighted integrals of X^0
    //    through X^(M-1).
    //
    {
        int order;

        double[] w = new double[m];

        for (order = 0; order < m; order++)
        {
            w[order] = Truncated.truncated_normal_b_moment(order, mu, sigma, b);
        }

        return(w);
    }
예제 #6
0
        protected override void ProcessRecord()
        {
            var ctl = new PsMessage();

            SetControlProps(ctl);

            ctl.OnDismiss = OnDismiss;
            ctl.Value     = Value;

            if (Multiline.IsPresent)
            {
                ctl.Multiline = Multiline.ToBool();
            }

            if (Truncated.IsPresent)
            {
                ctl.Truncated = Truncated.ToBool();
            }

            if (Dismiss.IsPresent)
            {
                ctl.Dismiss = Dismiss.ToBool();
            }

            if (Type.HasValue)
            {
                ctl.Type = Type.Value;
            }

            if (Buttons != null)
            {
                foreach (var button in Buttons)
                {
                    ctl.Buttons.Add(button);
                }
            }

            WriteObject(ctl);
        }
예제 #7
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (bodyTypeCase_ == BodyTypeOneofCase.AsBytes)
            {
                hash ^= AsBytes.GetHashCode();
            }
            if (bodyTypeCase_ == BodyTypeOneofCase.AsString)
            {
                hash ^= AsString.GetHashCode();
            }
            if (Truncated != false)
            {
                hash ^= Truncated.GetHashCode();
            }
            hash ^= (int)bodyTypeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #8
0
    private static void normal_truncated_b_sample_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_B_SAMPLE_TEST tests NORMAL_TRUNCATED_B_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 b    = 150.0;
        const double mu   = 100.0;
        const double s    = 25.0;
        int          seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_TRUNCATED_B_SAMPLE_TEST");
        Console.WriteLine("  NORMAL_TRUNCATED_B_MEAN computes the Normal Truncated B mean;");
        Console.WriteLine("  NORMAL_TRUNCATED_B_SAMPLE samples the Normal Truncated B distribution;");
        Console.WriteLine("  NORMAL_TRUNCATED_B_VARIANCE computes the Normal Truncated B 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 [-oo," + b + "]");

        double mean = Truncated.normal_truncated_b_mean(mu, s, b);

        double variance = Truncated.normal_truncated_b_variance(mu, s, b);

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

        for (i = 0; i < sample_num; i++)
        {
            x[i] = Truncated.normal_truncated_b_sample(mu, s, b, 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 + "");
    }