Skip to content

Using the standalone classes and functions

Different histograms can be computed using the available standalone classes and functions jackHI provides in the hogg_jackknife module.

Count histogram

Simple histogram with bins of specific width

To make a simple histogram that displays the counts per bin, one can execute:

from hogg_jackknife import UserBools, UserInput, histogram_blas_spec_width
import numpy as np

# set up the input objects
my_bools = UserBools(selection_string="count") # use 'neg' if negative values are included
my_input = UserInput(
    data_arr=np.array([0.25, 1.25, 2.50, 4.00]),
    min_nr_bins=0,
)
my_input.initialize_for_specific_width(
    bin_phase=0.0, # no binning phase
    bin_nr=10, # use 10 bins
    data_min=0.0, # set the data minimum to zero
    bin_width=0.5, # define the bin width
)

# compute the histogram
histogram_counts = histogram_blas_spec_width(
    user_bools=my_bools,
    user_input=my_input,
)

This should return [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0].

Hogg optimization procedure (specific width)

A more interesting example maximizes the jackknife likelihood of a small data array:

from hogg_jackknife import (
    UserBools,
    UserHoggBools,
    UserHoggInput,
    hogg_jackknife_likelihood_blas,
)
import numpy as np

# set up the input objects
my_bools = UserBools(selection_string="count")
hogg_bools = UserHoggBools(selection_string="verbretbin") # verbose + return binning parameters
hogg_input = UserHoggInput(
    data_arr=np.array([0.0, 1.0, 2.0, 3.0, 10.0, 10.5, 11.0, 19.0, 18.0, 20.0, 28.0, 36.0, 42.0, 50.0, 45.0]),
    alpha_parameters=np.array([0.2, 1.0, 2.0]), # set alpha smoothing parameters
    bin_numbers=np.arange(1, 10, 1), # set a variety of bin numbers
    bin_phases=np.linspace(0.0, 0.3, num=31, endpoint=True), # set a variety of binning phases
    custom_bin_width=None,
)

# compute the optimized histogram and return the binning parameters
(
    histogram_counts,
    histogram_edges,
    max_bin_widths,
    binning_parameters,
) = hogg_jackknife_likelihood_blas(
    user_bools=my_bools,
    hogg_bools=hogg_bools,
    hogg_input=hogg_input,
)

The expected optimized values are:

histogram_counts = np.array(
    [10.0, 2.0, 3.0],
)
histogram_edges = np.array(
    [0.0, 50.0/3.0, 100.0/3.0, 50.0],
)
max_bin_widths = np.array(
    [50.0/3.0],
) # single bin width, as expected
binning_parameters = {
    "binning alpha": 2.0,
    "nr of bins": 3,
    "binning phase": 0.21,
}

Simple histogram with specific (logarithmic) bin edges

To make a simple histogram that displays the counts per logarithmic bin, one can execute:

from hogg_jackknife import UserBools, UserInput, histogram_blas_log_spec_edges
import numpy as np

# set up the input objects
my_bools = UserBools(selection_string="count")
my_input = UserInput(
    data_arr=np.array([0.01, 0.2, 2.00, 20.0, 200.0]),
    min_nr_bins=0,
)
my_input.initialize_for_specific_edges(
    bin_edges=np.logspace(-2,3,num=6), # from 0.01 to 1000.0
)

# compute the count histogram
histogram_counts = histogram_blas_log_spec_edges(
    user_bools=my_bools,
    user_input=my_input,
)

This should return [1.0, 1.0, 1.0, 1.0, 1.0].

Hogg optimization procedure (specific logarithmic width)

A more interesting example maximizes the jackknife likelihood of a small data array in log-space:

from hogg_jackknife import (
    UserBools,
    UserHoggBools,
    UserHoggInput,
    hogg_jackknife_likelihood_blas_log,
)

# set up the input objects
my_hogg_input = UserHoggInput(
    data_arr=np.array([0.01, 0.2, 2.00, 20.0, 100.0]),
    alpha_parameters=np.array([0.2, 1.0, 2.0]),
    bin_numbers=np.array([1, 2, 4]),
    bin_phases=np.array([0.25, 0.5, 0.75]),
    custom_bin_width=None,
)
my_bools = UserBools(selection_string="count")
my_hogg_bools = UserHoggBools(selection_string="verbretbin")

# compute the optimized histogram and return the binning parameters
(
    histogram_counts,
    histogram_edges,
    max_bin_widths,
    binning_parameters,
) = hogg_jackknife_likelihood_blas_log(
    user_bools=my_bools,
    hogg_bools=my_hogg_bools,
    hogg_input=my_hogg_input,
)

The expected optimized values are:

histogram_counts = np.array(
    [1.0, 1.0, 1.0, 2.0],
)
histogram_edges = np.array(
    [0.01, 0.1, 1.0, 10.0, 100.0],
)
max_bin_widths = np.array(
    [0.09, 0.9, 9.0, 90.0],
) # single bin width, as expected
binning_parameters = {
    "binning alpha": 2.0,
    "nr of bins": 4,
    "binning phase": 0.25,
}