Struct HeatmapUsize

Source
pub struct HeatmapUsize<HistWidth, HistHeight> { /* private fields */ }
Expand description

§Heatmap

  • stores heatmap in row-major order: the rows of the heatmap are contiguous, and the columns are strided
  • enables you to quickly create a heatmap
  • you can create gnuplot scripts to plot the heatmap
  • you can transpose the heatmap

Implementations§

Source§

impl<HistWidth, HistHeight> HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Clone, HistHeight: Clone,

Source

pub fn transpose(&self) -> HeatmapUsize<HistHeight, HistWidth>

§Use this to get a “flipped” heatmap
Source§

impl<HistWidth, HistHeight> HeatmapUsize<HistWidth, HistHeight>

Source

pub fn transpose_inplace(self) -> HeatmapUsize<HistHeight, HistWidth>

§Use this to get a “flipped” heatmap
  • transposes the heatmap inplace
Source

pub fn get(&self, x: usize, y: usize) -> Option<usize>

Returns value stored in the heatmap at specified coordinates, or None, if out of Bounds

Source

pub fn get_row(&self, y: usize) -> Option<&[usize]>

§row of the heatmap
  • None if out of bounds
  • otherwise it is a slice of the row at height y
§Note
  • there is no get_column method, because, due to implementation details, it is way less efficient, and could not be returned as slice
Source

pub unsafe fn get_unchecked(&self, x: usize, y: usize) -> usize

Returns value stored in the heatmap at specified coordinates without performing bound checks.

§Safety

undefined behavior if coordinates are out of bounds

Source

pub fn width(&self) -> usize

§returns width of the heatmap
  • the width is the same size, as the self.width_projection().bin_count()
Source

pub fn height(&self) -> usize

§returns height of the heatmap
  • the height is the same size, as the self.height_projection().bin_count()
Source

pub fn width_hist(&self) -> &HistWidth

§Returns reference to current width Histogram
  • histogram used to bin in the “width” direction
  • all counts are counted here -> this is a projection of the heatmap
Source

pub fn height_hist(&self) -> &HistHeight

§Returns reference to current height Histogram
  • histogram used to bin in the “height” direction
  • all counts are counted here -> this is a projection of the heatmap
Source§

impl<HistWidth, HistHeight> HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Histogram, HistHeight: Histogram,

Source

pub fn new(width_hist: HistWidth, height_hist: HistHeight) -> Self

§Create a new Heatmap
  • heatmap will have width width_hist.bin_count() and height height_hist.bin_count()
  • histograms will be reset (zeroed) here, so it does not matter, if they were used before and contain Data
Source

pub fn reset(&mut self)

§Reset
  • resets histograms
  • heatmap is reset to contain only 0’s
  • miss_count is reset to 0
Source

pub fn combine<OtherHW, OtherHH>( &mut self, other: &HeatmapUsize<OtherHW, OtherHH>, ) -> Result<(), HeatmapError>
where OtherHW: Histogram, OtherHH: Histogram,

§“combine” heatmaps
  • heatmaps will be combined by adding all entries of other to self
  • heatmaps have to have the same dimensions
Source

pub fn total(&self) -> usize

§counts how often the heatmap was hit
  • should be equal to self.heatmap.iter().sum::<usize>() but more efficient
  • Note: it calculates this in O(min(self.width, self.height))
Source

pub fn total_misses(&self) -> usize

§Counts how often the Heatmap was missed, i.e., you tried to count a value (x,y), which was outside the Heatmap
Source

pub fn bins_hit(&self) -> usize

§counts how many bins of the heatmap where hit at least once
Source

pub fn bins_not_hit(&self) -> usize

§counts how many bins of the heatmap where never hit
Source

pub fn heatmap(&self) -> &Vec<usize>

§returns heatmap
  • each vector entry will contain the number of times, the corresponding bin was hit
  • an entry is 0 if it was never hit
§Access indices; understanding how the data is mapped
  • A specific heatmap location (x,y) corresponds to the index y * self.width() + x
  • you can use the heatmap_index function to calculate the index
Source

pub fn vec_normalized(&self) -> Vec<f64>

§returns Vector representing normalized heatmap
  • Vector contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of this Vector is 1.0 (or at least very close to 1.0)
§Access indices; understanding how the data is mapped
  • A specific heatmap location (x,y) corresponds to the index y * self.width() + x
  • you can use the function heatmap_index(width, x, y) for calculating the index
Source

pub fn heatmap_normalized(&self) -> HeatmapF64<HistWidth, HistHeight>
where HistHeight: Clone, HistWidth: Clone,

§returns normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of this Vector is 1.0 (within numerical errors)
Source

pub fn into_heatmap_normalized(self) -> HeatmapF64<HistWidth, HistHeight>

§returns normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of this Vector is 1.0 (within numerical errors)
Source

pub fn vec_normalized_columns(&self) -> Vec<f64>

§returns vector representing heatmap, normalized column wise
  • Vector contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each column (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the column will only consist of 0.0
§Access indices; understanding how the data is mapped

A specific heatmap location (x,y) corresponds to the index y * self.width() + x

  • you can use the function heatmap_index(width, x, y) for calculating the index
Source

pub fn heatmap_normalized_columns(&self) -> HeatmapF64<HistWidth, HistHeight>
where HistHeight: Clone, HistWidth: Clone,

§returns (column wise) normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each column (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the column will only consist of 0.0
  • otherwise the sum of this Vector is 1.0
Source

pub fn into_heatmap_normalized_columns( self, ) -> HeatmapF64<HistWidth, HistHeight>

§returns (column wise) normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each column (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the column will only consist of 0.0
  • otherwise the sum of this Vector is 1.0
Source

pub fn vec_normalized_rows(&self) -> Vec<f64>

§returns vector representing heatmap, normalized row wise
  • Vector contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each row (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the row will only consist of 0.0
§Access indices; understanding how the data is mapped

A specific heatmap location (x,y) corresponds to the index y * self.width() + x

  • you can use the function heatmap_index(width, x, y) for calculating the index
Source

pub fn heatmap_normalized_rows(&self) -> HeatmapF64<HistWidth, HistHeight>
where HistHeight: Clone, HistWidth: Clone,

§returns (row wise) normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each row (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the row will only consist of 0.0
  • otherwise the sum of this Vector is 1.0
Source

pub fn into_heatmap_normalized_rows(self) -> HeatmapF64<HistWidth, HistHeight>

§returns (row wise) normalized heatmap
  • returns normalized heatmap as HeatmapF64
  • Heatmap vector self.heatmap_normalized().heatmap() contains only 0.0, if nothing was in the heatmap
  • otherwise the sum of each row (fixed x) will be 1.0 (within numerical errors), if it contained at least one hit. If it did not, the row will only consist of 0.0
  • otherwise the sum of this Vector is 1.0
Source

pub fn count_multiple<A, B, X, Y, I>( &mut self, width_val_iter: I, height_val: B, ) -> Result<usize, HeatmapError>
where HistWidth: HistogramVal<X>, HistHeight: HistogramVal<Y>, A: Borrow<X>, B: Borrow<Y>, I: Iterator<Item = A>,

§update the heatmap
  • calculates the coordinates (x, y) of the bin corresponding to the given values pair (width_iter_entry, height_val)
  • as soon as a coordinate is encountered that is out of bounds, it counts a “miss” and returns the HeatmapError, aborting further execution
  • otherwise it counts the “hits” and returns the total number of hits added usize
Source

pub fn count<A, B, X, Y>( &mut self, width_val: A, height_val: B, ) -> Result<(usize, usize), HeatmapError>
where HistWidth: HistogramVal<X>, HistHeight: HistogramVal<Y>, A: Borrow<X>, B: Borrow<Y>,

§update the heatmap
  • calculates the coordinate (x, y) of the bin corresponding to the given value pair (width_val, height_val)
  • if coordinate is out of bounds, it counts a “miss” and returns the HeatmapError
  • otherwise it counts the “hit” and returns the coordinate (x, y)
Source

pub fn write_to<W>(&self, data_file: W) -> Result<()>
where W: Write,

§Write heatmap to file
  • writes data of heatmap to file.
§file
  • lets assume self.width()is 4 and self.height() is 3
  • the resulting file could look like
0 1 0 10
100 0 0 1
2 9 1 0
Source

pub fn gnuplot_quick<W>(&self, writer: W) -> Result<()>
where W: Write,

§Create a gnuplot script to plot your heatmap
  • writer: The gnuplot script will be written to this
  • gnuplot_output_name: how shall the file, created by executing gnuplot, be called? Ending of file will be set automatically
§Note
  • This is the same as calling gnuplot with default GnuplotSettings
  • The default axis are the bin indices, which, e.g, means they always begin at 0. You have to set the axis via the GnuplotSettings
Source

pub fn gnuplot<W, GS>(&self, gnuplot_writer: W, settings: GS) -> Result<()>
where W: Write, GS: Borrow<GnuplotSettings>,

§Create a gnuplot script to plot your heatmap

This function writes a file, that can be plotted via the terminal via gnuplot

gnuplot gnuplot_file
§Parameter:
  • gnuplot_writer: writer gnuplot script will be written to
  • gnuplot_output_name: how shall the file, created by executing gnuplot, be called? Ending of file will be set automatically
  • settings: Here you can set the axis, choose between terminals and more. I recommend that you take a look at GnuplotSettings
§Note

The default axis are the bin indices, which, e.g, means they always begin at 0. You have to set the axis via the GnuplotSettings

§Example
use rand_pcg::Pcg64;
use rand::{SeedableRng, distr::*};
use sampling::*;
use std::fs::File;
use std::io::BufWriter;
 
// first randomly create a heatmap
let h_x = HistUsizeFast::new_inclusive(0, 10).unwrap();
let h_y = HistU8Fast::new_inclusive(0, 10).unwrap();

let mut heatmap = HeatmapU::new(h_x, h_y);
heatmap.count(0, 0).unwrap();
heatmap.count(10, 0).unwrap();

let mut rng = Pcg64::seed_from_u64(27456487);
let x_distr = Uniform::new_inclusive(0, 10_usize)
    .unwrap();
let y_distr = Uniform::new_inclusive(0, 10_u8)
    .unwrap();

for _ in 0..100000 {
    let x = x_distr.sample(&mut rng);
    let y = y_distr.sample(&mut rng);
    heatmap.count(x, y).unwrap();
}
 
// create File for gnuplot script
let file = File::create("heatmap.gp").unwrap();
let buf = BufWriter::new(file);

// Choose settings for gnuplot
let mut settings = GnuplotSettings::new();
settings.x_axis(GnuplotAxis::new(-5.0, 5.0, 6))
    .y_axis(GnuplotAxis::from_slice(&["a", "b", "c", "d"]))
    .y_label("letter")
    .x_label("number")
    .title("Example")
    .terminal(GnuplotTerminal::PDF("heatmap".to_owned()));

// create gnuplot script
heatmap.gnuplot(
    buf,
    settings
).unwrap();

gnuplot script can now be plotted with

gnuplot heatmap.gp

Trait Implementations§

Source§

impl<HistWidth: Clone, HistHeight: Clone> Clone for HeatmapUsize<HistWidth, HistHeight>

Source§

fn clone(&self) -> HeatmapUsize<HistWidth, HistHeight>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<HistWidth: Debug, HistHeight: Debug> Debug for HeatmapUsize<HistWidth, HistHeight>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, HistWidth, HistHeight> Deserialize<'de> for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Deserialize<'de>, HistHeight: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<HistWidth, HistHeight> From<HeatmapUsize<HistWidth, HistHeight>> for HeatmapF64<HistWidth, HistHeight>
where HistWidth: Histogram, HistHeight: Histogram,

Source§

fn from(other: HeatmapU<HistWidth, HistHeight>) -> Self

Converts to this type from the input type.
Source§

impl<HistWidth, HistHeight> Serialize for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Serialize, HistHeight: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<HistWidth, HistHeight> Freeze for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Freeze, HistHeight: Freeze,

§

impl<HistWidth, HistHeight> RefUnwindSafe for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: RefUnwindSafe, HistHeight: RefUnwindSafe,

§

impl<HistWidth, HistHeight> Send for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Send, HistHeight: Send,

§

impl<HistWidth, HistHeight> Sync for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Sync, HistHeight: Sync,

§

impl<HistWidth, HistHeight> Unpin for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: Unpin, HistHeight: Unpin,

§

impl<HistWidth, HistHeight> UnwindSafe for HeatmapUsize<HistWidth, HistHeight>
where HistWidth: UnwindSafe, HistHeight: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,