Expand description
Traits for implementing histograms for Wang Landau or entropic sampling. Contains histogram implementations for all primitive numbers
§Using Histograms
For the histograms of integers with bin width larger than 1: you should use the newly implemented GenericHist of BinningWithWidth. These will likely be much faster than HistogramInt, especially if you have a lot of bins. I did not remove the slower implementation, because then I’d have to change all of my other code in which I use them ^^“
Anyhow, here is an example for using a fast histogram with bin width 3
use sampling::histogram::*;
use rand_pcg::Pcg64;
use rand::prelude::*;
use rand::distr::*;
// now I use one of the type aliases to first create the binning and then the histogram:
let mut hist = BinningI32::new_inclusive(-20,132, 3)
.unwrap()
.to_generic_hist();
let uniform = Uniform::new_inclusive(-20, 132).unwrap();
let mut rng = Pcg64::seed_from_u64(3987612);
// create 10000 samples
let iter = uniform
.sample_iter(rng)
.take(10000);
for val in iter{
hist.count_val(val)
.unwrap(); // would panic if a value were to be outside the hist
// alternatively, if you don't want the panic:
// let _ = hist.count_val(val);
}
If you have a bin width of 1, then you can either use the newly implemented GenericHist of FastSingleIntBinning like in the example below, or you can keep using the old HistogramFast, as there seems to be no real difference in speed, at least on my machine they are within variance of one another.
Either way, there are type aliases for convenience, see below.
use sampling::histogram::*;
use rand_pcg::Pcg64;
use rand::prelude::*;
use rand::distr::*;
// now I use one of the type aliases to first create the binning and then the histogram:
let mut hist = FastBinningI32::new_inclusive(-20,130)
.to_generic_hist();
let uniform = Uniform::new_inclusive(-20, 130).unwrap();
let mut rng = Pcg64::seed_from_u64(3987612);
// create 10000 samples
let iter = uniform
.sample_iter(rng)
.take(10000);
for val in iter{
hist.count_val(val)
.unwrap(); // would panic if a value were to be outside the hist
// alternatively, if you don't want the panic:
// let _ = hist.count_val(val);
}
§Atomic Histograms
Sometimes you want to create a histograms in parallel, i.e., from multiple threads simultaneously. In this case you can use Atomic histograms,
use sampling::histogram::*;
use rand_pcg::Pcg64;
use rand::prelude::*;
use rand::distr::*;
use rayon::prelude::*;
// now I use one of the type aliases to first create the binning and then the histogram:
let mut atomic_hist = BinningI16::new_inclusive(-20,132, 3)
.unwrap()
.to_generic_atomic_hist();
let uniform = Uniform::new_inclusive(-20, 132)
.unwrap();
(0..4)
.into_par_iter()
.for_each(
|seed|
{
let mut rng = Pcg64::seed_from_u64(seed);
// create 10000 samples
let iter = uniform
.sample_iter(rng)
.take(10000);
for val in iter{
atomic_hist.count_val(val)
.unwrap(); // would panic if a value were to be outside the hist
// alternatively, if you don't want the panic:
// let _ = hist.count_val(val);
}
}
);
assert_eq!(
atomic_hist.total_hits(),
40000
);
// You can also convert the generic atomic histogram into a normal histogram.
let hist = atomic_hist.into_generic_hist();
// You can also convert it the other way round
let atomic_hist = hist.into_atomic_generic_hist();
Structs§
- Atomic
Generic Hist - Provides Histogram functionality
- Atomic
Histogram Float - Generic Histogram struct
- Binning
With Width - Generic binning meant for any integer type
- Fast
Single IntBinning - Generic binning meant for any integer type
- Generic
Hist - Provides Histogram functionality
- Histogram
Fast - Faster version of HistogramInt for Integers
- Histogram
Float - Generic Histogram struct
- Histogram
Int Deprecated - Generic Histogram for integer types
Enums§
- Bin
- Definition of a Bin
- Hist
Errors - Possible Errors of the traits
Histogram
andHistogramVal
- Outcome
- You have done something that can succeed or fail
Traits§
- Atomic
Histogram - Implements histogram
- Atomic
Histogram Val - trait used for mapping values of arbitrary type
T
to binsused to create a histogram - BinDisplay
- Trait used to display bins
- Binning
- Implements Binning
- HasUnsigned
Version - Helper trait for efficient calculations in other implementations
- Histogram
- Implements histogram
- Histogram
Combine - Used to get a histogram, which contains the smaller histograms
- Histogram
Interval Distance - Distance metric for how far a value is from a valid interval
- Histogram
Partition - Your Interval is to large to sample in a reasonable amount of time? No problem
- Histogram
Val - trait used for mapping values of arbitrary type
T
to binsused to create a histogram - Interval
Order - Trait for comparing two intervals
Functions§
- checked_
mul_ div_ i8 - Checked multiply divide
- checked_
mul_ div_ i16 - Checked multiply divide
- checked_
mul_ div_ i32 - Checked multiply divide
- checked_
mul_ div_ i64 - Checked multiply divide
- checked_
mul_ div_ i128 - Checked multiply divide
- checked_
mul_ div_ isize - Checked multiply divide
- checked_
mul_ div_ u8 - Checked multiply divide
- checked_
mul_ div_ u16 - Checked multiply divide
- checked_
mul_ div_ u32 - Checked multiply divide
- checked_
mul_ div_ u64 - Checked multiply divide
- checked_
mul_ div_ u128 - Checked multiply divide
- checked_
mul_ div_ usize - Checked multiply divide
Type Aliases§
- Atomic
Hist F32 - Histogram for binning
f32
- alias forHistogramFloat<f32>
- Atomic
Hist F64 - Histogram for binning
f64
- alias forHistogramFloat<f64>
- Binning
I8 - Efficient binning for
i8
with arbitrary width - Binning
I16 - Efficient binning for
i16
with arbitrary width - Binning
I32 - Efficient binning for
i32
with arbitrary width - Binning
I64 - Efficient binning for
i64
with arbitrary width - Binning
I128 - Efficient binning for
i128
with arbitrary width - BinningISIZE
- Efficient binning for
isize
with arbitrary width - Binning
U8 - Efficient binning for
u8
with arbitrary width - Binning
U16 - Efficient binning for
u16
with arbitrary width - Binning
U32 - Efficient binning for
u32
with arbitrary width - Binning
U64 - Efficient binning for
u64
with arbitrary width - Binning
U128 - Efficient binning for
u128
with arbitrary width - BinningUSIZE
- Efficient binning for
usize
with arbitrary width - Fast
Binning I8 - Efficient binning for
i8
with bins of width 1 - Fast
Binning I16 - Efficient binning for
i16
with bins of width 1 - Fast
Binning I32 - Efficient binning for
i32
with bins of width 1 - Fast
Binning I64 - Efficient binning for
i64
with bins of width 1 - Fast
Binning I128 - Efficient binning for
i128
with bins of width 1 - Fast
BinningISIZE - Efficient binning for
isize
with bins of width 1 - Fast
Binning U8 - Efficient binning for
u8
with bins of width 1 - Fast
Binning U16 - Efficient binning for
u16
with bins of width 1 - Fast
Binning U32 - Efficient binning for
u32
with bins of width 1 - Fast
Binning U64 - Efficient binning for
u64
with bins of width 1 - Fast
Binning U128 - Efficient binning for
u128
with bins of width 1 - Fast
BinningUSIZE - Efficient binning for
usize
with bins of width 1 - HistF32
- Histogram for binning
f32
- alias forHistogramFloat<f32>
- HistF64
- Histogram for binning
f64
- alias forHistogramFloat<f64>
- HistI8
Deprecated - Histogram for binning
i8
- alias forHistogramInt<i8>
- Hist
I8Fast - Histogram for binning
i8
- alias forHistogramFastiu8>
- HistI16
Deprecated - Histogram for binning
i16
- alias forHistogramInt<i16>
- HistI32
Deprecated - Histogram for binning
i32
- alias forHistogramInt<i32>
- HistI64
Deprecated - Histogram for binning
i64
- alias forHistogramInt<i64>
- Hist
I16Fast - Histogram for binning
i16
- alias forHistogramFast<i16>
- Hist
I32Fast - Histogram for binning
i32
- alias forHistogramFast<i32>
- Hist
I64Fast - Histogram for binning
i64
- alias forHistogramFast<i64>
- Hist
I128 Deprecated - Histogram for binning
i128
- alias forHistogramInt<i128>
- Hist
I128 Fast - Histogram for binning
i128
- alias forHistogramFast<i128>
- Hist
Isize Deprecated - Histogram for binning
isize
- alias forHistogramInt<isize>
- Hist
Isize Fast - Histogram for binning
isize
- alias forHistogramFast<isize>
- HistU8
Deprecated - Histogram for binning
u8
- alias forHistogramInt<u8>
- Hist
U8Fast - Histogram for binning
u8
- alias forHistogramFast<u8>
- HistU16
Deprecated - Histogram for binning
u16
- alias forHistogramInt<u16>
- HistU32
Deprecated - Histogram for binning
u32
- alias forHistogramInt<u32>
- HistU64
Deprecated - Histogram for binning
u64
- alias forHistogramInt<u64>
- Hist
U16Fast - Histogram for binning
u16
- alias forHistogramFast<u16>
- Hist
U32Fast - Histogram for binning
u32
- alias forHistogramFast<u32>
- Hist
U64Fast - Histogram for binning
u64
- alias forHistogramFast<u64>
- Hist
U128 Deprecated - Histogram for binning
u128
- alias forHistogramInt<u128>
- Hist
U128 Fast - Histogram for binning
u128
- alias forHistogramFast<u128>
- Hist
Usize Deprecated - Histogram for binning
usize
- alias forHistogramInt<usize>
- Hist
Usize Fast - Histogram for binning
usize
- alias forHistogramFast<usize>