HIBF 1.0.0-rc.1
Loading...
Searching...
No Matches
toolbox.hpp
1// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <cinttypes> // for uint64_t, int64_t
8#include <cstddef> // for size_t
9#include <functional> // for greater
10#include <queue> // for priority_queue
11#include <vector> // for vector
12
13#include <hibf/contrib/robin_hood.hpp> // for unordered_flat_map
14#include <hibf/sketch/hyperloglog.hpp> // for hyperloglog
15
16namespace seqan::hibf::sketch::toolbox
17{
18
23{
24 // children in the tree
25 size_t left;
26 size_t right;
27 // hll sketch of the union if the node is still a root
28 hyperloglog hll;
29};
30
35{
36 size_t id;
37 double dist;
38
39 bool operator>(neighbor const & other) const
40 {
41 return dist > other.dist;
42 }
43};
44
49
53struct entry
54{
55 size_t id;
56 prio_queue pq;
57};
58
63
68
80 std::vector<hyperloglog> const & sketches,
81 std::vector<size_t> const & counts,
82 std::vector<size_t> const & positions,
83 int64_t const j);
84
95 std::vector<hyperloglog> const & sketches,
96 std::vector<size_t> const & counts,
97 std::vector<size_t> const & positions);
98
99#if 0 // Currently unused
106uint64_t estimate_interval(std::vector<hyperloglog> const & sketches, std::vector<size_t> const & positions);
107#endif
108
118 std::vector<size_t> const & counts,
119 std::vector<size_t> & positions,
120 double const max_ratio,
121 size_t const num_threads);
122
134 std::vector<size_t> & positions,
135 std::vector<size_t> & permutation,
136 size_t const first,
137 size_t const last,
138 size_t const num_threads);
139
145void random_shuffle(distance_matrix & dist, robin_hood::unordered_flat_map<size_t, size_t> & remaining_ids);
146
152void prune(distance_matrix & dist, robin_hood::unordered_flat_map<size_t, size_t> & remaining_ids);
153
167 size_t const previous_rightmost,
168 size_t const first,
169 size_t const id);
170
182void trace(std::vector<clustering_node> const & clustering,
183 std::vector<size_t> & permutation,
184 size_t const previous_rightmost,
185 size_t const first,
186 size_t const id);
187
188} // namespace seqan::hibf::sketch::toolbox
HyperLogLog estimates.
Definition hyperloglog.hpp:36
void sort_by_cardinalities(std::vector< size_t > const &counts, std::vector< size_t > &positions)
Sorts filenames and cardinalities by looking only at the cardinalities.
bool rotate(std::vector< clustering_node > &clustering, size_t const previous_rightmost, size_t const first, size_t const id)
Rotate the previous rightmost bin to the left of the clustering tree.
void trace(std::vector< clustering_node > const &clustering, std::vector< size_t > &permutation, size_t const previous_rightmost, size_t const first, size_t const id)
Do a recursive traceback to find the order of leaves in the clustering tree.
void precompute_initial_union_estimates(std::vector< uint64_t > &estimates, std::vector< hyperloglog > const &sketches, std::vector< size_t > const &counts, std::vector< size_t > const &positions)
Estimate the cardinality of the union for each interval [0, j] for all user bins j.
void prune(distance_matrix &dist, robin_hood::unordered_flat_map< size_t, size_t > &remaining_ids)
Delete inactive entries out of dist and shrink to fit its size while keeping track of the changes of ...
void rearrange_bins(std::vector< hyperloglog > const &sketches, std::vector< size_t > const &counts, std::vector< size_t > &positions, double const max_ratio, size_t const num_threads)
Rearrange filenames, sketches and counts such that similar bins are close to each other.
void cluster_bins(std::vector< hyperloglog > const &sketches, std::vector< size_t > &positions, std::vector< size_t > &permutation, size_t const first, size_t const last, size_t const num_threads)
Perform an agglomerative clustering variant on the index range [first:last)
void precompute_union_estimates_for(std::vector< uint64_t > &estimates, std::vector< hyperloglog > const &sketches, std::vector< size_t > const &counts, std::vector< size_t > const &positions, int64_t const j)
Estimate the cardinality of the union for a single user bin j with all prior ones j' < j.
void random_shuffle(distance_matrix &dist, robin_hood::unordered_flat_map< size_t, size_t > &remaining_ids)
Randomly swap entries in dist while keeping track of the changes of indices.
Provides seqan::hibf::sketch::hyperloglog.
type for a node in the clustering tree when for the rearrangement
Definition toolbox.hpp:23
entry of the distance matrix that has the id of a cluster with its neighbors in a prio queue
Definition toolbox.hpp:54
element of the second priority queue layer of the distance matrix
Definition toolbox.hpp:35