Doane's histogram bin estimator. Improved version of Sturges' formula which works better for non-normal data. See stats.stackexchange.com/questions/55134/doanes-formula-for-histogram-binning Parameters ---------- x : array_like Input data that is to be histogra
(x, range)
| 163 | |
| 164 | |
| 165 | def _hist_bin_doane(x, range): |
| 166 | """ |
| 167 | Doane's histogram bin estimator. |
| 168 | |
| 169 | Improved version of Sturges' formula which works better for |
| 170 | non-normal data. See |
| 171 | stats.stackexchange.com/questions/55134/doanes-formula-for-histogram-binning |
| 172 | |
| 173 | Parameters |
| 174 | ---------- |
| 175 | x : array_like |
| 176 | Input data that is to be histogrammed, trimmed to range. May not |
| 177 | be empty. |
| 178 | |
| 179 | Returns |
| 180 | ------- |
| 181 | h : An estimate of the optimal bin width for the given data. |
| 182 | """ |
| 183 | del range # unused |
| 184 | if x.size > 2: |
| 185 | sg1 = np.sqrt(6.0 * (x.size - 2) / ((x.size + 1.0) * (x.size + 3))) |
| 186 | sigma = np.std(x) |
| 187 | if sigma > 0.0: |
| 188 | # These three operations add up to |
| 189 | # g1 = np.mean(((x - np.mean(x)) / sigma)**3) |
| 190 | # but use only one temp array instead of three |
| 191 | temp = x - np.mean(x) |
| 192 | np.true_divide(temp, sigma, temp) |
| 193 | np.power(temp, 3, temp) |
| 194 | g1 = np.mean(temp) |
| 195 | return _ptp(x) / (1.0 + np.log2(x.size) + |
| 196 | np.log2(1.0 + np.absolute(g1) / sg1)) |
| 197 | return 0.0 |
| 198 | |
| 199 | |
| 200 | def _hist_bin_fd(x, range): |