private void CalcBin_ShowGraph(TireDataColumn column) { TireDataSet tds = Editor.SelectedDataSet; if (SourceCB.SelectedItem as ProjectTree.Node_TireDataSet != null) { var ntds = SourceCB.SelectedItem as ProjectTree.Node_TireDataSet; tds = ntds.GetIDataSet().GetDataSet(); } var table = (TableCB.SelectedItem as Table?).Value; Target = new List <double>(); foreach (var data in tds.GetDataList(table)) { Target.Add(data[column]); } Target.Sort(); MainChart.Series[SeriesData].Points.Clear(); if (Target.Count == 0) { return; } var max = tds.MaxminSet.Limit(table).Max[column]; var min = tds.MaxminSet.Limit(table).Min[column]; var bin = CalculateMinimumEntropyBin(Target, TireData.Resolution()[column], max, min); double dif = (max - min) / bin.Count; for (int i = 0; i < bin.Count; ++i) { var data = new DataPoint(i * dif + dif / 2 + min, bin[i]); MainChart.Series[SeriesData].Points.Add(data); } //選択 SortedBin = new List <Tuple <int, double> >(bin.Count); for (int i = 0; i < bin.Count; ++i) { SortedBin.Add(new Tuple <int, double>(i, bin[i])); } SortedBin.Sort(delegate(Tuple <int, double> ls, Tuple <int, double> rh) { if (ls.Item2 == rh.Item2) { return(0); } return(ls.Item2 - rh.Item2 > 0 ? -1 : 1); } ); Bin = bin; SelectBin(column); }
void CalculateMinimumEntropy(List <double> list, double max, double min) { int i = fistBins; NumBins = i; int count = 0; double minentropy = double.MaxValue; double entropy; var Bin = new List <int>(NumBins); int NumBinsMax = (int)((max - min) / TireData.Resolution()[Column]); Highest = 0; int HighestTemp = 0; while (count < 100 && i < NumBinsMax) { Bin.Clear(); entropy = CalculateEntropy(i, list, max, min, Bin); if (entropy > minentropy) { ++count; } else { HighestTemp = Highest; NumBins = i; count = 0; minentropy = entropy; } i = (int)Math.Round(i * coe); } Highest = (int)(HighestTemp * 1.1); if (HighestTemp == 0) { entropy = CalculateEntropy(i, list, max, min, Bin); Highest = (int)(Highest * 1.1); } }