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