public void comparePredictionsToolStripMenuItem_Click(object sender, EventArgs e) { if (TraversePredictionTree().Count(n => n.Checked) <= 1) MessageBox.Show("Select two or more predictions / groups to make a comparison."); else { EvaluateSelectedPredictions(); List<List<Plot>> plotRows = new List<List<Plot>>(); foreach (TreeNode node in TraversePredictionTree()) if (node.Checked) if (node.Tag is PredictionGroup) plotRows.Add(new List<Plot>(new Plot[] { (node.Tag as PredictionGroup).AggregatePlot })); else if (node.Tag is Prediction) plotRows.Add((node.Tag as Prediction).AssessmentPlots); else throw new Exception("Unexpected node tag: " + node.Tag); PredictionComparisonForm comparisonForm = new PredictionComparisonForm(plotRows, Size); if (comparisonForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { StringBuilder comparisonTitle = new StringBuilder(); Dictionary<string, List<PointF>> seriesPoints = new Dictionary<string, List<PointF>>(); foreach (SurveillancePlot selectedPlot in comparisonForm.SelectedPlots) { string plotTitle = selectedPlot.Title.Replace(Environment.NewLine, " ").RemoveRepeatedWhitespace(); comparisonTitle.Append((comparisonTitle.Length == 0 ? "Comparison of " : ", ") + plotTitle); foreach (string series in selectedPlot.SeriesPoints.Keys) if (series != DiscreteChoiceModel.OptimalSeriesName) { string baseSeriesTitle = plotTitle; if (series == DiscreteChoiceModel.OptimalSeriesName) baseSeriesTitle = DiscreteChoiceModel.OptimalSeriesName + " " + baseSeriesTitle; string seriesTitle = baseSeriesTitle; int dupNameNum = 2; while (seriesPoints.Keys.Count(k => k == seriesTitle) > 0) seriesTitle = baseSeriesTitle + " " + dupNameNum++; seriesPoints.Add(seriesTitle, selectedPlot.SeriesPoints[series]); } } SurveillancePlot comparisonPlot = new SurveillancePlot(comparisonTitle.ToString(), -1, seriesPoints, 500, 500, Plot.Format.JPEG, 2); DynamicForm f = new DynamicForm("Result comparison", DynamicForm.CloseButtons.OK); f.AddPictureBox(comparisonPlot.Image); f.ShowDialog(); } } }
public void aggregateAndEvaluateToolStripMenuItem_Click(object sender, EventArgs e) { if (SelectedPredictions.Count < 2) MessageBox.Show("Select at least two predictions to run an aggregate evaluation."); else { try { string title = "Aggregated"; if (TraversePredictionTree().Count(n => n.Checked) == 1) title = TraversePredictionTree().Where(n => n.Checked).First().Text; Tuple<SurveillancePlot, float> surveillancePlotAndCorrelation = DiscreteChoiceModel.GetAggregateSurveillancePlotAndCorrelation(SelectedPredictions, 500, 500, title, title); DynamicForm f = new DynamicForm(title, DynamicForm.CloseButtons.OK); f.AddPictureBox(surveillancePlotAndCorrelation.Item1.Image, "Correlation between threat and crime count: " + surveillancePlotAndCorrelation.Item2); f.ShowDialog(); } catch (Exception ex) { MessageBox.Show("Error rendering aggregate plot: " + ex.Message); } } }