コード例 #1
0
        public void CanSampleSequence()
        {
            var n   = new Cauchy();
            var ied = n.Samples();

            GC.KeepAlive(ied.Take(5).ToArray());
        }
コード例 #2
0
        public void CanCreateCauchy(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            Assert.AreEqual(location, n.Location);
            Assert.AreEqual(scale, n.Scale);
        }
コード例 #3
0
        public void CanCreateCauchy()
        {
            var n = new Cauchy();

            Assert.AreEqual(0.0, n.Location);
            Assert.AreEqual(1.0, n.Scale);
        }
コード例 #4
0
ファイル: CauchyTests.cs プロジェクト: wibble82/mmbot
        public void CanCreateCauchy([Values(0.0, 0.0, 0.0, 10.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 11.0, 100.0, Double.PositiveInfinity)] double scale)
        {
            var n = new Cauchy(location, scale);

            Assert.AreEqual(location, n.Location);
            Assert.AreEqual(scale, n.Scale);
        }
コード例 #5
0
        public void FunctionTest()
        {
            Cauchy       dense  = new Cauchy(3.6);
            SparseCauchy target = new SparseCauchy(3.6);

            double[] sx = { 1, -0.555556, 2, +0.250000, 3, -0.864407, 4, -0.916667 };
            double[] sy = { 1, -0.666667, 2, -0.166667, 3, -0.864407, 4, -0.916667 };
            double[] sz = { 1, -0.944444, 3, -0.898305, 4, -0.916667 };

            double[] dx = { -0.555556, +0.250000, -0.864407, -0.916667 };
            double[] dy = { -0.666667, -0.166667, -0.864407, -0.916667 };
            double[] dz = { -0.944444, +0.000000, -0.898305, -0.916667 };

            double expected, actual;

            expected = dense.Function(dx, dy);
            actual   = target.Function(sx, sy);
            Assert.AreEqual(expected, actual);

            expected = dense.Function(dx, dz);
            actual   = target.Function(sx, sz);
            Assert.AreEqual(expected, actual);

            expected = dense.Function(dy, dz);
            actual   = target.Function(sy, sz);
            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void ValidateToString()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            var n = new Cauchy(1d, 2d);

            Assert.AreEqual("Cauchy(x0 = 1, γ = 2)", n.ToString());
        }
コード例 #7
0
 /// <summary>
 /// Samples from a Cauchy distribution.
 /// </summary>
 /// <param name="location">The distribution's location.</param>
 /// <param name="scale">The distribution's scale.</param>
 /// <returns>The generated sample.</returns>
 public double SampleFromCauchyDistribution(double location, double scale)
 {
     lock (this._random)
     {
         var distribution = new Cauchy(location, scale, this._random);
         return(distribution.Sample());
     }
 }
コード例 #8
0
        public void ValidateCumulativeDistribution(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var x = i - 5.0;
                Assert.AreEqual(((1.0 / Constants.Pi) * Math.Atan((x - location) / scale)) + 0.5, n.CumulativeDistribution(x));
            }
        }
コード例 #9
0
        public void ValidateDensityLn(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var x = i - 5.0;
                Assert.AreEqual(-Math.Log((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.DensityLn(x));
            }
        }
コード例 #10
0
        public void ValidateDensity(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (int i = 0; i < 11; i++)
            {
                double x = i - 5.0;
                Assert.AreEqual <double>(1.0 / (Constants.Pi * scale * (1.0 + ((x - location) / scale) * ((x - location) / scale))), n.Density(x));
            }
        }
コード例 #11
0
ファイル: CauchyTests.cs プロジェクト: wibble82/mmbot
        public void ValidateDensityLn([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var x = i - 5.0;
                Assert.AreEqual(-Math.Log((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.DensityLn(x));
            }
        }
コード例 #12
0
ファイル: CauchyTests.cs プロジェクト: wibble82/mmbot
        public void ValidateCumulativeDistribution([Values(0.0, 0.0, 0.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var x = i - 5.0;
                Assert.AreEqual(((1.0 / Constants.Pi) * Math.Atan((x - location) / scale)) + 0.5, n.CumulativeDistribution(x));
            }
        }
コード例 #13
0
        public void ValidateDensity(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var    x        = i - 5.0;
                double expected = 1.0 / ((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale))));
                Assert.AreEqual(expected, n.Density(x));
                Assert.AreEqual(expected, Cauchy.PDF(location, scale, x));
            }
        }
コード例 #14
0
        public void ValidateInverseCumulativeDistribution(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            for (var i = 0; i < 11; i++)
            {
                var    x        = i - 5.0;
                double expected = (Math.Atan((x - location) / scale)) / Math.PI + 0.5;
                Assert.AreEqual(x, n.InverseCumulativeDistribution(expected), 1e-12);
                Assert.AreEqual(x, Cauchy.InvCDF(location, scale, expected), 1e-12);
            }
        }
コード例 #15
0
    public static void cauchy_cdf_values_test( )
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CAUCHY_CDF_VALUES_TEST tests CAUCHY_CDF_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 March 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx    = 0;
        double mu    = 0;
        double sigma = 0;
        double x     = 0;

        Console.WriteLine("");
        Console.WriteLine("CAUCHY_CDF_VALUES_TEST:");
        Console.WriteLine("  CAUCHY_CDF_VALUES returns values of ");
        Console.WriteLine("  the Cauchy Cumulative Density Function.");
        Console.WriteLine("");
        Console.WriteLine("     Mu      Sigma        X   CDF(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Cauchy.cauchy_cdf_values(ref n_data, ref mu, ref sigma, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + mu.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + sigma.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
コード例 #16
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Cauchy_distribution">Cauchy distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the Cauchy distribution class with parameters Location = 1 and Scale = 2.
            var cauchy = new Cauchy(1, 2);

            Console.WriteLine(@"1. Initialize the new instance of the Cauchy distribution class with parameters Location = {0} and Scale = {1}", cauchy.Location, cauchy.Scale);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", cauchy);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", cauchy.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", cauchy.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", cauchy.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", cauchy.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", cauchy.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", cauchy.Minimum.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", cauchy.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", cauchy.Mode.ToString(" #0.00000;-#0.00000"));

            // 3. Generate 10 samples of the Cauchy distribution
            Console.WriteLine(@"3. Generate 10 samples of the Cauchy distribution");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(cauchy.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
        }
コード例 #17
0
        public void ValidateToString()
        {
            var n = new Cauchy(1.0, 2.0);

            Assert.AreEqual("Cauchy(Location = 1, Scale = 2)", n.ToString());
        }
コード例 #18
0
        public void CanSample()
        {
            var n = new Cauchy();

            n.Sample();
        }
コード例 #19
0
 public void CanSampleSequence()
 {
     var n = new Cauchy();
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
コード例 #20
0
 public void ValidateToString()
 {
     var n = new Cauchy(1.0, 2.0);
     Assert.AreEqual("Cauchy(Location = 1, Scale = 2)", n.ToString());
 }
コード例 #21
0
        public void SetBadScaleFail()
        {
            var n = new Cauchy();

            Assert.Throws <ArgumentOutOfRangeException>(() => n.Scale = -1.0);
        }
コード例 #22
0
 public void SetScaleFail()
 {
     var n = new Cauchy();
     n.Scale = -1.0;
 }
コード例 #23
0
        public void SetBadScaleFail()
        {
            var n = new Cauchy();

            Assert.That(() => n.Scale = -1.0, Throws.ArgumentException);
        }
コード例 #24
0
        public void SetBadLocationFail()
        {
            var n = new Cauchy();

            Assert.Throws <ArgumentOutOfRangeException>(() => n.Location = Double.NaN);
        }
コード例 #25
0
        public void SetBadLocationFail()
        {
            var n = new Cauchy();

            Assert.That(() => n.Location = Double.NaN, Throws.ArgumentException);
        }
コード例 #26
0
 public void CanSetScale(double scale)
 {
     var n = new Cauchy();
     n.Scale = scale;
 }
コード例 #27
0
 public void CanSetLocation(double location)
 {
     var n = new Cauchy();
     n.Location = location;
 }
コード例 #28
0
 public void ValidateSkewness(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual<double>(0.0, n.Skewness);
 }
コード例 #29
0
 public void ValidateEntropy(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(Math.Log(4.0 * Constants.Pi * scale), n.Entropy);
 }
コード例 #30
0
 public void ValidateDensityLn([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(-Math.Log((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.DensityLn(x));
     }
 }
コード例 #31
0
 public void ValidateMedian(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(location, n.Median);
 }
コード例 #32
0
 public void CanCreateCauchy()
 {
     var n = new Cauchy();
     Assert.AreEqual(0.0, n.Location);
     Assert.AreEqual(1.0, n.Scale);
 }
コード例 #33
0
 public void ValidateMaximum(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
コード例 #34
0
 public void ValidateMinimum(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual<double>(Double.NegativeInfinity, n.Minimum);
 }
コード例 #35
0
 public void ValidateDensityLn(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(-Math.Log((Constants.Pi * scale) * (1.0 + (((x - location) / scale) * ((x - location) / scale)))), n.DensityLn(x));
     }
 }
コード例 #36
0
 public void SetLocationFail()
 {
     var n = new Cauchy();
     n.Location = Double.NaN;
 }
コード例 #37
0
 public void ValidateCumulativeDistribution(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(((1.0 / Constants.Pi) * Math.Atan((x - location) / scale)) + 0.5, n.CumulativeDistribution(x));
     }
 }
コード例 #38
0
 public void CauchyCreateFailsWithBadParameters(double location, double scale)
 {
     var n = new Cauchy(location, scale);
 }
コード例 #39
0
 public void CanCreateCauchy(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(location, n.Location);
     Assert.AreEqual(scale, n.Scale);
 }
コード例 #40
0
        public void ValidateToString()
        {
            var n = new Cauchy(1d, 2d);

            Assert.AreEqual("Cauchy(x0 = 1, γ = 2)", n.ToString());
        }
コード例 #41
0
 public void SetBadScaleFail()
 {
     var n = new Cauchy();
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = -1.0);
 }
コード例 #42
0
        public void Test_Randomized_Data()
        {
            #region Data Generators...

            Random rnd = null;             // initialized later

            var        dfFlips   = new Cauchy(10, 4, rnd);
            Func <int> makeFlips = () =>
            {
                int x = 0;
                while (x <= 0 || x >= 30)
                {
                    x = (int)Math.Floor(dfFlips.Sample());
                }
                return(x);
            };

            var           dfElev        = new Cauchy(10, 1, rnd);
            Func <double> makeElevation = () =>
            {
                double x = 0;
                while (x <= 0.0 || x >= 30)
                {
                    x = dfElev.Sample();
                }
                return(x);
            };

            bool        flipFlop     = false;
            Func <bool> makeFlipFlop = () =>
            {
                if (rnd.NextDouble() < 0.01)
                {
                    flipFlop = !flipFlop;
                }
                return(flipFlop);
            };

            var cities = new[]
            {
                "Paris", "Marseilles", "Lyon", "Toulouse", "Nice",
                "Nantes", "Strasbourg", "Montpellier", "Bordeaux", "Lille",
                "Rennes", "Reims", "Le Havre", "Saint-Étienne", "Toulon",
                "Grenoble", "Dijon", "Angers", "Saint-Denis", "Villeurbanne",
                "Nîmes", "Le Mans", "Clermont-Ferrand", "Aix-en-Provence", "Brest"
            };
            var           dfLoc        = new Cauchy(0, 1.25, rnd);
            Func <string> makeLocation = () =>
            {
                int x = cities.Length;
                while (x >= cities.Length)
                {
                    x = (int)Math.Floor(Math.Abs(dfLoc.Sample()));
                }
                return(cities[x]);
            };
            Func <int>  makeHeadsOrTails = () => rnd.NextDouble() < 0.01 ? CoinToss.EDGE : rnd.NextDouble() <= 0.5 ? CoinToss.HEAD : CoinToss.TAIL;           // biased!
            Func <bool> makeValid        = () => rnd.Next(1000) != 666;

            #endregion

            //foreach (var N in new[] { 1000, 2000, 5000, 10 * 1000, 20 * 1000, 50 * 1000, 100 * 1000 })
            const int N = 10 * 1000;
            {
                Console.WriteLine("=================================================================================================================================================================================================================================");
                Console.WriteLine("N = {0:N0}", N);
                Console.WriteLine("=================================================================================================================================================================================================================================");

                rnd = new Random(123456);

                var dataSet = Enumerable
                              .Range(0, N)
                              .Select(i => new KeyValuePair <int, CoinToss>(i, new CoinToss
                {
                    Id        = Guid.NewGuid(),
                    Valid     = makeValid(),
                    Result    = makeHeadsOrTails(),
                    Flips     = makeFlips(),
                    Elevation = makeElevation(),
                    Location  = makeLocation(),
                    Daytime   = makeFlipFlop(),
                }))
                              .ToList();

                var indexLoc       = new MemoryIndex <string>(StringComparer.Ordinal);
                var indexValid     = new MemoryIndex <bool>();
                var indexResult    = new MemoryIndex <int>();
                var indexFlips     = new MemoryIndex <int>();
                var indexElevation = new MemoryIndex <double>();                // quantized!
                var indexFlipFlop  = new MemoryIndex <bool>();

                var inserters = new []
                {
                    MakeInserter <KeyValuePair <int, CoinToss>, int>(indexResult, (kv) => kv.Key, (kv) => kv.Value.Result),
                    MakeInserter <KeyValuePair <int, CoinToss>, bool>(indexValid, (kv) => kv.Key, (kv) => kv.Value.Valid),
                    MakeInserter <KeyValuePair <int, CoinToss>, bool>(indexFlipFlop, (kv) => kv.Key, (kv) => kv.Value.Daytime),
                    MakeInserter <KeyValuePair <int, CoinToss>, int>(indexFlips, (kv) => kv.Key, (kv) => kv.Value.Flips),
                    MakeInserter <KeyValuePair <int, CoinToss>, double>(indexElevation, (kv) => kv.Key, (kv) => Math.Round(kv.Value.Elevation, 1, MidpointRounding.AwayFromZero)),
                    MakeInserter <KeyValuePair <int, CoinToss>, string>(indexLoc, (kv) => kv.Key, (kv) => kv.Value.Location),
                };

                var database = new Dictionary <int, CoinToss>();
                //Console.Write("Inserting data: ...");
                foreach (var data in dataSet)
                {
                    //if (database.Count % 1000 == 0) Console.Write("\rInserting data: {0} / {1}", database.Count, N);
                    database[data.Key] = data.Value;
                    foreach (var inserter in inserters)
                    {
                        inserter(data);
                    }
                }
                //Console.WriteLine("\rInserting data: {0} / {1}", database.Count, N);

                Console.WriteLine();
                DumpIndex("Result", indexResult, (s, _) => s, heatMaps: true);

                Console.WriteLine();
                DumpIndex("Valid", indexValid, (s, _) => s, heatMaps: true);

                Console.WriteLine();
                DumpIndex("FlipFlops", indexFlipFlop, (s, _) => s, heatMaps: true);

                Console.WriteLine();
                DumpIndex("Flips", indexFlips, (s, _) => s, heatMaps: true);

                Console.WriteLine();
                DumpIndex("Location", indexLoc, (_, n) => - n, heatMaps: true);

                Console.WriteLine();
                DumpIndex("Elevation", indexElevation, (s, _) => s, heatMaps: true);

                //Console.WriteLine(indexValid.Values[true].Dump());
                //Console.WriteLine(indexValid.Values[true].ToSlice().ToHexaString());
                Console.WriteLine();
                Console.WriteLine();
            }
        }
コード例 #43
0
 public void ValidateSkewnessThrowsNotSupportedException()
 {
     var n = new Cauchy(-0.0, 2.0);
     Assert.Throws<NotSupportedException>(() => { var s = n.Skewness; });
 }
コード例 #44
0
 public void SetBadLocationFail()
 {
     var n = new Cauchy();
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Location = Double.NaN);
 }
コード例 #45
0
 public void ValidateMode(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual<double>(location, n.Mode);
 }
コード例 #46
0
 public void ValidateEntropy([Values(-0.0, 0.0, 0.1, 1.0, 10.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0)] double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(Math.Log(4.0 * Constants.Pi * scale), n.Entropy);
 }
コード例 #47
0
ファイル: Cauchy.cs プロジェクト: philstopford/DesignLibs_GPL
    private static void cauchy_cdf_test()

//****************************************************************************80
//
//  Purpose:
//
//    CAUCHY_CDF_TEST tests CAUCHY_CDF, CAUCHY_CDF_INV, CAUCHY_PDF;
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    26 August 2006
//
//  Author:
//
//    John Burkardt
//
    {
        int i;
        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("CAUCHY_CDF_TEST");
        Console.WriteLine("  CAUCHY_CDF evaluates the Cauchy CDF;");
        Console.WriteLine("  CAUCHY_CDF_INV inverts the Cauchy CDF.");
        Console.WriteLine("  CAUCHY_PDF evaluates the Cauchy PDF;");

        const double a = 2.0;
        const double b = 3.0;

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter A =      " + a + "");
        Console.WriteLine("  PDF parameter B =      " + b + "");

        if (!Cauchy.cauchy_check(a, b))
        {
            Console.WriteLine("");
            Console.WriteLine("CAUCHY_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   = Cauchy.cauchy_sample(a, b, ref seed);
            double pdf = Cauchy.cauchy_pdf(x, a, b);
            double cdf = Cauchy.cauchy_cdf(x, a, b);
            double x2  = Cauchy.cauchy_cdf_inv(cdf, 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) + "");
        }
    }
コード例 #48
0
 public void ValidateMaximum([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
コード例 #49
0
        public void ValidateEntropy(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            Assert.AreEqual(Math.Log(4.0 * Constants.Pi * scale), n.Entropy);
        }
コード例 #50
0
 public void CanSample()
 {
     var n = new Cauchy();
     n.Sample();
 }
コード例 #51
0
        public void ValidateSkewnessThrowsNotSupportedException()
        {
            var n = new Cauchy(-0.0, 2.0);

            Assert.Throws <NotSupportedException>(() => { var s = n.Skewness; });
        }
コード例 #52
0
 public void ValidateCumulativeDistribution([Values(0.0, 0.0, 0.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double scale)
 {
     var n = new Cauchy(location, scale);
     for (var i = 0; i < 11; i++)
     {
         var x = i - 5.0;
         Assert.AreEqual(((1.0 / Constants.Pi) * Math.Atan((x - location) / scale)) + 0.5, n.CumulativeDistribution(x));
     }
 }
コード例 #53
0
        public void ValidateMedian(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            Assert.AreEqual(location, n.Median);
        }
コード例 #54
0
 public void CanCreateCauchy([Values(0.0, 0.0, 0.0, 10.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 11.0, 100.0, Double.PositiveInfinity)] double scale)
 {
     var n = new Cauchy(location, scale);
     Assert.AreEqual(location, n.Location);
     Assert.AreEqual(scale, n.Scale);
 }
コード例 #55
0
        public void ValidateMaximum(double location, double scale)
        {
            var n = new Cauchy(location, scale);

            Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
        }
コード例 #56
0
ファイル: Cauchy.cs プロジェクト: philstopford/DesignLibs_GPL
    private static void cauchy_sample_test()

//****************************************************************************80
//
//  Purpose:
//
//    CAUCHY_SAMPLE_TEST tests CAUCHY_MEAN, CAUCHY_SAMPLE, CAUCHY_VARIANCE;
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    26 August 2006
//
//  Author:
//
//    John Burkardt
//
    {
        const int SAMPLE_NUM = 1000;

        int i;
        int seed = 123456789;

        double[] x = new double [SAMPLE_NUM];

        Console.WriteLine("");
        Console.WriteLine("CAUCHY_SAMPLE_TEST");
        Console.WriteLine("  CAUCHY_MEAN computes the Cauchy mean;");
        Console.WriteLine("  CAUCHY_SAMPLE samples the Cauchy distribution;");
        Console.WriteLine("  CAUCHY_VARIANCE computes the Cauchy variance;");

        const double a = 2.0;
        const double b = 3.0;

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter A =      " + a + "");
        Console.WriteLine("  PDF parameter B =      " + b + "");

        if (!Cauchy.cauchy_check(a, b))
        {
            Console.WriteLine("");
            Console.WriteLine("CAUCHY_SAMPLE_TEST - Fatal error!");
            Console.WriteLine("  The parameters are not legal.");
            return;
        }

        double mean     = Cauchy.cauchy_mean(a, b);
        double variance = Cauchy.cauchy_variance(a, b);

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

        for (i = 0; i < SAMPLE_NUM; i++)
        {
            x[i] = Cauchy.cauchy_sample(a, 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 + "");
    }
コード例 #57
0
 public void ValidateDensity(double location, double scale)
 {
     var n = new Cauchy(location, scale);
     for (int i = 0; i < 11; i++)
     {
         double x = i - 5.0;
         Assert.AreEqual<double>(1.0 / (Constants.Pi * scale * (1.0 + ((x - location) / scale) * ((x - location) / scale))), n.Density(x));
     }
 }