private void PlotLikelihood(string text, NumericalTools.Likelihood lk) { if (lk == null) { Image im = pbLkDisplay.Image; Graphics g = Graphics.FromImage(im); g.FillRectangle(new SolidBrush(Color.White), 0, 0, im.Width, im.Height); g.DrawString("Likelihood not available - press Compute", new Font("Lucida", 10), new SolidBrush(Color.Black), 0, 0); pbLkDisplay.Refresh(); } else { Image im = pbLkDisplay.Image; Graphics g = Graphics.FromImage(im); g.FillRectangle(new SolidBrush(Color.White), 0, 0, im.Width, im.Height); double[] p = new double[(int)Math.Floor((lk.MaxBound(0) - lk.MinBound(0)) / 0.05 + 1.0)]; double[] logl = new double[p.Length]; int i; for (i = 0; i < p.Length; i++) { p[i] = lk.MinBound(0) + i * 0.05; logl[i] = lk.LogValue(p[i]); } NumericalTools.Plot pl = new NumericalTools.Plot(); pl.VecX = p; pl.VecY = logl; double dummy = 0.0; double miny = 0.0, maxy = 0.0; NumericalTools.Fitting.FindStatistics(logl, ref maxy, ref miny, ref dummy, ref dummy); maxy += 0.2 * (maxy - miny); pl.JoinPenThickness = 2; pl.MinX = lk.MinBound(0) - 0.05; pl.MaxX = lk.MaxBound(0) + 0.05; pl.SetXDefaultLimits = false; pl.MinY = miny; pl.MaxY = maxy; pl.SetYDefaultLimits = false; pl.XTitle = "P"; pl.YTitle = text; pl.LabelFont = new Font("Lucida", 10); pl.PanelFont = new Font("Lucida", 10); pl.PanelY = 3; pl.Scatter(g, im.Width, im.Height); pbLkDisplay.Refresh(); } }
private void btnDumpLikelihood_Click(object sender, EventArgs e) { if (Likelihood == null) return; SaveFileDialog sdlg = new SaveFileDialog(); sdlg.Title = "Select file to save likelihood function points."; sdlg.Filter = "Text files(*.txt)|*.txt|All files (*.*)|*.*"; System.IO.StreamWriter w = null; if (sdlg.ShowDialog() == DialogResult.OK) try { w = new System.IO.StreamWriter(sdlg.FileName); w.Write("P\tLogL"); double p; for (p = Likelihood.MinBound(0); p <= Likelihood.MaxBound(0); p += 0.05) w.Write("\r\n" + p.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\t" + Likelihood.LogValue(p).ToString(System.Globalization.CultureInfo.InvariantCulture)); w.Flush(); w.Close(); } catch (Exception x) { MessageBox.Show("Can't write file \"" + sdlg.FileName + "\".", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (w != null) { w.Close(); w = null; } } if (w != null) { w.Close(); w = null; } }