Skip to content

HistStat

Mojo struct 🡭

HistStat

@memory_only
struct HistStat

Select how histogram_bins() and histogram() normalize bins.

Here w[i] is bin i’s weight, W is the total included weight, and width[i] is edges[i + 1] - edges[i]:

Stat Bin value Totals to
COUNT w[i] W
FREQUENCY w[i] / width[i] W after multiplying by width
PROBABILITY w[i] / W 1
PERCENT 100 * w[i] / W 100
DENSITY w[i] / (W * width[i]) 1 after multiplying by width

Use FREQUENCY or DENSITY to account for unequal bin widths.

Aliases

  • COUNT = HistStat(Int(0)): Observation count, or total weight, in each bin.
  • FREQUENCY = HistStat(Int(1)): Observation count or weight per unit of x.
  • PROBABILITY = HistStat(Int(2)): Fraction of included weight in each bin; heights sum to 1.
  • PERCENT = HistStat(Int(3)): Percentage of included weight in each bin; heights sum to 100.
  • DENSITY = HistStat(Int(4)): Probability density; bar areas sum to 1.

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods

__init__

fn def __init__(out self, value: Int)

Prefer the COUNT/FREQUENCY/PROBABILITY/PERCENT/ DENSITY comptime constants over constructing one directly.

Args:

  • value (Int): 0 for COUNT, 1 for FREQUENCY, 2 for PROBABILITY, 3 for PERCENT, 4 for DENSITY.
  • self (Self)

Returns:

Self

__eq__

fn def __eq__(self, other: Self) -> Bool

Whether both name the same stat.

Args:

  • self (Self)
  • other (Self): The stat to compare against.

Returns:

Bool: True when they match.

__ne__

fn def __ne__(self, other: Self) -> Bool

Whether the two name different stats.

Args:

  • self (Self)
  • other (Self): The stat to compare against.

Returns:

Bool: True when they differ.

name

fn def name(self) -> String

This stat’s constant name, for error messages and axis captions that have to say which one was asked for.

Args:

  • self (Self)

Returns:

String: “COUNT”, “FREQUENCY”, “PROBABILITY”, “PERCENT”, “DENSITY”, or “HistStat()” for a value outside the five constants.