Skip to content

dist #

vsl.dist

vsl.dist provides histogram binning and text rendering for numeric samples. Histogram stores bin boundaries and counts; boundaries should be supplied in ascending order.

API Purpose
Histogram.new(stations) Create a histogram from bin boundaries.
find_bin(x) Return the matching bin index or an error when outside the range.
count(values, clear) Count values, optionally resetting prior counts first.
gen_labels(format) Format the bins as display labels.
density_area(nsamples) Estimate the normalized area from accumulated counts.
text_hist(labels, counts, barlen) Render labeled counts as a text chart.
build_text_hist(...) Build a histogram and render it in one call.
import vsl.dist

mut histogram := dist.Histogram.new([0.0, 1.0, 2.0, 3.0])
histogram.count([0.2, 0.7, 1.4, 2.8], true)!
labels := histogram.gen_labels('%g')!
println(dist.text_hist(labels, histogram.counts, 0)!)

See the histogram example and hist.v for formatting and boundary behavior.

fn build_text_hist #

fn build_text_hist(xmin f64, xmax f64, nstations int, values []f64, numfmt string, barlen int) !string

build_text_hist builds a text histogram

fn text_hist #

fn text_hist(labels []string, counts []int, barlen int) !string

text_hist prints a text histogram

fn Histogram.new #

fn Histogram.new(stations []f64) &Histogram

Histogram.new returns an histogram struct from a given list of stations

struct Histogram #

struct Histogram {
pub mut:
	stations []f64 // stations
	counts   []int // counts
}

Histogram defines a public data structure for this module.

fn (Histogram) find_bin #

fn (o Histogram) find_bin(x f64) !int

find_bin finds where x falls in returns -1 if x is outside the range

fn (Histogram) count #

fn (mut o Histogram) count(vals []f64, clear bool) !

count counts how many items fall within each bin

fn (Histogram) gen_labels #

fn (o Histogram) gen_labels(numfmt string) ![]string

gen_labels generate nice labels identifying bins

fn (Histogram) density_area #

fn (o Histogram) density_area(nsamples int) !f64

density_area computes the area of the density diagram nsamples -- number of samples used when generating pseudo-random numbers