Module Hugin_kit.Stats
Statistics.
A statistic summarises data into tensors that a figure draws. It computes when it is called, with nx operations where its data lies, and reads no value back to the host: its results lie beside its data, on the data's set.
Histograms
type 'd bins = {- #
x : 'd Nx.float64_t;(*The left edge of each bin.
*) - #
x2 : 'd Nx.float64_t;(*The right edge of each bin.
*) - #
count : 'd Nx.float64_t;(*The number of values in each bin.
*) - #
density : 'd Nx.float64_t;(*Each count divided by its histogram's total count and by its bin's width.
*)
}The type for histograms on the device set 'd. x and x2 have the shape [|n|] for n bins, and the bin j runs from x.{j} to x2.{j}, with x2.{j} = x.{j+1}. count and density have the shape of the data with its last axis replaced by n: one histogram per index of the data's other axes, over the bins they share.
A figure draws the bin j as the rectangle from x to x2 along x and from 0. to count or density along y.
histogram ~bins v counts the values along the last axis of v into bins bins of equal width, one histogram per index of v's other axes. Values are converted to float64 first, as Nx.cast does.
- The bins span the finite values of all of
v, from the leastloto the greatesthi, which are the left edge of the first bin and the right edge of the last. If there is no finite value,lois0.andhiis1.. - So that every bin has a positive width, a span narrower than
w = 4. *. float bins *. m *. epsilon_float, withmthe greater ofabs_float loandabs_float hi, widens by the same amount on either side to the widthw, shifted to stay within the finite floats. Iflo = hi,wis at least1.. - A bin holds the values from its left edge included to its right edge excluded; the last bin holds its right edge too. Every finite value is in one bin, and NaN and infinities are in none.
- The densities of a histogram, times the widths of their bins, sum to
1., unless a bin is wider thanmax_float: its width is then infinite and its density0.. A histogram with no finite value has the densitynanin every bin, which a figure drops as missing.
bins defaults to Sturges' rule from the length n of the last axis: 1 + ceil (log2 n), and 1 for n <= 1.
Raises Invalid_argument if bins < 1, if v is a scalar, or if v is complex or boolean.