public decimal Calculate_f_u(decimal[] input)
        {
            decimal index = 0.0m;

            for (int j = 0; j < input.Length; j++)
            {
                index += input[j] * input[j];
            }

            return(TaylorSeriesDecimal.Exponential(-index / 2m));
        }
Esempio n. 2
0
        /// <summary>
        /// 乱数を生成する
        /// 平均値 average
        /// 標準偏差 std
        /// </summary>
        /// <param name="average"></param>
        /// <param name="std"></param>
        /// <returns></returns>
        public decimal NextDecimal(decimal average, decimal std)
        {
retry_point:

            decimal u1 = ud1.NextDecimal();
            decimal u2 = ud2.NextDecimal();

            decimal v1 = 2 * u1 - 1;
            decimal v2 = 2 * u2 - 1;
            decimal v  = v1 * v1 + v2 * v2;

            if (v <= 0 || 1 <= v)
            {
                goto retry_point;
            }

            decimal w = TaylorSeriesDecimal.SquareRoot(-2 * TaylorSeriesDecimal.NaturalLogarithm(v) / v);

            decimal y1 = v1 * w;
            decimal y2 = v2 * w;


            if (even)
            {
                resultDecimal = y1;
                even          = false;
            }
            else
            {
                resultDecimal = y2;
                even          = true;
            }

            resultDecimal = TaylorSeriesDecimal.Exponential(resultDecimal * Math.Abs(std) + average);
            return(resultDecimal);
        }