private void button5_Click(object sender, EventArgs e) { var specbase = new SpecBase(@"F:\3506\15chemometrics\RIPP_DEMO\algorithm\原油测试数据\密度.Lib"); var model = new SubPLS1Model(); model.Comp = specbase.First().Components.First(); model.MaxFactor = 20; // var model = new IdentifyModel() { Wind = 11, MinSQ = 0.98, TQ = 0.998 }; model.Filters = new List <IFilter>(); model.Filters.Add(new Sgdiff(21, 2, 2)); //model.Filters.Add(new SavitzkyGolay(5)); var xidx = new List <RegionPoint>(); xidx.Add(new RegionPoint(4002, 4702)); xidx.Add(new RegionPoint(5302, 6102)); var varregion = new VarRegionManu(); var argu = varregion.Argus; argu["XaxisRegion"].Value = xidx; argu["Xaxis"].Value = specbase.First().Data.X; varregion.Argus = argu; model.Filters.Add(varregion); for (int i = 0; i < 10; i++) { var cv = new CrossValidation <SubPLS1Result>(model); DateTime dt1 = DateTime.Now; //cv.CV(specbase, false); //var span1 = (DateTime.Now - dt1).TotalMilliseconds; dt1 = DateTime.Now; cv.CV(specbase, true); var span2 = (DateTime.Now - dt1).TotalMilliseconds; } }
// [TestMethod] public void fiiting() { var specbase = new SpecBase(@"F:\3506\15chemometrics\RIPP_DEMO\algorithm\原油测试数据\crude.Lib"); var model = new FittingModel() { Wind = 11, MinSQ = 0.98, TQ = 0.998 }; // var model = new IdentifyModel() { Wind = 11, MinSQ = 0.98, TQ = 0.998 }; model.Filters = new List <IFilter>(); model.Filters.Add(new Sgdiff(21, 2, 2)); model.Filters.Add(new SavitzkyGolay(5)); var xidx = new List <RegionPoint>(); xidx.Add(new RegionPoint(4002, 4702)); xidx.Add(new RegionPoint(5302, 6102)); var varregion = new VarRegionManu(); var argu = varregion.Argus; argu["XaxisRegion"].Value = xidx; argu["Xaxis"].Value = specbase.First().Data.X; varregion.Argus = argu; model.Filters.Add(varregion); model.Filters.Add(new NormPathLength()); model.FiltersForIdentify = Serialize.DeepClone <IList <IFilter> >(model.Filters); var vspecbase = specbase.Clone(); vspecbase.Clear(); foreach (var s in specbase) { if (s.Usage == UsageTypeEnum.Calibrate) { vspecbase.Add(s.Clone()); } } var dd = RIPP.NIR.Data.Preprocesser.Process(model.Filters, vspecbase); var writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\fit\filterd.mat"); writer.WriteMatrix <double>(dd.GetX(), "filterd"); writer.Close(); var cv = new CrossValidation <FittingResult>(model); var lst = cv.CV(specbase); var allTQ = new DenseVector(specbase.Where(d => d.Usage == UsageTypeEnum.Calibrate).Count()); var allSQ = new DenseVector(specbase.Where(d => d.Usage == UsageTypeEnum.Calibrate).Count()); var allRate = new DenseMatrix(5, specbase.Where(d => d.Usage == UsageTypeEnum.Calibrate).Count()); for (int i = 0; i < lst.Count; i++) { allTQ[i] = lst[i].TQ; allSQ[i] = lst[i].SQ.Min(); var ddd = lst[i].Specs.Select(d => d.Rate); for (int k = 0; k < 5; k++) { if (k >= ddd.Count()) { break; } allRate[k, i] = ddd.ElementAt(k); } } writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\fit\tq.mat"); writer.WriteMatrix <double>(allTQ.ToColumnMatrix(), "TQ"); writer.Close(); writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\fit\sq.mat"); writer.WriteMatrix <double>(allSQ.ToColumnMatrix(), "SQ"); writer.Close(); writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\fit\result.mat"); writer.WriteMatrix <double>(allRate, "allRate"); writer.Close(); }
// [TestMethod] public void Identify() { var specbase = new SpecBase(@"F:\3506\15chemometrics\RIPP_DEMO\algorithm\原油测试数据\crude.Lib"); var model = new IdentifyModel() { Wind = 11, MinSQ = 0.98, TQ = 0.998 }; model.Filters = new List <IFilter>(); model.Filters.Add(new Sgdiff(21, 2, 2)); model.Filters.Add(new SavitzkyGolay(5)); var xidx = new List <RegionPoint>(); xidx.Add(new RegionPoint(4002, 4702)); xidx.Add(new RegionPoint(5302, 6102)); var varregion = new VarRegionManu(); var argu = varregion.Argus; argu["XaxisRegion"].Value = xidx; argu["Xaxis"].Value = specbase.First().Data.X; varregion.Argus = argu; model.Filters.Add(varregion); model.Filters.Add(new NormPathLength()); var vspecbase = specbase.Clone(); vspecbase.Clear(); foreach (var s in specbase) { if (s.Usage == UsageTypeEnum.Calibrate) { vspecbase.Add(s.Clone()); } } var dd = RIPP.NIR.Data.Preprocesser.Process(model.Filters, vspecbase); var writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\id\filterd.mat"); writer.WriteMatrix <double>(dd.GetX(), "filterd"); writer.Close(); var cv = new CrossValidation <IdentifyResult>(model); var lst = cv.CV(specbase); var allTQ = new DenseMatrix(5, specbase.Where(d => d.Usage == UsageTypeEnum.Calibrate).Count()); var allSQ = new DenseMatrix(5, specbase.Where(d => d.Usage == UsageTypeEnum.Calibrate).Count()); var allResult = allSQ.Clone(); for (int i = 0; i < lst.Count; i++) { var tq = new DenseVector(lst[i].Items.Select(d => d.TQ).ToArray()); var sq = new DenseVector(lst[i].Items.Select(d => d.SQ).ToArray()); var resulttt = new DenseVector(lst[i].Items.Select(d => Convert.ToDouble(d.Result)).ToArray()); allTQ.SetColumn(i, tq.SubVector(0, 5)); allSQ.SetColumn(i, sq.SubVector(0, 5)); allResult.SetColumn(i, resulttt.SubVector(0, 5)); } writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\id\tq.mat"); writer.WriteMatrix <double>(allTQ, "TQ"); writer.Close(); writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\id\sq.mat"); writer.WriteMatrix <double>(allSQ, "SQ"); writer.Close(); writer = new MatlabMatrixWriter(@"F:\3506\15chemometrics\RIPP_DEMO\src\RIPP\testdata\id\result.mat"); writer.WriteMatrix <double>(allResult, "result"); writer.Close(); }