import smile.math.Math; //导入方法依赖的package包/类
/**
* Initialize random number generator.
*/
Patchwork(int N, int m, int n) {
super(N, m, n);
double Mp, np, p, modef, U; // (X, Y) (V, W)
Mp = (double) (m + 1);
np = (double) (n + 1);
L = N - m - n;
p = Mp / (N + 2.);
modef = np * p;
// approximate deviation of reflection points k2, k4 from modef - 1/2
U = Math.sqrt(modef * (1. - p) * (1. - (n + 2.) / (N + 3.)) + 0.25);
// mode, reflection points k2 and k4, and points k1 and k5, which
// delimit the centre region of h(x)
// k2 = ceil (modef - 1/2 - U), k1 = 2*k2 - (mode - 1 + delta_ml)
// k4 = floor(modef - 1/2 + U), k5 = 2*k4 - (mode + 1 - delta_mr)
int mode = (int) modef;
k2 = (int) Math.ceil(modef - 0.5 - U);
if (k2 >= mode) {
k2 = mode - 1;
}
k4 = (int) (modef - 0.5 + U);
k1 = k2 + k2 - mode + 1; // delta_ml = 0
k5 = k4 + k4 - mode; // delta_mr = 1
// range width of the critical left and right centre region
dl = (double) (k2 - k1);
dr = (double) (k5 - k4);
// recurrence constants r(k) = p(k)/p(k-1) at k = k1, k2, k4+1, k5+1
r1 = (np / (double) k1 - 1.) * (Mp - k1) / (double) (L + k1);
r2 = (np / (double) k2 - 1.) * (Mp - k2) / (double) (L + k2);
r4 = (np / (double) (k4 + 1) - 1.) * (m - k4) / (double) (L + k4 + 1);
r5 = (np / (double) (k5 + 1) - 1.) * (m - k5) / (double) (L + k5 + 1);
// reciprocal values of the scale parameters of expon. tail envelopes
ll = Math.log(r1); // expon. tail left
lr = -Math.log(r5); // expon. tail right
// hypergeom. constant, necessary for computing function values f(k)
cPm = lnpk(mode, L, m, n);
// function values f(k) = p(k)/p(mode) at k = k2, k4, k1, k5
f2 = Math.exp(cPm - lnpk(k2, L, m, n));
f4 = Math.exp(cPm - lnpk(k4, L, m, n));
f1 = Math.exp(cPm - lnpk(k1, L, m, n));
f5 = Math.exp(cPm - lnpk(k5, L, m, n));
// area of the two centre and the two exponential tail regions
// area of the two immediate acceptance regions between k2, k4
p1 = f2 * (dl + 1.); // immed. left
p2 = f2 * dl + p1; // centre left
p3 = f4 * (dr + 1.) + p2; // immed. right
p4 = f4 * dr + p3; // centre right
p5 = f1 / ll + p4; // expon. tail left
p6 = f5 / lr + p5; // expon. tail right
}