private void button_Generate_Click(object sender, EventArgs e) { Result.Clear(); string[] Str = textBox_Times.Text.Replace("\r", "").Split('\n'); List <int> Nums = new List <int>(); int Temp = 0; foreach (string EachStr in Str) { if (Int32.TryParse(EachStr, out Temp)) { Nums.Add(Temp); } } int ClassLen = Classification.Length; int CountTimesLen = CountTimes.Length; if (Stat.DirichletAlphas(Nums, ClassLen, ref Alphas)) { if (ClassLen != 0 && CountTimesLen != 0) { Result.Append("先验分布: "); Result.Append("Dirichlet("); for (int i = 0; i < ClassLen; i++) { Result.Append(Alphas[i].ToString()); if (i < ClassLen - 1) { Result.Append(", "); } } Result.Append(")\r\n"); Stat.ConjugateDirichlet(ref Alphas, CountTimes); Result.Append("似然函数: "); Result.Append("Binomial("); double p = 0; double sum = CountTimes.Sum(); Result.Append(sum.ToString()); Result.Append(", "); for (int i = 0; i < ClassLen; i++) { p = ((double)CountTimes[i]) / sum; Result.Append(MathV.NumberPolish(p.ToString()).Trim()); if (i < ClassLen - 1) { Result.Append(", "); } } Result.Append(")\r\n"); Result.Append("Dirichlet("); for (int i = 0; i < ClassLen; i++) { Result.Append(Alphas[i].ToString()); if (i < ClassLen - 1) { Result.Append(", "); } } Result.Append(")\r\n"); Result.Append("后验分布等效样本量: "); Result.Append((Alphas.Sum() - Alphas.Count).ToString()); Result.Append("\r\n"); MainForm.S.richTextBox1.AppendText(Result.ToString()); MainForm.S.richTextBox1.Select(); //让RichTextBox获得焦点 MainForm.S.richTextBox1.Select(MainForm.S.richTextBox1.TextLength, 0); //将插入符号置于文本结束处 MainForm.S.richTextBox1.ScrollToCaret(); button_PosteriorDensity.Enabled = true; } } else { MessageBox.Show("输入次数缺失!"); } }