/// <summary> /// generate roc plot data for all models in the best-fit models list and makes the plots. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tabControl2_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl2.SelectedIndex == 3) //do nothing if not roc curves tab selected { if (listBox1.Items.Count < 1) return; if (_list.Count > 0) //if we have models, make plots { double lowerbound = 0.0d; double upperbound = 1.0d; listView3.Items.Clear(); GraphPane pane = zgcROC.GraphPane; if (pane.CurveList.Count > 0) pane.CurveList.Clear(); pane.Title.Text = "Receiver Operating Characteristic Curves \n for Best-Fit Models"; pane.XAxis.Title.Text = "1 - Specificity"; pane.YAxis.Title.Text = "Sensitivity"; object[] colors = new object[] {Color.DarkSeaGreen, Color.Green, Color.Indigo, Color.ForestGreen, Color.CadetBlue, Color.DarkBlue, Color.DarkViolet, Color.DarkCyan, Color.Blue, Color.DarkGray}; object[] symbols = new object[] {SymbolType.Circle, SymbolType.Diamond, SymbolType.Plus, SymbolType.Square, SymbolType.Star, SymbolType.Triangle, SymbolType.TriangleDown, SymbolType.XCross, SymbolType.VDash, SymbolType.HDash}; string[] item = new string[2]; PointPairList ppl = new PointPairList(); //generate the data, make the plots, and fill the listbox with model/areaundercurve info int maxmodelptr = -1; double maxmodelauc = 0; //if there are more models in list than showing... use 10 or use the number in the list int maxNmodels = _list.Count <= 10 ? _list.Count : 10; //initialize a structure for storing roc curve information for all curves... _tableVals = new Dictionary<string,List<object>>(); //...and one for individual model List<object> modelRocVals = null; //for (int li = 0; li < list.Count; li++) for (int li = 0; li < maxNmodels; li++) { //PointPairList ppl = ROCpoints( (MLRIndividual)list[li]); ppl = ROCpoints((MLRIndividual)_list[li], out modelRocVals); string key = _list[li].Fitness.ToString("##.####"); if (!_tableVals.ContainsKey(key)) { _tableVals.Add(key, modelRocVals); } if (ppl != null && ppl.Count > 0) { //BasicArrayPointList ppl = ROCpoints((MLRIndividual)list[li]); LineItem curve = pane.AddCurve(_list[li].Fitness.ToString("##.####"), ppl, (Color)colors[li], (SymbolType)symbols[li]); double[] X = new double[ppl.Count]; double[] Y = new double[ppl.Count]; for (int i = 0; i < ppl.Count; i++) //there must be a smarter way to do this { X[i] = ppl[i].X; Y[i] = ppl[i].Y; } //performing integral evaluation with EM Piecewise constant curve instance //(another possibility is the Piecewise linear curve class... splines and //other curve definitions seem like overkill and delegate realfunctions seem //like the wrong approach entirely - requires curve fitting/definition and all //we have are data points for VERY similar curves) Calculus calc = new Calculus(X, Y, lowerbound, upperbound); double auc = calc.PieceWiseConstantCurveIntegrate(); //maybe piecewise linear curve is better? calc = new Calculus(X, Y, lowerbound, upperbound); double auc2 = calc.PieceWiseLinearCurveIntegrate(); double idiff = auc - auc2; //comment next line to use piecewiseconstant integral calc auc = auc2; item[0] = _list[li].Fitness.ToString("##.####"); //item[1] = string.Format("{0:f6}", auc.ToString()); item[1] = auc.ToString("#.######"); ListViewItem lvi = new ListViewItem(item); listView3.Items.Add(lvi); if (auc > maxmodelauc) { maxmodelauc = auc; maxmodelptr = li; } } } //add the no information trace PointPair orig = new PointPair(0, 0); PointPair extent = new PointPair(1, 1); PointPairList ppl2 = new PointPairList(); ppl2.Add(orig); ppl2.Add(extent); LineItem curve2 = pane.AddCurve("", ppl2, Color.Black); //curve2.Tag = "NoInfo"; curve2.IsVisible = true; pane.XAxis.Scale.Max = 1.0; pane.YAxis.Scale.Max = 1.0; zgcROC.AxisChange(); if (pane.CurveList.Count > 1) { //highlight the max auc trace LineItem bestcurve = (LineItem)pane.CurveList[maxmodelptr]; //bestcurve.Symbol.Size = 12.0f; bestcurve.Line.Width = 3.0f; bestcurve.Line.Color = Color.Red; //highlight the model with the max auc in the listbox //listView3.Items[maxmodelptr].BackColor = Color.Pink; listView3.Items[maxmodelptr].ForeColor = Color.Red; //dump the roc parameters to the table (list) string temp = listView3.Items[maxmodelptr].Text; List<object> vals = _tableVals[temp]; updateList(vals); } else { MessageBox.Show("The current values for the decision criterion and regulatory standard do not permit ROC curves to be calculated.", "No Appropriate Plot Data", MessageBoxButtons.OK); } } } }