スネデガーF分布サンプリング; Snedecor's F Distribution Sampling
概要
スネデガーF分布とは以下の式で表現される確率分布。自由度\(d_1, d_2\)の2つのカイ二乗分布に従う確率変数\(U_1, U_2\)があるとき、\(\frac{U_1 / d_1}{U_2 / d_2} \)はスネデガーF分布に従う。
$$f(x)=\frac{1}{x B(d_1/2, d_2/2)} \left( \frac{d_1 x}{d_1 x + d_2} \right)^{d_1/2} \left(1- \frac{d_1 x}{d_1 x + d_2} \right)^{d_2/2} $$
ソースコード
namespace ExRandom.Continuous {
public class SnedecorsFRandom : Random{
readonly ChiSquaredRandom cd1, cd2;
readonly double d1, d2;
public SnedecorsFRandom(MT19937 mt, uint d1 = 2, uint d2 = 2) {
if(mt == null) {
throw new ArgumentNullException();
}
this.cd1 = new ChiSquaredRandom(mt, k : d1);
this.cd2 = new ChiSquaredRandom(mt, k : d2);
this.d1 = d1;
this.d2 = d2;
}
public override double Next() {
double c1 = cd1.Next(), c2 = cd2.Next();
return (c1 * d2) / Math.Max(c2 * d1, Double.Epsilon);
}
}
}
関連項目
メルセンヌ・ツイスタ
各種確率分布サンプリング基本クラス
カイ二乗分布サンプリング