コード例 #1
0
        private static RealVector GenerateRandomInSpere(RealVector currentPoint, double radius, Area area)
        {
            RealVector normallyDistributed = gorn.GetNormalVector(area.ToDictionary(kvp => kvp.Key, kvp => Tuple.Create(0.0, 1.0)));
            var        r = Math.Sqrt(normallyDistributed.Elements.Values.Select(v => v * v).Sum());

            RealVector shift          = (normallyDistributed * (gorn.GetContinuousUniform(0.0, radius) / r)).Elements;
            RealVector generatedPoint = (currentPoint + shift).Elements;

            return(generatedPoint.Constrain(area));
        }
コード例 #2
0
        static void TestNormalAndStatistic()
        {
            var mu_sigma_x = Tuple.Create(17.0, 7.0);
            var mu_sigma_y = Tuple.Create(7.0, 17.0);
            var prob       = new Dictionary <string, Tuple <double, double> >
            {
                { "x", mu_sigma_x },
                { "y", mu_sigma_y }
            };

            int  maxAttempts = 10;
            bool result      = false;

            for (int i = 0; i < maxAttempts && !result; ++i)
            {
                var samples = new List <Dictionary <string, double> >();
                for (int j = 0; j < N; ++j)
                {
                    samples.Add(gorn.GetNormalVector(prob));
                }

                var x = samples.Select(kvp => kvp["x"]);
                var y = samples.Select(kvp => kvp["y"]);

                var muEst_x    = Statistics.GetMean(x);
                var sigmaEst_x = Statistics.GetUnbiasedSigma(x);
                var muEst_y    = Statistics.GetMean(y);
                var sigmaEst_y = Statistics.GetUnbiasedSigma(y);

                var success_mu_x    = Math.Abs(mu_sigma_x.Item1 - muEst_x) < eps;
                var success_mu_y    = Math.Abs(mu_sigma_y.Item1 - muEst_y) < eps;
                var success_sigma_x = Math.Abs(mu_sigma_x.Item2 - sigmaEst_x) < eps;
                var success_sigma_y = Math.Abs(mu_sigma_y.Item2 - sigmaEst_y) < eps;

                result = success_mu_x && success_mu_y && success_sigma_x && success_sigma_y;
            }

            Assert.True(result);
        }