- Timestamp:
- 05/13/09 15:38:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/3.2/Statistics.cs
r1529 r1786 41 41 T minimum = enumerator.Current; 42 42 43 while (enumerator.MoveNext()) {43 while (enumerator.MoveNext()) { 44 44 T current = enumerator.Current; 45 if (current.CompareTo(minimum) < 0) {45 if (current.CompareTo(minimum) < 0) { 46 46 minimum = current; 47 47 } … … 65 65 T maximum = enumerator.Current; 66 66 67 while (enumerator.MoveNext()) {67 while (enumerator.MoveNext()) { 68 68 T current = enumerator.Current; 69 if (current.CompareTo(maximum) > 0) {69 if (current.CompareTo(maximum) > 0) { 70 70 maximum = current; 71 71 } … … 99 99 /// <returns></returns> 100 100 public static double Range(double[] values, int start, int end) { 101 if (start < 0 || start > values.Length || end < 0 || end > values.Length || start > end) {101 if (start < 0 || start > values.Length || end < 0 || end > values.Length || start > end) { 102 102 throw new InvalidOperationException(); 103 103 } … … 105 105 double minimum = values[start]; 106 106 double maximum = minimum; 107 for(int i = start; i < end; i++) { 108 if(values[i] > maximum) { 109 maximum = values[i]; 110 } 111 if(values[i] < minimum) { 112 minimum = values[i]; 107 for (int i = start; i < end; i++) { 108 if (!double.IsNaN(values[i])) { 109 if (values[i] > maximum) { 110 maximum = values[i]; 111 } 112 if (values[i] < minimum) { 113 minimum = values[i]; 114 } 113 115 } 114 116 } … … 124 126 int n = values.Length; 125 127 double sum = 0.0; 126 for (int i = 0; i < n; i++) {127 if (double.IsNaN(values[i])) {128 for (int i = 0; i < n; i++) { 129 if (double.IsNaN(values[i])) { 128 130 throw new NotFiniteNumberException(); 129 131 } else { … … 156 158 /// <returns></returns> 157 159 public static double Mean(double[] values, int start, int end) { 158 if (values.Length == 0) throw new InvalidOperationException();160 if (values.Length == 0) throw new InvalidOperationException(); 159 161 double sum = 0.0; 160 162 int n = 0; 161 for (int i = start; i < end; i++) {162 if (!double.IsNaN(values[i])) {163 for (int i = start; i < end; i++) { 164 if (!double.IsNaN(values[i])) { 163 165 sum += values[i]; 164 166 n++; … … 175 177 /// <returns></returns> 176 178 public static double Median(double[] values) { 177 if (values.Length == 0) throw new InvalidOperationException();179 if (values.Length == 0) throw new InvalidOperationException(); 178 180 int n = values.Length; 179 if (n == 0)181 if (n == 0) 180 182 return 0; 181 183 … … 186 188 187 189 // return the middle element (if n is uneven) or the average of the two middle elements if n is even. 188 if (n % 2 == 1) {190 if (n % 2 == 1) { 189 191 return sortedValues[n / 2]; 190 192 } else {
Note: See TracChangeset
for help on using the changeset viewer.