예제 #1
0
        public void ShowFitResult(FittingResult result)
        {
            if (result == null || result.Wind < 1 || result.SpecOriginal == null || result.FitSpec == null || result.Specs == null || result.VarIndex == null || result.VarIndex.Length < 5)
            {
                return;
            }


            this.guetPanel1.Title = string.Format("拟合结果:{0}", result.SpecOriginal.Name);
            var o = result.SpecOriginal.Clone();
            var f = result.FitSpec.Clone();

            o.Name = "原光谱";
            f.Name = "拟合光谱";
            var specs = new Spectrum[] { o, f };

            this.specGraph2.DrawSpec(specs.ToList());
            this.specGraph2.SetTitle("预处理后光谱与拟合光谱对比");

            double[] tSQ;
            double   tTQ;
            var      y1 = new double[result.VarIndex.Length];
            var      y2 = new double[result.VarIndex.Length];
            var      x  = new double[result.VarIndex.Length];

            for (int i = 0; i < y1.Length; i++)
            {
                y1[i] = o.Data.Y[result.VarIndex[i] - 1];
                y2[i] = f.Data.Y[result.VarIndex[i] - 1];
                x[i]  = f.Data.X[result.VarIndex[i] - 1];
            }
            RIPP.NIR.Data.Tools.MWCorr(y1, y2, result.Wind, out tTQ, out tSQ);
            var spec = o.Clone();

            spec.Data.X = x;
            spec.Data.Y = tSQ;
            spec.Name   = "SQ";
            spec.Color  = Color.Blue;
            this.specGraph1.DrawSpec(spec);


            var slst = new List <Spectrum>();

            foreach (var r in result.Specs)
            {
                var s = r.Spec.Clone();
                s.Name = string.Format("{0}:{1}", r.Rate.ToString("F4"), s.Name);
                slst.Add(s);
            }
            this.specGraph3.DrawSpec(slst);
            this.specGraph3.SetTitle("参与拟合的光谱集合");
            this.specGraph3.SetLenged();

            this.ShowDialog();
        }
예제 #2
0
        private void ShowfitGrid(FittingResult result)
        {
            this.gridFit.Rows.Clear();
            this.gridId.Visible  = false;
            this.gridPLS.Visible = false;
            this.gridFit.Visible = true;

            this.gridItg.Visible = false;

            if (result == null || result.Specs.Length == 0)
            {
                return;
            }
            int k = 1;

            foreach (var item in result.Specs)
            {
                var cell = new DataGridViewRowHeaderCell()
                {
                    Value = k.ToString()
                };
                var row = new MyDataFitRow()
                {
                    Item       = item,
                    HeaderCell = cell
                };
                if (k == 1)
                {
                    row.CreateCells(this.gridFit, item.Spec.UUID, item.Rate.ToString("F4"), result.TQ.ToString("F4"), result.SQ.ToString("F4"));
                }
                else
                {
                    row.CreateCells(this.gridFit, item.Spec.UUID, item.Rate.ToString("F4"));
                }
                this.gridFit.Rows.Add(row);
                k++;
            }
        }
예제 #3
0
 public nodeRow(FittingResult result)
 {
     this._result = result;
 }
예제 #4
0
        private void AddResult(FittingResult r)
        {
            if (!this._inited)
            {
                this.Init();
            }
            if (r == null)
            {
                return;
            }
            this._results.Add(r);
            if (!this._compShow)
            {
                var names = r.FitSpec.Components.Select(c => c.Name).ToArray();
                for (int i = 0; i < names.Length; i++)
                {
                    if (i < this._dColnum - 5 && this.Columns.Count > (5 + i))
                    {
                        this.Columns[5 + i].HeaderText = names[i];
                    }
                    else
                    {
                        this.Columns.Add(new DataGridViewTextBoxColumn()
                        {
                            Width      = 60,
                            HeaderText = names[i],
                            ReadOnly   = true,
                        });
                    }
                }
                this._compShow = true;
            }



            nodeRow node;

            if (this.Nodes.Count <= (this._results.Count - 1) * 3)
            {
                node = new nodeRow(r);
                this.Nodes.Add(node);
            }
            else
            {
                node        = this.Nodes[(this._results.Count - 1) * 3] as nodeRow;
                node.Result = r;
            }
            node.Cells[0].Value = r.SpecOriginal.Name;
            node.Cells[1].Value = "";
            node.Cells[2].Value = r.TQ.ToString("F4");
            node.Cells[3].Value = r.SQ.ToString("F4");
            node.Cells[4].Value = r.Result;
            var cidx = 5;

            foreach (var c in r.SpecOriginal.Components)
            {
                node.Cells[cidx].Value = double.IsNaN(c.ActualValue) ? "" : c.ActualValue.ToString(string.Format("F{0}", c.Eps));
                cidx++;
            }


            foreach (var d in r.Specs)
            {
                var ds = new List <object>();
                ds.Add(d.Spec.Name);
                ds.Add(d.Rate.ToString("F4"));
                ds.Add("");
                ds.Add("");
                ds.Add("");
                foreach (var c in d.Spec.Components)
                {
                    ds.Add(c.ActualValue.ToString(string.Format("F{0}", c.Eps)));
                }
                node.Nodes.Add(ds.ToArray());
            }



            //预测值
            var objs = new List <object>();

            objs.Add("预测值");
            objs.Add("");
            objs.Add("");
            objs.Add("");
            objs.Add("");
            foreach (var c in r.FitSpec.Components)
            {
                objs.Add(double.IsNaN(c.PredictedValue) ? "" : c.PredictedValue.ToString(string.Format("F{0}", c.Eps)));
            }

            if (this.Nodes.Count <= (this._results.Count - 1) * 3 + 1)
            {
                this.Nodes.Add(objs.ToArray());
            }
            else
            {
                var tn = this.Nodes[(this._results.Count - 1) * 3 + 1];
                for (int i = 0; i < objs.Count; i++)
                {
                    if (tn.Cells.Count > i)
                    {
                        tn.Cells[i].Value = objs[i];
                    }
                }
            }

            //偏差

            objs = new List <object>();
            objs.Add("偏差");
            objs.Add("");
            objs.Add("");
            objs.Add("");
            objs.Add("");
            if (r.SpecOriginal.Components != null && r.FitSpec.Components.Count > 0)
            {
                for (int i = 0; i < r.FitSpec.Components.Count; i++)
                {
                    r.SpecOriginal.Components[i].Error = r.SpecOriginal.Components[i].ActualValue - r.FitSpec.Components[i].PredictedValue;

                    objs.Add(double.IsNaN(r.SpecOriginal.Components[i].Error) ? "" : r.SpecOriginal.Components[i].Error.ToString(string.Format("F{0}", r.SpecOriginal.Components[i].Eps)));
                }
            }
            if (this.Nodes.Count <= (this._results.Count - 1) * 3 + 2)
            {
                this.Nodes.Add(objs.ToArray());
            }
            else
            {
                var tn = this.Nodes[(this._results.Count - 1) * 3 + 2];
                for (int i = 0; i < objs.Count; i++)
                {
                    if (tn.Cells.Count > i)
                    {
                        tn.Cells[i].Value = objs[i];
                    }
                }
            }
        }