# Algorithms

This page documents library components that are all basically just implementations of mathematical functions or algorithms that don't fit in any of the other pages of the dlib documentation. So this includes things like checksums, cryptographic hashes, sorting, etc.

Tools
bigint
disjoint_subsets
Quantum Computing
quantum_register gate
Geometry
border_enumerator rectangle vector point rotate_point point_rotator point_transform point_transform_affine rotation_matrix get_rect centered_rect center dcenter shrink_rect grow_rect translate_rect resize_rect resize_rect_width resize_rect_height move_rect nearest_point distance_to_rect_edge
Graph Utilities
graph_contains_directed_cycle graph_contains_undirected_cycle create_moral_graph triangulate_graph_and_find_cliques graph_contains_length_one_cycle find_connected_nodes graph_is_connected is_clique is_maximal_clique copy_graph_structure edge is_join_tree create_join_tree
hsort_array
isort_array
put_in_range
qsort_array
square_root
Set Utilities
set_intersection_size set_intersection set_union set_difference
Statistics
rand
median
running_stats
running_scalar_covariance
mean_sign_agreement
correlation
covariance
r_squared
mean_squared_error
running_covariance
random_subset_selector
randomly_subsample
randomly_sample_image_features
Hashing
md5
crc32
hash
murmur_hash3
murmur_hash3_128bit
projection_hash
create_random_projection_hash
Filtering
kalman_filter
rls_filter
bigint
dlib/bigint.h
dlib/bigint/bigint_kernel_abstract.h
This object represents an arbitrary precision unsigned integer. It's pretty simple. It's interface is just like a normal int, you don't have to tell it how much memory to use or anything unusual. It just goes :)
bigint_kernel_1
dlib/bigint/bigint_kernel_1.h
This implementation is done using an array of unsigned shorts. It is also reference counted. For further details see the above link. Also note that kernel_2 should be faster in almost every case so you should really just use that version of the bigint object.
kernel_1a
is a typedef for bigint_kernel_1
bigint_kernel_2
dlib/bigint/bigint_kernel_2.h
This implementation is basically the same as kernel_1 except it uses the Fast Fourier Transform to perform multiplications much faster.
kernel_2a
is a typedef for bigint_kernel_2
crc32
dlib/crc32.h
dlib/crc32/crc32_kernel_abstract.h
This object represents the CRC-32 algorithm for calculating checksums.
murmur_hash3
dlib/hash.h
dlib/general_hash/murmur_hash3_abstract.h
This function takes a block of memory and returns a 32bit hash. The hashing algorithm used is Austin Appleby's excellent MurmurHash3.
murmur_hash3_128bit
dlib/hash.h
dlib/general_hash/murmur_hash3_abstract.h
This function takes a block of memory and returns a 128bit hash. The hashing algorithm used is Austin Appleby's excellent MurmurHash3.
kalman_filter
dlib/filtering.h
dlib/filtering/kalman_filter_abstract.h
This object implements the Kalman filter, which is a tool for recursively estimating the state of a process given measurements related to that process. To use this tool you will have to be familiar with the workings of the Kalman filter. An excellent introduction can be found in the paper:

> An Introduction to the Kalman Filter by Greg Welch and Gary Bishop

rls_filter
dlib/filtering.h
dlib/filtering/rls_filter_abstract.h
This object is a tool for doing time series prediction using linear recursive least squares. In particular, this object takes a sequence of points from the user and, at each step, attempts to predict the value of the next point.
projection_hash
dlib/lsh.h
dlib/lsh/projection_hash_abstract.h
This is a tool for hashing elements of a vector space into the integers. It is intended to represent locality sensitive hashing functions such as the popular random projection hashing method.
create_random_projection_hash
dlib/lsh.h
dlib/lsh/create_random_projection_hash_abstract.h
Creates a random projection based locality sensitive hashing function.
hash
dlib/hash.h
dlib/general_hash/hash_abstract.h
This is a set of convenience functions for invoking murmur_hash3 on std::strings, std::vectors, std::maps, or dlib::matrix objects.

As an aside, the hash() for matrix objects is defined here. It has the same interface as all the others.

rand
dlib/rand.h
dlib/rand/rand_kernel_abstract.h
This object represents a pseudorandom number generator.
rectangle
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This object represents a rectangular region inside a Cartesian coordinate system. It allows you to easily represent and manipulate rectangles.
border_enumerator
dlib/geometry.h
dlib/geometry/border_enumerator_abstract.h
This object is an enumerator over the border points of a rectangle.
vector
dlib/geometry.h
dlib/geometry/vector_abstract.h
This object represents a two or three dimensional vector.
point
dlib/geometry.h
dlib/geometry/vector_abstract.h
This object represents a point inside a Cartesian coordinate system.
disjoint_subsets
dlib/disjoint_subsets.h
dlib/disjoint_subsets/disjoint_subsets_abstract.h
This object represents a set of integers which is partitioned into a number of disjoint subsets. It supports the two fundamental operations of finding which subset a particular integer belongs to as well as merging subsets.
running_stats
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This object represents something that can compute the running mean and variance of a stream of real numbers.
kcentroid_ex.cpp.html
running_covariance
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This object is a simple tool for computing the mean and covariance of a sequence of vectors.
running_scalar_covariance
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This object is a simple tool for computing the covariance of a sequence of scalar values.
mean_sign_agreement
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This is a function for computing the probability that matching elements of two std::vectors have the same sign.
correlation
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This is a function for computing the correlation between matching elements of two std::vectors.
covariance
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This is a function for computing the covariance between matching elements of two std::vectors.
r_squared
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This is a function for computing the R squared coefficient between matching elements of two std::vectors.
mean_squared_error
dlib/statistics.h
dlib/statistics/statistics_abstract.h
This is a function for computing the mean squared error between matching elements of two std::vectors.
random_subset_selector
dlib/statistics.h
dlib/statistics/random_subset_selector_abstract.h
This object is a tool to help you select a random subset of a large body of data. In particular, it is useful when the body of data is too large to fit into memory.
randomly_subsample
dlib/statistics.h
dlib/statistics/random_subset_selector_abstract.h
This is a set of convenience functions for creating random subsets of data.
randomly_sample_image_features
dlib/statistics.h
dlib/statistics/image_feature_sampling_abstract.h
Given a feature extractor such as the hog_image, this routine selects a random subsample of local image feature vectors from a set of images.
hsort_array
dlib/sort.h
dlib/sort.h
hsort_array is an implementation of the heapsort algorithm. It will sort anything that has an array like operator[] interface.
put_in_range
dlib/algs.h
dlib/algs.h
This is a simple function that takes a range and a value and returns the given value if it is within the range. If it isn't in the range then it returns the end of range value that is closest.
isort_array
dlib/sort.h
dlib/sort.h
isort_array is an implementation of the insertion sort algorithm. It will sort anything that has an array like operator[] interface.
qsort_array
dlib/sort.h
dlib/sort.h
qsort_array is an implementation of the QuickSort algorithm. It will sort anything that has an array like operator[] interface. If the quick sort becomes unstable then it switches to a heap sort. This way sorting is guaranteed to take at most N*log(N) time.
md5
dlib/md5.h
dlib/md5/md5_kernel_abstract.h
This is an implementation of The MD5 Message-Digest Algorithm as described in rfc1321.
median
dlib/algs.h
dlib/algs.h
This function takes three parameters and finds the median of the three. The median is swapped into the first parameter and the first parameter ends up in one of the other two, unless the first parameter was the median to begin with of course.
square_root
dlib/algs.h
dlib/algs.h
square_root is a function which takes an unsigned long and returns the square root of it or if the root is not an integer then it is rounded up to the next integer.
edge
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph object and a pair of indices. It returns a reference to the edge object between the two nodes with the given indices.
is_join_tree
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes two graph objects and checks if the second of the two graphs is a valid join tree (aka tree decomposition) of the first graph.
create_join_tree
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph object and creates a join tree for that graph. Or in other words, this function finds a tree decomposition of the given graph.
graph_contains_directed_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks a directed_graph for directed cycles.
set_intersection
dlib/set_utils.h
dlib/set_utils/set_utils_abstract.h
This function takes two set objects and gives you their intersection.
set_union
dlib/set_utils.h
dlib/set_utils/set_utils_abstract.h
This function takes two set objects and gives you their union.
set_difference
dlib/set_utils.h
dlib/set_utils/set_utils_abstract.h
This function takes two set objects and gives you their difference.
set_intersection_size
dlib/set_utils.h
dlib/set_utils/set_utils_abstract.h
This function takes two set objects and tells you how many items they have in common.
triangulate_graph_and_find_cliques
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and turns it into a chordal graph. It also returns a set that contains all the cliques present in the chordal graph.
create_moral_graph
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a directed_graph and returns the moralized version of the graph in the form of a graph object.
graph_contains_length_one_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph object and returns true if and only if the graph contains a node that has an edge that links back to itself.
find_connected_nodes
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a node from a graph or directed_graph object and a set of unsigned longs. It finds all the nodes in the given graph that are connected to the given node by an undirected path and returns them in the set (also note that the original query node is also returned in this set).
graph_is_connected
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph object and determines if the graph is connected. That is, it returns true if and only if there is an undirected path between any two nodes in the given graph.
is_clique
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and a set of node index values and checks if the specified set of nodes is a clique in the graph.
copy_graph_structure
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph and copies its structure to another graph or directed_graph object. The only restriction is that you can't copy the structure of a graph into a directed_graph. The three other possible combinations are allowed however.
is_maximal_clique
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and a set of node index values and checks if the specified set of nodes is a maximal clique in the graph.
nearest_point
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and a point and returns the point in the given rectangle that is nearest to the given point.
distance_to_rect_edge
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and a point and returns the Manhattan distance between the rectangle's edge and the point.
move_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and moves it so that it's upper left corner occupies the given location.
resize_rect_height
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and returns a new rectangle with the given height but otherwise with the same edge points as the original rectangle.
resize_rect_width
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and returns a new rectangle with the given width but otherwise with the same edge points as the original rectangle.
resize_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and returns a new rectangle with the given size but with the same upper left corner as the original rectangle.
translate_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle and moves it by a given number of units along the x and y axis relative to where it was before the move.
quantum_register
dlib/quantum_computing.h
dlib/quantum_computing/quantum_computing_abstract.h
This object represents a set of quantum bits. It can be used with the quantum gate object to simulate quantum algorithms.
quantum_computing_ex.cpp.html
gate
dlib/quantum_computing.h
dlib/quantum_computing/quantum_computing_abstract.h
This object represents a quantum gate that operates on a quantum_register.
quantum_computing_ex.cpp.html
center
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
Returns the center point of a rectangle.
dcenter
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
Returns the center point of a rectangle. This is a version of center() which returns a double version of the point rather than one which uses integers to represent the result. Therefore, it is slightly more accurate.
centered_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
There are various overloads of this function but the basic idea is that it returns a rectangle with a given width and height and centered about a given point.
shrink_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle object, shrinks its borders by a given amount, and returns the result.
grow_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This function takes a rectangle object, grows its borders by a given amount, and returns the result.
rotate_point
dlib/geometry.h
dlib/geometry/vector_abstract.h
This is a function that rotates a 2D vector or point object about a given point.
point_rotator
dlib/geometry.h
dlib/geometry/vector_abstract.h
This is an object that rotates a 2D vector or point object about the origin.
point_transform
dlib/geometry.h
dlib/geometry/vector_abstract.h
This is an object that rotates a 2D vector or point object about the origin and then adds a displacement vector.
point_transform_affine
dlib/geometry.h
dlib/geometry/vector_abstract.h
This is an object that applies an affine transformation to a vector or point.
rotation_matrix
dlib/geometry.h
dlib/geometry/vector_abstract.h
This is a method for creating 2D rotation matrices.
get_rect
dlib/geometry.h
dlib/geometry/rectangle_abstract.h
This is a simple template function that returns a rectangle representing the size of a 2D container (e.g. matrix or array2d).
graph_contains_undirected_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks a directed_graph for undirected cycles.