当前位置:网站首页>C # use laida criterion (3) σ Criteria) reject abnormal data (.Net reject singular values in a group of data)
C # use laida criterion (3) σ Criteria) reject abnormal data (.Net reject singular values in a group of data)
2022-04-23 07:48:00 【Dake mountain man】
1、 Problem presentation :
Battery production , The measurement result data of a batch of batteries :
| Voltage value | Number of batteries | Voltage value | Number of batteries | Voltage value | Number of batteries | Voltage value | Number of batteries | |||
| 0.056 | 1 | 4.09 | 1 | 4.146 | 17 | 4.174 | 13434 | |||
| 0.321 | 1 | 4.094 | 1 | 4.147 | 17 | 4.175 | 13973 | |||
| 0.767 | 1 | 4.099 | 2 | 4.148 | 19 | 4.176 | 13339 | |||
| 0.972 | 1 | 4.112 | 1 | 4.149 | 23 | 4.177 | 12275 | |||
| 3.098 | 1 | 4.119 | 3 | 4.15 | 26 | 4.178 | 10309 | |||
| 3.187 | 1 | 4.12 | 1 | 4.151 | 40 | 4.179 | 8376 | |||
| 3.319 | 1 | 4.121 | 1 | 4.152 | 50 | 4.18 | 6324 | |||
| 3.526 | 1 | 4.122 | 3 | 4.153 | 75 | 4.181 | 4667 | |||
| 3.53 | 1 | 4.125 | 3 | 4.154 | 84 | 4.182 | 3340 | |||
| 3.532 | 1 | 4.126 | 2 | 4.155 | 100 | 4.183 | 2358 | |||
| 3.54 | 1 | 4.127 | 1 | 4.156 | 118 | 4.184 | 1719 | |||
| 3.541 | 1 | 4.128 | 2 | 4.157 | 153 | 4.185 | 1199 | |||
| 3.544 | 1 | 4.129 | 3 | 4.158 | 173 | 4.186 | 839 | |||
| 3.545 | 2 | 4.13 | 2 | 4.159 | 248 | 4.187 | 622 | |||
| 3.832 | 1 | 4.132 | 2 | 4.16 | 335 | 4.188 | 417 | |||
| 3.928 | 1 | 4.133 | 2 | 4.161 | 419 | 4.189 | 304 | |||
| 3.93 | 1 | 4.134 | 4 | 4.162 | 540 | 4.19 | 170 | |||
| 3.951 | 1 | 4.135 | 1 | 4.163 | 731 | 4.191 | 124 | |||
| 3.963 | 1 | 4.136 | 5 | 4.164 | 962 | 4.192 | 77 | |||
| 3.972 | 1 | 4.137 | 4 | 4.165 | 1359 | 4.193 | 43 | |||
| 3.973 | 2 | 4.138 | 6 | 4.166 | 1846 | 4.194 | 44 | |||
| 4.045 | 1 | 4.139 | 9 | 4.167 | 2621 | 4.195 | 25 | |||
| 4.046 | 1 | 4.14 | 2 | 4.168 | 3728 | 4.196 | 20 | |||
| 4.079 | 1 | 4.141 | 6 | 4.169 | 5086 | 4.197 | 8 | |||
| 4.085 | 1 | 4.142 | 4 | 4.17 | 6822 | 4.198 | 9 | |||
| 4.087 | 1 | 4.143 | 6 | 4.171 | 8649 | 4.199 | 5 | |||
| 4.088 | 1 | 4.144 | 13 | 4.172 | 10210 | 4.2 | 3 | |||
| 4.089 | 1 | 4.145 | 14 | 4.173 | 12072 |
among , The voltage of some batteries is too low and too high , Does not conform to the normal distribution .
Now we need to eliminate these abnormal battery data .
2、 Methods the principle :
3σ The criterion is also known as the laida criterion , It assumes that a set of test data contains only random errors , The standard deviation is calculated and processed , Determine an interval according to a certain probability , If the error exceeds this range , It's not a random error, it's a gross error , Data containing this error should be eliminated .
In the normal distribution σ Represents the standard deviation ,μ For mean .x=μ That is, the axis of symmetry of the image
3σ principle :
The values are distributed in (μ-σ,μ+σ) The probability of 0.6827
The values are distributed in (μ-2σ,μ+2σ) The probability of 0.9544
The values are distributed in (μ-3σ,μ+3σ) The probability of 0.9974
It can be said that ,Y The values of are almost all concentrated in (μ-3σ,μ+3σ) Within the interval , There is no possibility of going beyond that 0.3%.
3、C# The concrete realization of :
// Define voltage - Class of quantitative relationship
public class VoltageCount
{
public Double Voltage { get; set; }
public int CountV { get; set; }
public VoltageCount()
{
}
public VoltageCount(Double voltage, int countV)
{
this.Voltage = voltage;
this.CountV = countV;
}
}
// Key classes use the laida criterion (3σ Rules ) Eliminate data exceptions
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Photo.QQAA.Net.Helper
{
/// <summary>
/// Use the laida rule (3σ Rules ) Eliminate data exceptions
/// </summary>
public class ExceptionVoltageHelper
{
List<VoltageCount> listVoltageCount;
double average = 0.0;
int _badDataCount = -1;// Number of singular values
/// <summary>
/// Get the number of singular values
/// </summary>
public int BadDataCount
{
get { return _badDataCount; }
}
public ExceptionVoltageHelper(List<VoltageCount> list)
{
this.listVoltageCount = list;
SetAverage();
}
/// <summary>
/// Obtain the average voltage value
/// </summary>
/// <returns></returns>
protected double GetAvgVoltage()
{
double avg = 0;
double total = 0;
int allCount = 0;
foreach (VoltageCount vc in listVoltageCount)
{
double v = vc.Voltage;
int c = vc.CountV;
total += v * c;
allCount += c;
}
avg = total / (allCount * 1.0);
return Math.Round(avg, 3, MidpointRounding.AwayFromZero);
}
/// <summary>
/// Average
/// </summary>
/// <returns></returns>
void SetAverage()
{
this.average = GetAvgVoltage();
}
/// <summary>
/// Standard deviation
/// </summary>
/// <returns></returns>
double StandardDeviation()
{
List<double> listDataV = new List<double>();
foreach (VoltageCount vc in this.listVoltageCount)
{
double v = vc.Voltage;
int countV = vc.CountV;
for (int i = 0; i < countV; i++ )
{
listDataV.Add((v - this.average) * (v - this.average));
}
}
double sumDataV = listDataV.Sum();
double std = Math.Sqrt(sumDataV / (listDataV.Count - 1));
return std;
}
public List<VoltageCount> GetGoodList()
{
_badDataCount = 0;
double sd3 = StandardDeviation() * 3;//3 Times the standard deviation
List<VoltageCount> listVC = new List<VoltageCount>();
foreach (VoltageCount vc in this.listVoltageCount)
{
if (Math.Abs(vc.Voltage - this.average) <= sd3)
{
listVC.Add(vc);
}
else
{
_badDataCount += vc.CountV;
}
}
return listVC;
}
}
}
4、 Limitations and precautions :
Ben 3σ The rule is limited to the processing of sample data with normal or approximate normal distribution , It is also applicable when there are many groups of data .
The principle and method of this discrimination processing are based on the premise that the number of measurements is sufficiently large , When the number of measurements is small, it is not reliable to eliminate gross errors with criteria . therefore , In the case of fewer measurements , It's best not to use the guidelines , And use other criteria .
版权声明
本文为[Dake mountain man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230625378940.html
边栏推荐
猜你喜欢

ABAP 从CDS VIEW 发布OData Service示例

js之DOM事件

Super classic & Programming Guide (red and blue book) - Reading Notes

ABAP 7.4 SQL Window Expression

SAP ECC连接SAP PI系统配置

BTREE, B + tree and hash index

Mongodb starts warning information processing

int a = 1存放在哪

使用flask时代码无报错自动结束,无法保持连接,访问不了url。

SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
随机推荐
Shapley Explanation Networks
驼峰命名对像
Ogldev reading notes
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
Unity 获取一个资源被那些资源引用
Xamarin版的C# SVG路径解析器
FSM finite state machine
js之作用域、作用域链、全局变量和局部变量
定位、修饰样式
基于NLP的软件安全研究(一)
Double sided shader
Mongodb starts warning information processing
Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism
Mvcc (multi version concurrency control)
Game assisted script development journey
SampleCameraFilter
Page dynamic display time (upgraded version)
解决在docker中部署mysql8, 密码正确但无法登陆MySQL问题
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
事件系统(二)多播事件