// --- corpus controle : 4 themes x 4 mots + 3 mots partages (structure connue, jamais utilisee pour apprendre) ---
var randSel = new Random(42);
string[] vocabSel = {
"football","equipe","match","competition",
"ordinateur","logiciel","internet","application",
"recette","ingredient","cuisson","gastronomie",
"hotel","avion","destination","tourisme",
"recherche","performance","preparation" // 16-18 partages
};
int Vsel = vocabSel.Length;
double[][] phiGen = {
new double[]{.24,.20,.18,.16,.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.05,.04,.03},
new double[]{.01,.01,.01,.01,.24,.20,.18,.16,.01,.01,.01,.01,.01,.01,.01,.01,.03,.05,.04},
new double[]{.01,.01,.01,.01,.01,.01,.01,.01,.24,.20,.18,.16,.01,.01,.01,.01,.04,.03,.06},
new double[]{.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.01,.24,.20,.18,.16,.03,.04,.05}
};
for (int k = 0; k < 4; k++) { double s = phiGen[k].Sum(); for (int v = 0; v < Vsel; v++) phiGen[k][v] /= s; }
double[][] thetaGen = new double[16][];
int diSel = 0;
for (int t = 0; t < 4; t++) for (int r = 0; r < 3; r++) {
var v = Enumerable.Repeat(0.1, 4).ToArray(); v[t] = 0.7; thetaGen[diSel++] = v;
}
thetaGen[12] = new double[]{.4,.4,.1,.1};
thetaGen[13] = new double[]{.1,.4,.4,.1};
thetaGen[14] = new double[]{.4,.1,.4,.1};
thetaGen[15] = new double[]{.25,.25,.25,.25};
double[][] heldThetaGen = { new double[]{.7,.1,.1,.1}, new double[]{.1,.7,.1,.1},
new double[]{.1,.1,.7,.1}, new double[]{.4,.1,.1,.4} };
int docLen = 24;
static int SampleDiscrete(Random rng, double[] p) { double u = rng.NextDouble(); double c = 0; for (int i = 0; i < p.Length; i++) { c += p[i]; if (u < c) return i; } return p.Length - 1; }
int[] GenDoc(Random rng, double[] thetaT) =>
Enumerable.Range(0, docLen).Select(n => phiGen[SampleDiscrete(rng, thetaT)])
.Select(ph => SampleDiscrete(rng, ph)).ToArray();
int[][] trainSel = thetaGen.Select(t => GenDoc(randSel, t)).ToArray();
int[][] heldSel = heldThetaGen.Select(t => GenDoc(randSel, t)).ToArray();
Console.WriteLine($"train docs: {trainSel.Length}, held: {heldSel.Length}, V={Vsel}, L={docLen}");