示例#1
0
文件: frmModel.cs 项目: wrbrooks/VB3
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            _smi = listBox1.SelectedIndex;
            if (_smi != _pmi)
            {
                if (_pmi == -1)
                {
                    _state = _mlrState.clean;
                }
                else
                {
                    _state = _mlrState.dirty;
                }
                _pmi = _smi;
            }
            else
            {
                _state = _mlrState.clean;
            }

            listView1.Items.Clear();
            listView2.Items.Clear();

            int idx = listBox1.SelectedIndex;
            MLRIndividual ind = (MLRIndividual)_list[idx];

            _selectedModelIndex = idx;

            //tell the main form to enable the model save/saveas menu selection buttons
            OnModelSelected(null);

            string[] item = null;
            ListViewItem lvi = null;

            int numColumns = ind.Parameters.Columns.Count;
            for (int i = 0; i < ind.Parameters.Rows.Count; i++)
            {
                item = new string[numColumns];
                item[0] = ind.Parameters.Rows[i][0].ToString();
                item[1] = formatNumber((double)ind.Parameters.Rows[i][1]);
                item[2] = formatNumber((double)ind.Parameters.Rows[i][2]);
                item[3] = formatNumber((double)ind.Parameters.Rows[i][3]);
                item[4] = formatNumber((double)ind.Parameters.Rows[i][4]);
                item[5] = formatNumber((double)ind.Parameters.Rows[i][5]);
                lvi = new ListViewItem(item);
                listView1.Items.Add(lvi);
            }

            DataTable dt = _projMgr.ModelDataTable;

            int numRecords = dt.Rows.Count;
            if (numRecords != ind.PredictedValues.Length)
                return;

            List<double[]> data = new List<double[]>();
            double[] record = null;
            for (int i = 0; i < numRecords; i++)
            {
                record = new double[2];
                record[0] = Convert.ToDouble(dt.Rows[i][1].ToString());
                record[1] = ind.PredictedValues[i];
                data.Add(record);
            }

            //for plotting xyplot when transform radio buttons changed
            _XYPlotdata = data;

            item = new string[2];
            item[0] = "R Squared";
            item[1] = String.Format("{0:F4}", ind.R2);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "Adjusted R Squared";
            item[1] = String.Format("{0:F4}", ind.AdjustedR2);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "Akaike Information Criterion";
            item[1] = String.Format("{0:F4}", ind.AIC);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "Corrected AIC";
            item[1] = String.Format("{0:F4}", ind.AICC);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "Bayesian Info Criterion";
            item[1] = String.Format("{0:F4}", ind.BIC);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "PRESS";
            item[1] = String.Format("{0:F4}", ind.Press);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "RMSE";
            item[1] = String.Format("{0:F4}", ind.RMSE);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            if ((ind.DecisionThreshold != Double.NaN) && (ind.MandatedThreshold != Double.NaN))
            {
                item = new string[2];
                item[0] = "";
                item[1] = "";
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "Decision Criterion";
                item[1] = string.Format("{0:F4}", ind.DecisionThreshold);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "Regulatory Standard";
                item[1] = string.Format("{0:F4}", ind.MandatedThreshold);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                ModelErrorCounts mec = new ModelErrorCounts();
                mec.getCounts(ind.DecisionThreshold, ind.MandatedThreshold, ind.PredictedValues, ind.ObservedValues);
                int fp = mec.FPCount;
                int fn = mec.FNCount;

                item = new string[2];
                item[0] = "False Positives";
                item[1] = string.Format("{0:n}", fp);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "Specificity";
                item[1] = String.Format("{0:F4}", ind.Specificity);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "False Negatives";
                item[1] = string.Format("{0:n}", fn);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "Sensitivity";
                item[1] = String.Format("{0:F4}", ind.Sensitivity);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                //item = new string[2];
                //item[0] = "Specificity";
                //item[1] = String.Format("{0:F4}", ind.Specificity);
                //lvi = new ListViewItem(item);
                //listView2.Items.Add(lvi);

                item = new string[2];
                item[0] = "Accuracy";
                item[1] = String.Format("{0:F4}", ind.Accuracy);
                lvi = new ListViewItem(item);
                listView2.Items.Add(lvi);

                //for reporting/plotting
                ThresholdChecked = true;
            }
            else
            {
                //for reporting/plotting
                ThresholdChecked = false;
            }

            item = new string[2];
            item[0] = "";
            item[1] = "";
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            item = new string[2];
            item[0] = "Number of Observations";
            item[1] = string.Format("{0}", numRecords);
            lvi = new ListViewItem(item);
            listView2.Items.Add(lvi);

            UpdateResults(data);
            mlrPredObs1.UpdateResults(data);
            //UpdateResults2(data);

            _projMgr.Model = ind.Model;
            _projMgr.ModelIndependentVariables = new List<string>(_projMgr.GetIndependentVariableList(ind.Chromosome));

            SaveModelingInfo();

            //if user selects a model in list....
            _projMgr._comms.sendMessage("Show the MLR Prediction form.", this);
            //also want to show the residuals tab but don't need another call
            //_proj._comms.sendMessage("Show the Residuals form.", this);
        }
示例#2
0
        //update results based on changed data
        public void UpdateResults(List<double[]> data)
        {
            lstXYPlotdata = data;

            if ((lstXYPlotdata == null) || (lstXYPlotdata.Count < 1))
            {
                zedGraphControl1.GraphPane.CurveList[0].Clear();
                zedGraphControl1.Refresh();
                return;
            }

            // Make sure that the curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
                return;

            // Get the first CurveItem in the graph
            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            if (curve == null)
                return;

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
                return;

            list.Clear();

            double maxX = Double.NegativeInfinity;
            double maxY = Double.NegativeInfinity;
            double minX = 0;
            double minY = 0;
            for (int i = 0; i < data.Count; i++)
            {
                list.Add(data[i][0], data[i][1]);
                if (data[i][0] > maxX)
                    maxX = data[i][0];
                if (data[i][1] > maxY)
                    maxY = data[i][1];
                if (data[i][0] < minX)
                    minX = data[i][0];
                if (data[i][1] < minY)
                    minY = data[i][1];
            }

            //if data out of range of thresholds, make the threshold plot lines bigger
            if (dblDecisionThreshold > maxX) maxX = dblMandateThreshold; //_decisionThreshold;
            if (dblMandateThreshold > maxY) maxY = dblDecisionThreshold; //_mandateThreshold;

            //find the model error counts for the XYplot display
            ModelErrorCounts mec = new ModelErrorCounts();
            mec.getCounts(dblDecisionThreshold, dblMandateThreshold, data);
            if (mec.Status)
            {
                int intFpc = mec.FPCount;
                int intFnc = mec.FNCount;
                tbFN.Text = intFnc.ToString();
                tbFP.Text = intFpc.ToString();
                txbSpecificity.Text = mec.Specificity.ToString();
                txbSensitivity.Text = mec.Sensitivity.ToString();
                txbAccuracy.Text = mec.Accuracy.ToString();
            }
            else
            {
                string msg = "Data Error: " + mec.Message.ToString();
                MessageBox.Show(msg);
                return;
            }

            LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            LineItem curve3 = zedGraphControl1.GraphPane.CurveList[2] as LineItem;
            if ((curve2 != null) && (curve3 != null))
            {
                curve2.Line.IsVisible = false;
                curve3.Line.IsVisible = false;

                // Get the PointPairList
                IPointListEdit list2 = curve2.Points as IPointListEdit;
                list2.Clear();
                //mikec want the thresholds crossing, thus the "-1", "+1"
                list2.Add(minX - 1, dblDecisionThreshold);
                list2.Add(maxX + 1, dblDecisionThreshold);
                curve2.Line.IsVisible = true;

                // Get the PointPairList
                //mikec want the thresholds crossing, thus the "-1", "+1"
                IPointListEdit list3 = curve3.Points as IPointListEdit;
                list3.Clear();
                list3.Add(dblMandateThreshold, minY - 1);
                list3.Add(dblMandateThreshold, maxY + 1);
                curve3.Line.IsVisible = true;
            }

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
            if (data[data.Count - 1][0] > xScale.Max - xScale.MajorStep)
            {
            }

            GraphPane zgc1pane = zedGraphControl1.GraphPane;
            zgc1pane.XAxis.Cross = 0;

            // Make sure the Y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
            zedGraphControl1.Refresh();
            Application.DoEvents();
        }
示例#3
0
        //update results based on changed data
        public void UpdateResults(List <double[]> data)
        {
            lstXYPlotdata = data;

            if ((lstXYPlotdata == null) || (lstXYPlotdata.Count < 1))
            {
                zedGraphControl1.GraphPane.CurveList[0].Clear();
                zedGraphControl1.Refresh();
                return;
            }

            // Make sure that the curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
            {
                return;
            }

            list.Clear();

            double maxX = Double.NegativeInfinity;
            double maxY = Double.NegativeInfinity;
            double minX = 0;
            double minY = 0;

            for (int i = 0; i < data.Count; i++)
            {
                list.Add(data[i][0], data[i][1]);
                if (data[i][0] > maxX)
                {
                    maxX = data[i][0];
                }
                if (data[i][1] > maxY)
                {
                    maxY = data[i][1];
                }
                if (data[i][0] < minX)
                {
                    minX = data[i][0];
                }
                if (data[i][1] < minY)
                {
                    minY = data[i][1];
                }
            }

            //if data out of range of thresholds, make the threshold plot lines bigger
            if (dblDecisionThreshold > maxX)
            {
                maxX = dblMandateThreshold;                              //_decisionThreshold;
            }
            if (dblMandateThreshold > maxY)
            {
                maxY = dblDecisionThreshold;                             //_mandateThreshold;
            }
            //find the model error counts for the XYplot display
            ModelErrorCounts mec = new ModelErrorCounts();

            mec.getCounts(dblDecisionThreshold, dblMandateThreshold, data);
            if (mec.Status)
            {
                int intFpc = mec.FPCount;
                int intFnc = mec.FNCount;
                tbFN.Text           = intFnc.ToString();
                tbFP.Text           = intFpc.ToString();
                txbSpecificity.Text = mec.Specificity.ToString();
                txbSensitivity.Text = mec.Sensitivity.ToString();
                txbAccuracy.Text    = mec.Accuracy.ToString();
            }
            else
            {
                string msg = "Data Error: " + mec.Message.ToString();
                MessageBox.Show(msg);
                return;
            }

            LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            LineItem curve3 = zedGraphControl1.GraphPane.CurveList[2] as LineItem;

            if ((curve2 != null) && (curve3 != null))
            {
                curve2.Line.IsVisible = false;
                curve3.Line.IsVisible = false;

                // Get the PointPairList
                IPointListEdit list2 = curve2.Points as IPointListEdit;
                list2.Clear();
                //mikec want the thresholds crossing, thus the "-1", "+1"
                list2.Add(minX - 1, dblDecisionThreshold);
                list2.Add(maxX + 1, dblDecisionThreshold);
                curve2.Line.IsVisible = true;

                // Get the PointPairList
                //mikec want the thresholds crossing, thus the "-1", "+1"
                IPointListEdit list3 = curve3.Points as IPointListEdit;
                list3.Clear();
                list3.Add(dblMandateThreshold, minY - 1);
                list3.Add(dblMandateThreshold, maxY + 1);
                curve3.Line.IsVisible = true;
            }

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            if (data[data.Count - 1][0] > xScale.Max - xScale.MajorStep)
            {
            }

            GraphPane zgc1pane = zedGraphControl1.GraphPane;

            zgc1pane.XAxis.Cross = 0;

            // Make sure the Y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
            zedGraphControl1.Refresh();
            Application.DoEvents();
        }