xsample09.cpp File Reference

Example: Use succinct vectors for histogram construction. More...

`#include <iostream>`
`#include <memory>`
`#include <vector>`
`#include <random>`
`#include <algorithm>`
`#include <stdexcept>`
`#include "bm.h"`
`#include "bmtimer.h"`
`#include "bmsparsevec.h"`
`#include "bmsparsevec_compr.h"`
`#include "bmdbg.h"`
`#include "bmundef.h"`
Include dependency graph for xsample09.cpp:

Go to the source code of this file.

## Typedefs

typedef bm::sparse_vector< unsigned, bvector_type > | sparse_vector_u32
typedef bm::rsc_sparse_vector< unsigned, sparse_vector_u32 > | rsc_sparse_vector_u32
typedef std::vector< std::pair< bv_size_type, bv_size_type > > | bv_ranges_vector

## Functions

static void | generate_test_data (rsc_sparse_vector_u32 &csv, unsigned size)
| Generate a test RSC vector with a randomly distributed values imitating distribution density of genome variations it adds a huge area of empty in the middle to simulate chr centromere.
static void | generate_access_samples (std::vector< bvector_type::size_type > &sample_vec, unsigned size)
| generate list of random indexes (locations) to read histogram values
static void | compute_historgam (sparse_vector_u32 &hist_sv, const rsc_sparse_vector_u32 &csv, sparse_vector_u32::size_type sampling_size)
| Compute histogram as a SV vector using fixed sampling interval.
static void | compute_rsc_historgam (rsc_sparse_vector_u32 &hist_rsc, const rsc_sparse_vector_u32 &csv, sparse_vector_u32::size_type sampling_size)
| Compute histogram as a RSC vector using fixed sampling interval.
static void | compute_adaptive_rsc_histogram (rsc_sparse_vector_u32 &hist_rsc, const rsc_sparse_vector_u32 &csv, sparse_vector_u32::size_type sampling_size)
| Adaptive histogram identifies number of not NULL elements (events) and varies the size of the histogram bin trying to make sure all bins (but last) are the same weight.
static void | verify_histograms (const rsc_sparse_vector_u32 &hist_rsc, const sparse_vector_u32 &hist_sv, sparse_vector_u32::size_type sampling_size)
| Some test to confirm correctness.
static unsigned long long | access_bench1 (const sparse_vector_u32 &hist_sv, const std::vector< bvector_type::size_type > &sample_vec, unsigned sampling_size)
| Access benchmark 1.
static unsigned long long | access_bench2 (const rsc_sparse_vector_u32 &hist_rsc, const std::vector< bvector_type::size_type > &sample_vec)
| Access benchmark 2.
static void | access_bench3 (const rsc_sparse_vector_u32 &hist_rsc, const std::vector< bvector_type::size_type > &sample_vec, const rsc_sparse_vector_u32 &rsc_data)
int | main (void)

## Variables

const unsigned | test_size = 250000000
const unsigned | sampling_interval = 2500
bm::chrono_taker ::duration_map_type | timing_map

## Detailed Description

Example: Use succinct vectors for histogram construction.

Definition in file xsample09.cpp.

## Typedef Documentation

## bv_ranges_vector

typedef std::vector<std::pair<bv_size_type, bv_size_type> > bv_ranges_vector

Definition at line 71 of file xsample09.cpp.

## rsc_sparse_vector_u32

typedef bm::rsc_sparse_vector<unsigned, sparse_vector_u32> rsc_sparse_vector_u32

Definition at line 69 of file xsample09.cpp.

## sparse_vector_u32

typedef bm::sparse_vector<unsigned, bvector_type> sparse_vector_u32

Definition at line 68 of file xsample09.cpp.

## Function Documentation

## access_bench1()

unsigned long long access_bench1 | ( | const sparse_vector_u32 & | hist_sv,
|  | const std::vector< bvector_type::size_type > & | sample_vec,
|  | unsigned | sampling_size )

static

Access benchmark 1.

uses regular bit-transposed sparse vector to read histogram values in random order. It relies on fixed inetrval sampling.

Examples
  xsample09.cpp.

Definition at line 273 of file xsample09.cpp.

Referenced by main().

## access_bench2()

unsigned long long access_bench2 | ( | const rsc_sparse_vector_u32 & | hist_rsc,
|  | const std::vector< bvector_type::size_type > & | sample_vec )

static

Access benchmark 2.

Uses Rank-Select bit-transposed vector to read histogram values Sampling interval can be non-fixed (variadic, adaptive sampling). Method finds the interval start and value using RSC container not NULL vector

Examples
  xsample09.cpp.

Definition at line 294 of file xsample09.cpp.

References bm::bvector< Alloc >::find_reverse(), and bm::rsc_sparse_vector< Val, SV >::get_null_bvector().

Referenced by main().

## access_bench3()

void access_bench3 | ( | const rsc_sparse_vector_u32 & | hist_rsc,
|  | const std::vector< bvector_type::size_type > & | sample_vec,
|  | const rsc_sparse_vector_u32 & | rsc_data )

static

Examples
  xsample09.cpp.

Definition at line 319 of file xsample09.cpp.

References bm::bvector< Alloc >::find(), bm::bvector< Alloc >::find_reverse(), and bm::rsc_sparse_vector< Val, SV >::get_null_bvector().

Referenced by main().

## compute_adaptive_rsc_histogram()

void compute_adaptive_rsc_histogram | ( | rsc_sparse_vector_u32 & | hist_rsc,
|  | const rsc_sparse_vector_u32 & | csv,
|  | sparse_vector_u32::size_type | sampling_size )

static

Adaptive histogram identifies number of not NULL elements (events) and varies the size of the histogram bin trying to make sure all bins (but last) are the same weight.

Examples
  xsample09.cpp.

Definition at line 220 of file xsample09.cpp.

References BM_DECLARE_TEMP_BLOCK, bm::rsc_sparse_vector< Val, SV >::get_null_bvector(), bm::rsc_sparse_vector< Val, SV >::optimize(), bm::rsc_sparse_vector< Val, SV >::push_back(), bm::rank_range_split(), and bm::rsc_sparse_vector< Val, SV >::sync().

Referenced by main().

## compute_historgam()

void compute_historgam | ( | sparse_vector_u32 & | hist_sv,
|  | const rsc_sparse_vector_u32 & | csv,
|  | sparse_vector_u32::size_type | sampling_size )

static

Compute histogram as a SV vector using fixed sampling interval.

Examples
  xsample09.cpp.

Definition at line 143 of file xsample09.cpp.

References BM_DECLARE_TEMP_BLOCK, bm::bvector< Alloc >::count_range(), bm::sparse_vector< Val, BV >::get_back_inserter(), bm::rsc_sparse_vector< Val, SV >::get_null_bvector(), bm::sparse_vector< Val, BV >::optimize(), and bm::rsc_sparse_vector< Val, SV >::size().

Referenced by main().

## compute_rsc_historgam()

void compute_rsc_historgam | ( | rsc_sparse_vector_u32 & | hist_rsc,
|  | const rsc_sparse_vector_u32 & | csv,
|  | sparse_vector_u32::size_type | sampling_size )

static

Compute histogram as a RSC vector using fixed sampling interval.

Histogram values are stored as "true" interval start coordinates and it is a more flexible scheme if we eventually decide to use adaptive sampling (variable step).

Examples
  xsample09.cpp.

Definition at line 180 of file xsample09.cpp.

References BM_DECLARE_TEMP_BLOCK, bm::bvector< Alloc >::count_range(), bm::rsc_sparse_vector< Val, SV >::get_null_bvector(), bm::rsc_sparse_vector< Val, SV >::load_from(), bm::rsc_sparse_vector< Val, SV >::optimize(), bm::sparse_vector< Val, BV >::set(), bm::rsc_sparse_vector< Val, SV >::size(), bm::rsc_sparse_vector< Val, SV >::sync(), and bm::use_null.

Referenced by main().

## generate_access_samples()

void generate_access_samples | ( | std::vector< bvector_type::size_type > & | sample_vec,
|  | unsigned | size )

static

generate list of random indexes (locations) to read histogram values

Examples
  xsample09.cpp.

Definition at line 124 of file xsample09.cpp.

Referenced by main().

## generate_test_data()

void generate_test_data | ( | rsc_sparse_vector_u32 & | csv,
|  | unsigned | size )

static

Generate a test RSC vector with a randomly distributed values imitating distribution density of genome variations it adds a huge area of empty in the middle to simulate chr centromere.

Examples
  xsample09.cpp.

Definition at line 83 of file xsample09.cpp.

References BM_DECLARE_TEMP_BLOCK, bm::rsc_sparse_vector< Val, SV >::get_back_inserter(), bm::rsc_sparse_vector< Val, SV >::optimize(), and bm::rsc_sparse_vector< Val, SV >::sync().

Referenced by main().

## main()

int main | ( | void |  | ) |

Definition at line 357 of file xsample09.cpp.

References access_bench1(), access_bench2(), access_bench3(), bm::sparse_vector< Val, BV >::begin(), bm::rsc_sparse_vector< Val, SV >::calc_stat(), bm::sparse_vector< Val, BV >::calc_stat(), compute_adaptive_rsc_histogram(), compute_historgam(), compute_rsc_historgam(), bm::bvector< Alloc >::count(), bm::chrono_taker< TOut >::ct_ops_per_sec, bm::sparse_vector< Val, BV >::end(), generate_access_samples(), generate_test_data(), bm::rsc_sparse_vector< Val, SV >::get_null_bvector(), bm::chrono_taker< TOut >::print_duration_map(), sampling_interval, bm::rsc_sparse_vector< Val, SV >::size(), bm::sparse_vector< Val, BV >::size(), test_size, timing_map, and verify_histograms().

## verify_histograms()

void verify_histograms | ( | const rsc_sparse_vector_u32 & | hist_rsc,
|  | const sparse_vector_u32 & | hist_sv,
|  | sparse_vector_u32::size_type | sampling_size )

static

Some test to confirm correctness.

Examples
  xsample09.cpp.

Definition at line 246 of file xsample09.cpp.

References bm::bvector< Alloc >::get_enumerator(), and bm::rsc_sparse_vector< Val, SV >::get_null_bvector().

Referenced by main().

## Variable Documentation

## sampling_interval

const unsigned sampling_interval = 2500

Examples
  xsample09.cpp.

Definition at line 64 of file xsample09.cpp.

Referenced by main().

## test_size

const unsigned test_size = 250000000

Definition at line 63 of file xsample09.cpp.

## timing_map

bm::chrono_taker ::duration_map_type timing_map

Definition at line 76 of file xsample09.cpp.