6.10.94-stable
In this page
  1. Usage
  2. Reference

Histogram

The HistogramFloat && HistogramInt types are used to compute statistics on a set of numeric values. Exposed in the utils module

Both types provide a set of native functions that allow you to perform various operations on the histogram data, such as adding values, getting counts, computing intervals, calculating percentiles, and more.


Usage

Let’s create a histogram of float values and add some random normal distributed values to it.

var rng = Random::new();

// Create a new histogram
var histogram = HistogramFloat {};

for (var i = 0; i < 1000; i++) {
    // Add a random value to the histogram
    // rng.normal: Generates a random float from the normal distribution with average `5.0` and standard deviation `1.0`
    histogram.add(rng.normal(5.0, 1.0));
}

Reference

native type HistogramFloat {
  static table_off_from : int = 0;
  static table_off_to : int = 1;
  static table_off_count : int = 2;
  static table_off_percentage : int = 3;
  native fn setBounds(min: float, max: float);
  native fn clear();
  /// add a value to the histogram with default count=1
  native fn add(value: float?);
  native fn addWithCount(value: float?, count: int);
  /// get the count of a specific value
  native fn getCount(value: float?): int;
  native fn all(): Table<any>;
  /// get the count of values in an interval [From;To[
  native fn interval(from: float, to: float): Table<any>;
  /// split [from - to[ to N intervals and get the count of each interval in an table
  native fn sample(from: float, to: float, buckets: int): Table<any>;
  /// get the percentage of a certain value
  native fn percentage(value: float): float;
  /// get the value at a certain percentile
  native fn percentile(percentile: float): float?;
  /// split [0 - 100[ to N intervals and get the value related to each percentile in an table
  native fn percentiles(buckets: int): Table<any>;
  /// Get number of elements
  native fn size(): int;
  /// Get number of nulls
  native fn nbNull(): int;
  /// Get the min
  native fn min(): float?;
  /// Get the max
  native fn max(): float?;
  /// Get the avg
  native fn avg(): float?;
  /// Get the std
  native fn std(): float?;
  /// Get the sum
  native fn sum(): float?;
  /// Get the sum squared
  native fn sumsq(): float?;
  native fn toBoxPlot(): BoxPlotFloat?;
}

native type HistogramInt {
  static table_off_from : int = 0;
  static table_off_to : int = 1;
  static table_off_count : int = 2;
  static table_off_percentage : int = 3;
  native fn setBounds(min: int, max: int);
  native fn clear();
  /// add a value to the histogram with default count=1
  native fn add(value: int?);
  native fn addWithCount(value: int?, count: int);
  /// get the count of a specific value
  native fn getCount(value: int?): int;
  native fn all(): Table<any>;
  /// get the count of values in an interval [From;To[
  native fn interval(from: int, to: int): Table<any>;
  /// split [from - to[ to N intervals and get the count of each interval in an table
  native fn sample(from: int, to: int, buckets: int): Table<any>;
  /// get the percentage at a certain value
  native fn percentage(value: int): float;
  /// get the value at a certain percentile
  native fn percentile(percentile: float): int?;
  /// split [0 - 100] to N intervals and get the value related to each percentile in an table
  native fn percentiles(buckets: int): Table<any>;
  /// Get number of elements
  native fn size(): int;
  /// Get number of nulls
  native fn nbNull(): int;
  /// Get the min
  native fn min(): int?;
  /// Get the max
  native fn max(): int?;
  /// Get the avg
  native fn avg(): float?;
  /// Get the std
  native fn std(): float?;
  /// Get the sum
  native fn sum(): float?;
  /// Get the sum squared
  native fn sumsq(): float?;
  native fn toBoxPlot(): BoxPlotInt?;
}