# Algorithms

This page documents library components that are all basically just implementations of mathematical functions or algorithms without any really significant data structures associated with them. So this includes things like checksums, cryptographic hashes, machine learning algorithms, sorting, etc...

Objects
bigint
crc32
rand
mlp
Geometry
rectangle vector point
Bayes Utilities
assignment joint_probability_table conditional_probability_table bayes_node bayesian_network_gibbs_sampler bayesian_network_join_tree
SVM Utilities
radial_basis_kernel polynomial_kernel linear_kernel decision_function probabilistic_decision_function krls
Global Functions
randomize_samples
hsort_array
isort_array
md5
median
qsort_array
square_root
Geometry
centered_rect translate_rect resize_rect resize_rect_width resize_rect_height move_rect nearest_point
SVM Utilities
svm_nu_train svm_nu_train_prob svm_nu_cross_validate
Set Utilities
set_intersection_size set_intersection set_union set_difference
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
Bayes Node Utilities
set_node_value node_value node_is_evidence set_node_as_evidence set_node_as_nonevidence set_node_num_values node_num_values node_probability set_node_probability node_first_parent_assignment node_next_parent_assignment node_cpt_filled_out
bayesian_network_join_tree
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object represents an implementation of the join tree algorithm (a.k.a. the junction tree algorithm) for inference in bayesian networks.
bayes_net_ex.cpp.html
bayes_net_gui_ex.cpp.html
bayes_net_from_disk_ex.cpp.html
bayesian_network_gibbs_sampler
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object performs Markov Chain Monte Carlo sampling of a bayesian network using the Gibbs sampling technique.
bayes_net_ex.cpp.html
bayes_node
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object represents a node in a bayesian network. It is intended to be used inside the directed_graph object to represent bayesian networks.
bayes_net_ex.cpp.html
bayes_net_gui_ex.cpp.html
conditional_probability_table
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object represents a conditional probability table.
joint_probability_table
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object represents a joint probability table.
assignment
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This object models an assignment of random variables to particular values. It is used with the joint_probability_table and conditional_probability_table objects to represent assignments of various random variables to actual values.
bayes_net_ex.cpp.html
bayes_net_gui_ex.cpp.html
set_node_probability
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily set the probability of a bayes_node given its parents when it is inside a directed_graph object.
bayes_net_ex.cpp.html
node_first_parent_assignment
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily obtain an assignment that contains all the parents of a node in a bayesian network.
bayes_net_gui_ex.cpp.html
node_next_parent_assignment
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily loop through all the parent assignments of a node in a bayesian network.
bayes_net_gui_ex.cpp.html
node_cpt_filled_out
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily verify that a node in a bayesian network has its conditional_probability_table completely filled out.
bayes_net_gui_ex.cpp.html
node_probability
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily obtain the probability of a bayes_node given its parents when it is inside a directed_graph object.
node_num_values
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily obtain the number of values of a bayes_node when it is inside a directed_graph object.
set_node_num_values
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily set the number of values of a bayes_node when it is inside a directed_graph object.
bayes_net_ex.cpp.html
set_node_as_nonevidence
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily remove the evidence flag of a bayes_node when it is inside a directed_graph object.
bayes_net_ex.cpp.html
set_node_as_evidence
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily set the evidence flag of a bayes_node when it is inside a directed_graph object.
bayes_net_ex.cpp.html
node_is_evidence
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily determine if a bayes_node is evidence when it is inside a directed_graph object.
node_value
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily obtain the value of a bayes_node when it is inside a directed_graph object.
set_node_value
dlib/bayes_utils.h
dlib/bayes_utils/bayes_utils_abstract.h
This is a function declared in the dlib::bayes_node_utils namespace. It is a convenience function that allows you to easily modify the value of a bayes_node when it is inside a directed_graph object.
bayes_net_ex.cpp.html
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 multiplcations 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.
crc32_kernel_1
dlib/crc32/crc32_kernel_1.h
This implementation uses the polynomial 0xedb88320.
kernel_1a
is a typedef for crc32_kernel_1
rand
dlib/rand.h
dlib/rand/rand_kernel_abstract.h
This object represents a pseudorandom number generator.
rand_kernel_1
dlib/rand/rand_kernel_1.h
This implementation is done using the Mersenne Twister algorithm.
kernel_1a
is a typedef for rand_kernel_1
rand_float
dlib/rand/rand_float_abstract.h
This extension gives rand the ability to generate random floating point numbers.
rand_float_1
dlib/rand/rand_float_1.h
The implementation is obvious. Click on the link if you want to see.
float_1a
is a typedef for rand_kernel_1a extended by rand_float_1
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.
mlp
dlib/mlp.h
dlib/mlp/mlp_kernel_abstract.h
This object represents a multilayer layer perceptron network that is trained using the back propagation algorithm. The training algorithm also incorporates the momentum method. That is, each round of back propagation training also adds a fraction of the previous update. This fraction is controlled by the momentum term set in the constructor.
mlp_ex.cpp.html
mlp_kernel_1
dlib/mlp/mlp_kernel_1.h
This is implemented in the obvious way.
kernel_1a
is a typedef for mlp_kernel_1
vector
dlib/geometry.h
dlib/geometry/vector_abstract.h
This object represents a three dimensional vector.
point
dlib/geometry.h
dlib/geometry/vector_abstract.h
This object represents a point inside a Cartesian coordinate system.
krls
dlib/svm.h
dlib/svm/krls_abstract.h
This is an implementation of the kernel recursive least squares algorithm described in the paper The Kernel Recursive Least Squares Algorithm by Yaakov Engel.

The long and short of this algorithm is that it is an online kernel based regression algorithm. You give it samples (x,y) and it learns the function f(x) == y. For a detailed description of the algorithm read the above paper.

svm_nu_train_prob
dlib/svm.h
dlib/svm/svm_abstract.h

Trains a nu support vector classifier and outputs a probabilistic_decision_function.

This function uses the svm_nu_train function and creates the probability model using the technique described in the paper:

> Probabilistic Outputs for Support Vector Machines and Comparisons to Regularized Likelihood Methods by John C. Platt. Match 26, 1999

svm_ex.cpp.html
svm_nu_train
dlib/svm.h
dlib/svm/svm_abstract.h

Trains a nu support vector classifier and outputs a decision_function.

The implementation of the nu-svm training algorithm used by this library is based on the following excellent papers:

- Chang and Lin, Training {nu}-Support Vector Classifiers: Theory and Algorithms
- Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support vector machines, 2001. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm

svm_ex.cpp.html
probabilistic_decision_function
dlib/svm.h
dlib/svm/function_abstract.h
This object represents a binary decision function for use with support vector machines. It returns an estimate of the probability that a given sample is in the +1 class.
svm_ex.cpp.html
decision_function
dlib/svm.h
dlib/svm/function_abstract.h
This object represents a binary decision function for use with support vector machines.
svm_ex.cpp.html
linear_kernel
dlib/svm.h
dlib/svm/kernel_abstract.h
This object represents a linear function kernel for use with support vector machines.
polynomial_kernel
dlib/svm.h
dlib/svm/kernel_abstract.h
This object represents a polynomial kernel for use with support vector machines.
radial_basis_kernel
dlib/svm.h
dlib/svm/kernel_abstract.h
This object represents a radial basis function kernel for use with support vector machines.
svm_ex.cpp.html
randomize_samples
dlib/svm.h
dlib/svm/svm_abstract.h
Randomizes the order of samples in a column vector containing sample data.
svm_ex.cpp.html
svm_nu_cross_validate
dlib/svm.h
dlib/svm/svm_abstract.h
Performs k-fold cross validation using the svm_nu_train() function.
svm_ex.cpp.html
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.
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 paramaters 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 choral 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 nearst to the given 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.
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.
graph_contains_undirected_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks a directed_graph for undirected cycles.