histogram#

class histogram(values=None, bins=None, density=False, data=None, **kwargs)[source]#

Bases: Dist

Sample from a histogram with defined bins

Note: unlike other distributions, the parameters of this distribution can’t be modified after creation.

Parameters:
  • values (array) – the probability (or count) of each bin

  • bins (array) – the edges of each bin

  • density (bool) – treat the histogram as a density instead of counts; only matters with unequal bin widths, see numpy.histogram and scipy.stats.rv_histogram for more information

  • data (array) – if supplied, compute the values and bin edges using this data and np.histogram() instead

Note: if the length of bins is equal to the length of values, they will be interpreted as left bin edges, and one additional right-bin edge will be added based on the difference between the last two bins (e.g. if the last two bins are 40 and 50, the final right edge will be added at 60). If no bins are supplied, then they will be created as integers matching the length of the values.

The values can be supplied in either normalized (sum to 1) or un-normalized format.

Examples:

# Sample from an age distribution
age_bins = [0,    10,  20,  40,  65, 100]
age_vals = [0.1, 0.1, 0.3, 0.3, 0.2]
h1 = ss.histogram(values=age_vals, bins=age_bins, strict=False)
h1.plot_hist()

# Create a histogram from data
data = np.random.randn(10_000)*2+5
h2 = ss.histogram(data=data, strict=False)
h2.plot_hist(bins=100)

Attributes

bitgen

state

Get the current state

state_int

Get the integer corresponding to the current state

Methods