| | |
| | | /// <param name="numIntervals"></param> |
| | | /// <param name="filterNum">以最小值作为过滤的系数</param> |
| | | /// <returns></returns> |
| | | public static List<DataPoint> GetFrequencyDistribution(List<double> data, out List<double>[] datapoints, int numIntervals = 10,double filterNum=5 ) |
| | | public static List<DataPoint> GetFrequencyDistribution(List<Result> data, out List<DataPoint>[] datapoints, int numIntervals = 10,double filterNum=5 ) |
| | | { |
| | | |
| | | List<DataPoint> resultPoints = new List<DataPoint>(); |
| | | datapoints= new List<double>[numIntervals]; |
| | | datapoints= new List<DataPoint>[numIntervals]; |
| | | for(int i=0;i<numIntervals;i++) |
| | | { |
| | | datapoints[i]= new List<double>(); |
| | | datapoints[i]= new List<DataPoint>(); |
| | | } |
| | | // 设置置信水平 |
| | | |
| | |
| | | |
| | | |
| | | // 计算数据的最小值和最大值 |
| | | double minValue = data.Min(); |
| | | double maxValue = data.Max(); |
| | | double minValue = data.Min(x=>x.ObjFunctionValue); |
| | | double maxValue = data.Max(x => x.ObjFunctionValue); |
| | | |
| | | // 计算区间宽度 |
| | | double intervalWidth = (maxValue - minValue) / numIntervals; |
| | |
| | | int[] freqDist = new int[numIntervals]; |
| | | |
| | | // 计算各个区间的频率 |
| | | foreach (double x in data) |
| | | foreach (var xd in data) |
| | | { |
| | | var x = xd.ObjFunctionValue; |
| | | int index = (int)((x - minValue) / intervalWidth); |
| | | if (index < 0) // 数据小于最小值 |
| | | { |
| | | freqDist[0]++; |
| | | datapoints[0].Add(x); |
| | | datapoints[0].Add(new DataPoint() {XValue= x,Tag=xd }); |
| | | } |
| | | else if (index >= numIntervals) // 数据大于最大值 |
| | | { |
| | | freqDist[numIntervals - 1]++; |
| | | datapoints[numIntervals - 1].Add(x); |
| | | datapoints[numIntervals - 1].Add(new DataPoint() { XValue = x, Tag = xd }); |
| | | } |
| | | else // 数据在区间内 |
| | | { |
| | | freqDist[index]++; |
| | | datapoints[index].Add(x); |
| | | datapoints[index].Add(new DataPoint() { XValue = x, Tag = xd }); |
| | | } |
| | | } |
| | | double[] freqDistPersent =new double[numIntervals]; |