MCPcopy Create free account
hub / github.com/numpy/numpy / _hist_bin_doane

Function _hist_bin_doane

numpy/lib/histograms.py:164–196  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

_ptpFunction · 0.70
stdMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected