private void RebuildWindow() { //重新计算r this.R = ValidateWindow.CalcRValue(this.RawValues); //计算R值 var cv = ValidateWindow.GetCoefficientOfVariationValue(this.RawValues); if (cv < this.KThreshold) { this._invalidCount = 0; foreach (var value in this._windowDatas) { value.ValidValue = value.RawValue; value.IsValid = true; } } }
private bool ValidateValue(AnalysisValue value) { var validValues = this.ValidValues; if (ValidateWindow.GetDiscreteCount(value.RawValue, validValues, this.R) > this.DiscreteThreshold) { value.IsValid = false; value.ValidValue = ValidateWindow.CalcMeanValue(validValues); } else { value.IsValid = true; value.ValidValue = value.RawValue; } //过滤完就填充 this._windowDatas.RemoveAt(0); this._windowDatas.Add(value); return(value.IsValid); }
/// <summary> /// 初始化稳定窗口 /// </summary> /// <param name="seed"></param> //public void ReCreateWindow(decimal seed) //{ // if (seed == SeedInit) // { // } // _windowDatas.Clear(); // for (var i = 0; i < _windowSize; i++) // { // _windowDatas.Add(new AnalysisValue(seed)); // } //} /// <summary> /// 过滤数据 /// </summary> /// <param name="value"></param> public void ProcessValue(AnalysisValue value) { if (this.IsOpenWindow) { _log.Debug(this.ToSimpleString()); } if (value == null) { return; } //复制一份放在窗口里面 var tempValue = new AnalysisValue(value.RawValue, value.IsValid); tempValue.ValidValue = tempValue.RawValue; //未过滤之前数据就是原始值 value.ValidValue = value.RawValue; try { //考虑到先对数据过滤,后面又暂停了! if (!this.IsOpenWindow) { if (this._windowDatas.Count < this._windowSize) { this.InsertDate(tempValue); } else { this.RemoveInsertData(tempValue); } return; } if (this._windowDatas.Count == this._windowSize && this._windowDatas.Count > 0) //窗口已满,有数据 { //包含了窗口和变异系数的变化 if (this.R == Rinitvalue) { this.R = ValidateWindow.CalcRValue(this.RawValues, this.KThreshold); //初始化 } if (this.ValidateValue(tempValue) == false) //值无效 { value.IsValid = tempValue.IsValid; value.ValidValue = tempValue.ValidValue; if (this._invalidCount++ >= this.ReCalcRValueThreshold) { this.RebuildWindow(); } } //调整位置 var cv = ValidateWindow.GetCoefficientOfVariationValue(this.ValidValues); if (cv > this.KThreshold) { this.R = ValidateWindow.CalcRValue(this.RawValues, this.KThreshold); //初始化 } if (this.NeedLog) { //打印出数据 _log.Debug(this.ToString()); _log.Debug(tempValue.ToString()); } } else //窗口未满 { this.InsertDate(tempValue); } } catch (UnStableWindowExcepiton ex) { //不稳定怎么处理--继续滑动窗口 this.RemoveInsertData(tempValue); } //Dump(null, null); }