private void OnSelectedSlopeSetChanged(object sender, EventArgs e) { if (clSlopeSets.SelectedIndex >= 0) { FitSet fs = (FitSet)clSlopeSets.SelectedItem; PlotLikelihood("LogL \"" + fs.ToString() + "\"", fs.Likelihood); } }
private void btnCompute_Click(object sender, EventArgs e) { if (clSlopeSets.CheckedItems.Count < 1) { MessageBox.Show("At least one data set must be enabled.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } NumericalTools.Likelihood[] lk = new NumericalTools.Likelihood[clSlopeSets.CheckedItems.Count]; int i; for (i = 0; i < clSlopeSets.CheckedItems.Count; i++) { FitSet fs = (FitSet)clSlopeSets.CheckedItems[i]; if (fs.Likelihood == null) try { MCSLikelihood.ProcessData(fs.Tracks, out fs.Likelihood); } catch (Exception x) { MessageBox.Show("Error computing likelihood for set \"" + fs.ToString() + "\":\r\n" + x.Message, "Computation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } lk[i] = fs.Likelihood; } Likelihood = null; txtResults.Text = ""; try { Likelihood = new NumericalTools.OneParamLogLikelihood(0.05, lk); string t = Likelihood.Best(0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + ";"; double cl = ((SySal.Processing.MCSLikelihood.Configuration)MCSLikelihood.Config).ConfidenceLevel; double[] bounds = Likelihood.ConfidenceRegions(0, cl); for (i = 0; i < bounds.Length; i += 2) t += " [" + bounds[i].ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "," + bounds[i + 1].ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "]"; t += "; " + cl.ToString("F2", System.Globalization.CultureInfo.InvariantCulture); txtResults.Text = t; } catch (Exception x) { MessageBox.Show("Error computing combined likelihood:\r\n" + x.Message, "Computation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } PlotLikelihood("LogL (combined)", Likelihood); }
internal void Add(FitSet fs) { try { if (fs.Tracks.Length < 2) throw new Exception("At least two slopes must be measured."); if (clSlopeSets.Items.Contains(fs)) throw new Exception("Slope set is already contained and will not be added again."); foreach (object o in clSlopeSets.Items) { FitSet fso = (FitSet)o; if (fso.Source == fs.Source) throw new Exception("Slope set is already contained and will not be added again."); int i, j; i = j = 0; while (i < fso.Tracks.Length && j < fs.Tracks.Length) if (fso.Tracks[i].Field < fs.Tracks[j].Field) i++; else if (fso.Tracks[i].Field > fs.Tracks[j].Field) j++; else throw new Exception("The new data set has at least one plate in common with \"" + fso.ToString() + "\".\r\nCombined fit requires that no data be in common.\r\nDuplicate found on layer " + fso.Tracks[i].Field + " Grains " + fso.Tracks[i].Count + " SX/Y " + fso.Tracks[i].Slope.X.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "/" + fso.Tracks[i].Slope.Y.ToString("F4", System.Globalization.CultureInfo.InvariantCulture)); } clSlopeSets.SetItemChecked(clSlopeSets.Items.Add(fs), true); } catch (Exception x) { MessageBox.Show(x.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }