/// <summary>
        /// multivariate normal distribution example
        /// </summary>
        public static void Example()
        {
            // init a bivariate normal distribution
            double[,] D = { { 1.9, 0 },
                            { 0, 1.9 } };
            double[] m = { 1, 2 };
            PZMath_matrix sigam1 = new PZMath_matrix(D);
            PZMath_vector mu1 = new PZMath_vector(m);

            MultivariateNormalDistribution BND = new MultivariateNormalDistribution(mu1, sigam1);

            // sample
            string filename1 = "v1.txt";
            FileStream fs1 = new FileStream(filename1, FileMode.Create, FileAccess.Write);
            StreamWriter w1 = new StreamWriter(fs1);
            for (int i = 0; i < 10000; i++)
            {
                double[] sample = BND.Sample();
                w1.Write(sample[0]);
                w1.Write("        ");
                w1.WriteLine(sample[1]);
            }
            w1.Close();
            fs1.Close();

            // evalualte
            double[] x = { 1.5, 2.5 };
            double value = BND.Evaluate(x);
            // correct answer
            // value = 0.0734
            Console.WriteLine(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// example target distribution function
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        private static double ExampleTargetDistributionFunction(double[] x)
        {
            //double[,] S = { { 1, 0.9 }, { 0.9, 1 } };
            double[,] S = { { 2, 0 }, { 0, 1 } };
            double[] m = { 1, 2 };
            PZMath_matrix targetSigma = new PZMath_matrix(S);
            PZMath_vector targetMu = new PZMath_vector(m);

            MultivariateNormalDistribution random = new MultivariateNormalDistribution(targetMu, targetSigma);
            return random.Evaluate(x);
        }