Back to Influxdb

experimental.histogram() function

content/flux/v0/stdlib/experimental/histogram.md

latest3.6 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/experimental/experimental.flux#L1276-L1280 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

experimental.histogram() approximates the cumulative distribution of a dataset by counting data frequencies for a list of bins.

A bin is defined by an upper bound where all data points that are less than or equal to the bound are counted in the bin. Bin counts are cumulative.

Function behavior

  • Outputs a single table for each input table.
  • Each output table represents a unique histogram.
  • Output tables have the same group key as the corresponding input table.
  • Drops columns that are not part of the group key.
  • Adds an le column to store upper bound values.
  • Stores bin counts in the _value column.
Function type signature
js
(<-tables: stream[{A with _value: float}], bins: [float], ?normalize: bool) => stream[{A with le: float, _value: float}]

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

bins

({{< req >}}) List of upper bounds to use when computing histogram frequencies, including the maximum value of the data set.

This value can be set to positive infinity (float(v: "+Inf")) if no maximum is known.

Bin helper functions

The following helper functions can be used to generated bins.

  • linearBins()
  • logarithmicBins()

normalize

Convert count values into frequency values between 0 and 1. Default is false.

Note: Normalized histograms cannot be aggregated by summing their counts.

tables

Input data. Default is piped-forward data (<-).

Examples

Create a histogram from input data

js
import "experimental"
import "sampledata"

sampledata.float()
    |> experimental.histogram(
        bins: [
            0.0,
            5.0,
            10.0,
            15.0,
            20.0,
        ],
    )

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time*tag_value
2021-01-01T00:00:00Zt1-2.18
2021-01-01T00:00:10Zt110.92
2021-01-01T00:00:20Zt17.35
2021-01-01T00:00:30Zt117.53
2021-01-01T00:00:40Zt115.23
2021-01-01T00:00:50Zt14.43
_time*tag_value
2021-01-01T00:00:00Zt219.85
2021-01-01T00:00:10Zt24.97
2021-01-01T00:00:20Zt2-3.75
2021-01-01T00:00:30Zt219.77
2021-01-01T00:00:40Zt213.86
2021-01-01T00:00:50Zt21.86

Output data

*tagle_value
t101
t152
t1103
t1154
t1206
*tagle_value
t201
t253
t2103
t2154
t2206

{{% /expand %}} {{< /expand-wrapper >}}