Keyword: 多変量スチューデントt-分布, 疑似乱数ベクトル
概要
本サンプルは多変量スチューデントt-分布から疑似乱数ベクトルの生成を行うFortranによるサンプルプログラムです。 本サンプルは以下に示される確率密度関数をもつ多変量スチューデントt-分布から10個の疑似乱数を生成し出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン g05ryf() のExampleコードです。本サンプル及びルーチンの詳細情報は g05ryf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はg05ryf のマニュアルページを参照)| このデータをダウンロード |
G05RYF Example Program Data
1 1 1762543 :: GENID,SUBID,SEED(1)
10 4 :: N,M
10 :: DF
1.0 2.0 -3.0 0.0 :: XMU
1.69 0.39 -1.86 0.07
98.01 -7.07 -0.71
11.56 0.03
0.01 :: End of C (upper triangular part)
- 1行目はタイトル行で読み飛ばされます。
- 2行目に使用する生成器(genid=1:nAG基本生成器)、生成器に関する情報(subid=1:GENIDが1の場合この値は参照されません)、生成器の初期値(seed=1762543)を指定しています。
- 3行目に生成される乱数の数(n=10)と次元の数(m=4)を指定しています。
- 4行目に分布の自由度の数(df=10)を指定しています。
- 5行目に分布の平均ベクトル(xmu)を指定しています。
- 6〜9行目に分布の共分散行列の上三角部分(c)を指定しています。
出力結果
(本ルーチンの詳細はg05ryf のマニュアルページを参照)| この出力例をダウンロード |
G05RYF Example Program Results
Variates
1 2 3 4
1 1.4957 -15.6226 -3.8101 0.1294
2 -1.0827 -6.7473 0.6696 -0.0391
3 2.1369 6.3861 -5.7413 0.0140
4 2.2481 -16.0417 -1.0982 0.1641
5 -0.2550 3.5166 -0.2541 -0.0592
6 0.9731 -4.3553 -4.4181 0.0043
7 0.7098 -3.4281 1.1741 0.0586
8 1.8827 23.2619 1.5140 -0.0704
9 0.9904 22.7479 0.1811 -0.0893
10 1.5026 2.7753 -2.2805 -0.0112
- 5〜14行目に生成された疑似乱数が出力されています。
ソースコード
(本ルーチンの詳細はg05ryf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM g05ryfe
! G05RYF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : g05kff, g05ryf, nag_wp, x04caf
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: lseed = 1, nin = 5, nout = 6
! .. Local Scalars ..
INTEGER :: df, genid, i, ifail, ldc, ldx, lr, &
lstate, m, mode, n, subid
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: c(:,:), r(:), x(:,:), xmu(:)
INTEGER :: seed(lseed)
INTEGER, ALLOCATABLE :: state(:)
! .. Executable Statements ..
WRITE (nout,*) 'G05RYF Example Program Results'
WRITE (nout,*)
FLUSH (nout)
! Skip heading in data file
READ (nin,*)
! Read in the base generator information and seed
READ (nin,*) genid, subid, seed(1)
! Initial call to initialiser to get size of STATE array
lstate = 0
ALLOCATE (state(lstate))
ifail = 0
CALL g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Reallocate STATE
DEALLOCATE (state)
ALLOCATE (state(lstate))
! Initialize the generator to a repeatable sequence
ifail = 0
CALL g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Read in sample size and number of dimensions
READ (nin,*) n, m
ldc = m
ldx = n
lr = m*(m+1) + 2
ALLOCATE (x(ldx,m),c(ldc,m),r(lr),xmu(m))
! Read in degrees of freedom
READ (nin,*) df
! Read in vector of means
READ (nin,*) xmu(1:m)
! Read in upper triangle portion of the covariance matrix
DO i = 1, m
READ (nin,*) c(i,i:m)
END DO
! Using a single call to G05RYF, so set up reference vector
! and generate values in one go
mode = 2
! Generate variates
ifail = 0
CALL g05ryf(mode,n,df,m,xmu,c,ldc,r,lr,state,x,ldx,ifail)
! Display the variates
ifail = 0
CALL x04caf('General',' ',n,m,x,ldx,'Variates',ifail)
END PROGRAM g05ryfe
