Keyword: ポワソン分布, 変動平均, 整数疑似乱数ベクトル
概要
本サンプルは変動平均のポワソン分布から整数疑似乱数ベクトルの生成を行うC#によるサンプルプログラムです。 本サンプルは確率が以下で表される、5つの変動平均(0.5、5、10、500、1000)をもつポワソン分布から10個の整数疑似乱数を生成し出力します。
※本サンプルはnAG Library for .NETに含まれる関数 g05tk() のExampleコードです。本サンプル及び関数の詳細情報は g05tk のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
出力結果
(本関数の詳細はg05tk のマニュアルページを参照)| この出力例をダウンロード |
g05tk Example Program Results 1 1 6 12 507 1003 2 0 9 11 520 1028 3 1 3 7 483 1041 4 0 3 11 513 1012 5 1 5 9 496 940 6 0 6 17 548 990 7 1 9 8 512 1035 8 0 4 10 458 1029 9 1 6 13 523 971 10 0 9 16 519 999
- 3〜12行目に生成された10個の整数疑似乱数が変動平均ごとに出力されています。
ソースコード
(本関数の詳細はg05tk のマニュアルページを参照)
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// g05tk Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
using System.IO;
namespace NagDotNetExamples
{
public class G05TKE
{
static void Main(String[] args)
{
StartExample();
}
public static void StartExample()
{
try
{
const int mseed=1;
const int m=5;
const int n=10;
int genid, i, j, subid;
double[] lambda = new double[m];
int[] seed = new int[mseed];
int[] x = new int[n];
int ifail;
Console.WriteLine("g05tk Example Program Results");
Console.WriteLine("");
// Set the distribution parameter lambda
lambda[0] = 0.50e0;
lambda[1] = 5.00e0;
lambda[2] = 1.00e1;
lambda[3] = 5.00e2;
lambda[4] = 1.00e3;
// Initialise the seed
seed[0] = 1762543;
// genid and subid identify the base generator
genid = 1;
subid = 1;
// Initialise the generator to a repeatable sequence
G05.G05State g05State = new G05.G05State(genid, subid, seed, out ifail);
if (ifail != 0)
{
Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail);
goto L40;
}
// Generate N sets of the M variates
for (i = 1 ; i <= n ; i++)
{
G05.g05tk(m, lambda, g05State, x, out ifail);
if (ifail != 0)
{
Console.WriteLine("** g05tk failed with ifail = {0,5}", ifail);
goto L40;
}
// Display the variates
Console.Write(" {0,3}", i);
for (j = 1 ; j <= m ; j++)
{
Console.Write(" {0,10}", x[j - 1]);
}
Console.WriteLine("");
}
//
L40: ;
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine( "Exception Raised");
}
}
}
}
