示例#1
0
        public BindResult PredictForAPI(Spectrum spec, bool needFilter = true, int numOfId = 5, int topK = 1)
        {
            if (this.IdModels.Count > 0)
            {
                IdentifyResult iresult = null;
                foreach (var i in this.IdModels)
                {
                    iresult = CombineIdResult(iresult, i.Predict(spec, needFilter, numOfId, topK));
                }
                if (iresult != null && iresult.Items.Where(d => d.Result).Count() > 0)
                {
                    iresult = IdentifyModel.GetPredictValue(iresult, iresult.Items.Length, numOfId);
                    return(new BindResult()
                    {
                        MethodType = PredictMethod.Identify,
                        Result = iresult
                    });
                }
            }
            if (this.FitModels.Count > 0)
            {
                var fitmodel = Serialize.DeepClone <FittingModel>(this.FitModels.First());
                for (int i = 1; i < this.FitModels.Count; i++)
                {
                    fitmodel.SpecLib.Merger(this.FitModels[i].SpecLib);
                }

                var flst = new List <FittingResult>();//这里需要修改,将List<FittingResult>改为FittingResult
                flst.Add(fitmodel.Predict(spec, needFilter, numOfId, topK));
                if (flst.Where(d => d.Result).Count() > 0)
                {
                    return new BindResult()
                           {
                               MethodType = PredictMethod.Fitting,
                               Result     = flst.Where(d => d.Result).OrderByDescending(d => d.TQ).FirstOrDefault()
                           }
                }
                ;
            }
            if (this.PLS != null)
            {
                var plsr = this.PLS.Predict(spec, needFilter, numOfId);
                return(new BindResult()
                {
                    MethodType = PredictMethod.PLSBind,
                    Result = plsr
                });
            }

            return(new BindResult()
            {
                MethodType = PredictMethod.None
            });
        }
示例#2
0
        /// <summary>
        /// 获取预测出来的性质
        /// </summary>
        /// <returns></returns>
        public ComponentList GetPredictComp(int num = 5, int numOfId = 5)
        {
            ComponentList c;

            switch (this.MethodType)
            {
            case PredictMethod.Fitting:
                var r1 = this.GetResult <FittingResult>();
                c = r1.FitSpec.Components;
                break;

            case PredictMethod.Identify:
                var r2 = this.GetResult <IdentifyResult>();
                r2 = IdentifyModel.GetPredictValue(r2, num, numOfId);
                c  = r2.Components;
                break;

            case PredictMethod.PLSBind:
                var r3 = this.GetResult <List <PLS1Result> >();
                c = new ComponentList();
                foreach (var cc in r3.Select(d => d.Comp))
                {
                    c.Add(cc);
                }
                break;

            case PredictMethod.Integrate:
                var r4 = this.GetResult <List <IntegrateResultItem> >();
                c = new ComponentList();
                foreach (var i in r4)
                {
                    var cc = i.Comp;
                    if (i.ConfidenceOutter < 90)
                    {
                        cc.State = i.ConfidenceOutter > 80 ? ComponentStatu.Blue : ComponentStatu.Red;
                    }
                    c.Add(cc);
                }
                break;

            default:
                c = null;
                break;
            }
            return(c);
        }
        /// <summary>
        /// 获取预测出来的性质
        /// </summary>
        /// <param name="num">识别最大个数</param>
        /// <returns></returns>
        public Component GetResult(int num)
        {
            Component idc = null, fc = null, pls1c = null, annc = null, result = this.Comp.Clone();

            //识别
            if (this.IDResult != null && this.IDResult.IsId)
            {
                var clst = IdentifyModel.GetPredictValue(this.IDResult, num);
                idc = clst.Components.FirstOrDefault();
            }
            if (this.FitResult != null)
            {
                fc = this.FitResult.FitSpec.Components.FirstOrDefault();
            }
            if (this.PLS1Result != null)
            {
                pls1c = this.PLS1Result.Comp;
            }
            if (this.PLSANNResult != null)
            {
                annc = this.PLSANNResult.Comp;
            }
            result.PredictedValue = 0;

            bool needavg = false;

            if (idc == null && this.IDRate > 0)
            {
                needavg = true;
            }
            if (fc == null && this.FitRate > 0)
            {
                needavg = true;
            }
            if (needavg)
            {
                int countResult = 0;
                if (idc != null)
                {
                    result.PredictedValue += idc.PredictedValue;
                    countResult++;
                }
                if (fc != null)
                {
                    result.PredictedValue += fc.PredictedValue;
                    countResult++;
                }
                if (pls1c != null)
                {
                    result.PredictedValue += pls1c.PredictedValue;
                    countResult++;
                }
                if (annc != null)
                {
                    result.PredictedValue += annc.PredictedValue;
                    countResult++;
                }
                if (countResult > 0)
                {
                    result.PredictedValue = result.PredictedValue / countResult;
                }
            }
            else
            {
                if (idc != null)
                {
                    result.PredictedValue += idc.PredictedValue * this.IDRate / 100.0;
                }
                if (fc != null)
                {
                    result.PredictedValue += fc.PredictedValue * this.FitRate / 100.0;
                }
                if (pls1c != null)
                {
                    result.PredictedValue += pls1c.PredictedValue * this.PLS1Rate / 100.0;
                }
                if (annc != null)
                {
                    result.PredictedValue += annc.PredictedValue * this.PLSANNRate / 100.0;
                }
            }
            return(result);
        }