[10148] | 1 | using System;
|
---|
[10165] | 2 | using System.Linq;
|
---|
[10216] | 3 | using HeuristicLab.Common;
|
---|
[10148] | 4 |
|
---|
| 5 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10165] | 6 |
|
---|
[10183] | 7 | public class StatisticInfo : IStatisticInfo {
|
---|
[10148] | 8 |
|
---|
[10159] | 9 | private IPreprocessingData preprocessingData;
|
---|
[10148] | 10 |
|
---|
[10180] | 11 | public StatisticInfo(IPreprocessingData thePreprocessingData) {
|
---|
[10165] | 12 | preprocessingData = thePreprocessingData;
|
---|
[10148] | 13 | }
|
---|
| 14 |
|
---|
| 15 | public int GetColumnCount() {
|
---|
[10159] | 16 | return preprocessingData.Columns;
|
---|
[10148] | 17 | }
|
---|
| 18 |
|
---|
| 19 | public int GetRowCount() {
|
---|
[10159] | 20 | return preprocessingData.Rows;
|
---|
[10148] | 21 | }
|
---|
| 22 |
|
---|
| 23 | public int GetNumericColumnCount() {
|
---|
[10159] | 24 | int count = 0;
|
---|
[10183] | 25 | foreach (var variableName in preprocessingData.VariableNames) {
|
---|
| 26 | if (preprocessingData.IsType<double>(variableName)) {
|
---|
[10159] | 27 | ++count;
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | return count;
|
---|
[10148] | 31 | }
|
---|
| 32 |
|
---|
| 33 | public int GetNominalColumnCount() {
|
---|
[10159] | 34 | return preprocessingData.Columns - GetNumericColumnCount();
|
---|
[10148] | 35 | }
|
---|
| 36 |
|
---|
| 37 | public int GetMissingValueCount() {
|
---|
| 38 | int count = 0;
|
---|
[10183] | 39 | foreach (var variableName in preprocessingData.VariableNames) {
|
---|
| 40 | count += GetMissingValueCount(variableName);
|
---|
[10148] | 41 | }
|
---|
| 42 | return count;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[10183] | 45 | public int GetMissingValueCount(string variableName) {
|
---|
[10189] | 46 | return preprocessingData.GetMissingValueIndices(variableName).Count();
|
---|
[10148] | 47 | }
|
---|
| 48 |
|
---|
[10183] | 49 | public T GetMin<T>(string variableName) where T : IComparable<T> {
|
---|
| 50 | return preprocessingData.GetValues<T>(variableName).Min();
|
---|
[10148] | 51 | }
|
---|
| 52 |
|
---|
[10183] | 53 | public T GetMax<T>(string variableName) where T : IComparable<T> {
|
---|
| 54 | return preprocessingData.GetValues<T>(variableName).Max();
|
---|
[10148] | 55 | }
|
---|
| 56 |
|
---|
[10183] | 57 | public double GetMedian(string variableName) {
|
---|
[10166] | 58 | double median = double.NaN;
|
---|
[10183] | 59 | if (preprocessingData.IsType<double>(variableName)) {
|
---|
[10216] | 60 | median = preprocessingData.GetValues<double>(variableName).Median();
|
---|
[10166] | 61 | }
|
---|
| 62 | return median;
|
---|
[10148] | 63 | }
|
---|
| 64 |
|
---|
[10183] | 65 | public double GetAverage(string variableName) {
|
---|
[10166] | 66 | double avg = double.NaN;
|
---|
[10183] | 67 | if (preprocessingData.IsType<double>(variableName)) {
|
---|
| 68 | avg = preprocessingData.GetValues<double>(variableName).Average();
|
---|
[10166] | 69 | }
|
---|
| 70 | return avg;
|
---|
[10148] | 71 | }
|
---|
| 72 |
|
---|
[10183] | 73 | public T GetMostCommonValue<T>(string variableName) {
|
---|
| 74 | return preprocessingData.GetValues<T>(variableName)
|
---|
[10180] | 75 | .GroupBy(x => x)
|
---|
| 76 | .OrderByDescending(g => g.Count())
|
---|
| 77 | .Select(g => g.Key)
|
---|
| 78 | .First();
|
---|
[10148] | 79 | }
|
---|
| 80 |
|
---|
[10167] | 81 |
|
---|
[10183] | 82 | public double GetStandardDeviation(string variableName) {
|
---|
[10169] | 83 | double stdDev = double.NaN;
|
---|
[10183] | 84 | if (preprocessingData.IsType<double>(variableName)) {
|
---|
[10216] | 85 | stdDev = preprocessingData.GetValues<double>(variableName).StandardDeviation();
|
---|
[10169] | 86 | }
|
---|
| 87 | return stdDev;
|
---|
[10148] | 88 | }
|
---|
| 89 |
|
---|
[10216] | 90 | public double GetVariance(string variableName) {
|
---|
| 91 | double stdDev = double.NaN;
|
---|
| 92 | if (preprocessingData.IsType<double>(variableName)) {
|
---|
| 93 | stdDev = preprocessingData.GetValues<double>(variableName).Variance();
|
---|
| 94 | }
|
---|
| 95 | return stdDev;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[10183] | 98 | public int GetDifferentValuesCount<T>(string variableName) {
|
---|
| 99 | return preprocessingData.GetValues<T>(variableName).GroupBy(x => x).Count();
|
---|
[10179] | 100 | }
|
---|
[10191] | 101 |
|
---|
| 102 | public int GetRowMissingValueCount(int rowIndex) {
|
---|
| 103 | int count = 0;
|
---|
| 104 | foreach (var variableName in preprocessingData.VariableNames) {
|
---|
| 105 | if (preprocessingData.IsMissingValue(variableName, rowIndex)) {
|
---|
| 106 | ++count;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | return count;
|
---|
| 110 | }
|
---|
[10148] | 111 | }
|
---|
| 112 | }
|
---|