# Algorithms_in_C++: machine_learning/vector_ops.hpp Source File

vector_ops.hpp
Go to the documentation of this file.
/**
* @file vector_ops.hpp
* @author [Deep Raval](https://github.com/imdeep2905)
*
* @brief Various functions for vectors associated with [NeuralNetwork (aka Multilayer Perceptron)]
* (https://en.wikipedia.org/wiki/Multilayer_perceptron).
*
*/
#ifndef VECTOR_OPS_FOR_NN
#define VECTOR_OPS_FOR_NN
#include <iostream>
#include <algorithm>
#include <vector>
#include <valarray>
#include <chrono>
#include <random>
/**
* @namespace machine_learning
* @brief Machine Learning algorithms
*/
namespace machine_learning {
/**
* Overloaded operator "<<" to print 2D vector
* @tparam T typename of the vector
* @param out std::ostream to output
* @param A 2D vector to be printed
*/
template <typename T>
std::ostream &operator<<(std::ostream &out,
std::vector<std::valarray<T>> const &A) {
// Setting output precision to 4 in case of floating point numbers
out.precision(4);
for(const auto &a : A) { // For each row in A
for(const auto &x : a) { // For each element in row
std::cerr << x << ' '; // print element
}
std::cerr << std::endl;
}
return out;
}
/**
* Overloaded operator "<<" to print a pair
* @tparam T typename of the pair
* @param out std::ostream to output
* @param A Pair to be printed
*/
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::pair<T, T> &A) {
// Setting output precision to 4 in case of floating point numbers
out.precision(4);
// printing pair in the form (p, q)
std::cerr << "(" << A.first << ", " << A.second << ")";
return out;
}
/**
* Overloaded operator "<<" to print a 1D vector
* @tparam T typename of the vector
* @param out std::ostream to output
* @param A 1D vector to be printed
*/
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::valarray<T> &A) {
// Setting output precision to 4 in case of floating point numbers
out.precision(4);
for(const auto &a : A) { // For every element in the vector.
std::cerr << a << ' '; // Print element
}
std::cerr << std::endl;
return out;
}
/**
* Function to insert element into 1D vector
* @tparam T typename of the 1D vector and the element
* @param A 1D vector in which element will to be inserted
* @param ele element to be inserted
* @return new resultant vector
*/
template <typename T>
std::valarray<T> insert_element(const std::valarray <T> &A, const T &ele) {
std::valarray <T> B; // New 1D vector to store resultant vector
B.resize(A.size() + 1); // Resizing it accordingly
for(size_t i = 0; i < A.size(); i++) { // For every element in A
B[i] = A[i]; // Copy element in B
}
B[B.size() - 1] = ele; // Inserting new element in last position
return B; // Return resultant vector
}
/**
* Function to remove first element from 1D vector
* @tparam T typename of the vector
* @param A 1D vector from which first element will be removed
* @return new resultant vector
*/
template <typename T>
std::valarray <T> pop_front(const std::valarray<T> &A) {
std::valarray <T> B; // New 1D vector to store resultant vector
B.resize(A.size() - 1); // Resizing it accordingly
for(size_t i = 1; i < A.size(); i ++) { // // For every (except first) element in A
B[i - 1] = A[i]; // Copy element in B with left shifted position
}
return B; // Return resultant vector
}
/**
* Function to remove last element from 1D vector
* @tparam T typename of the vector
* @param A 1D vector from which last element will be removed
* @return new resultant vector
*/
template <typename T>
std::valarray <T> pop_back(const std::valarray<T> &A) {
std::valarray <T> B; // New 1D vector to store resultant vector
B.resize(A.size() - 1); // Resizing it accordingly
for(size_t i = 0; i < A.size() - 1; i ++) { // For every (except last) element in A
B[i] = A[i]; // Copy element in B
}
return B; // Return resultant vector
}
/**
* Function to equally shuffle two 3D vectors (used for shuffling training data)
* @tparam T typename of the vector
* @param A First 3D vector
* @param B Second 3D vector
*/
template <typename T>
void equal_shuffle(std::vector < std::vector <std::valarray<T>> > &A,
std::vector < std::vector <std::valarray<T>> > &B) {
// If two vectors have different sizes
if(A.size() != B.size())
{
std::cerr << "ERROR : Can not equally shuffle two vectors with different sizes: ";
std::cerr << A.size() << " and " << B.size() << std::endl;
std::exit(EXIT_FAILURE);
}
for(size_t i = 0; i < A.size(); i++) { // For every element in A and B
// Genrating random index < size of A and B
std::srand(std::chrono::system_clock::now().time_since_epoch().count());
size_t random_index = std::rand() % A.size();
// Swap elements in both A and B with same random index
std::swap(A[i], A[random_index]);
std::swap(B[i], B[random_index]);
}
return;
}
/**
* Function to initialize given 2D vector using uniform random initialization
* @tparam T typename of the vector
* @param A 2D vector to be initialized
* @param shape required shape
* @param low lower limit on value
* @param high upper limit on value
*/
template <typename T>
void uniform_random_initialization(std::vector<std::valarray<T>> &A,
const std::pair<size_t, size_t> &shape,
const T &low,
const T &high) {
A.clear(); // Making A empty
// Uniform distribution in range [low, high]
std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_real_distribution <T> distribution(low, high);
for(size_t i = 0; i < shape.first; i++) { // For every row
std::valarray <T> row; // Making empty row which will be inserted in vector
row.resize(shape.second);
for(auto &r : row) { // For every element in row
r = distribution(generator); // copy random number
}
A.push_back(row); // Insert new row in vector
}
return;
}
/**
* Function to Intialize 2D vector as unit matrix
* @tparam T typename of the vector
* @param A 2D vector to be initialized
* @param shape required shape
*/
template <typename T>
void unit_matrix_initialization(std::vector<std::valarray<T>> &A,
const std::pair<size_t, size_t> &shape
) {
A.clear(); // Making A empty
for(size_t i = 0; i < shape.first; i++) {
std::valarray <T> row; // Making empty row which will be inserted in vector
row.resize(shape.second);
row[i] = T(1); // Insert 1 at ith position
A.push_back(row); // Insert new row in vector
}
return;
}
/**
* Function to Intialize 2D vector as zeroes
* @tparam T typename of the vector
* @param A 2D vector to be initialized
* @param shape required shape
*/
template <typename T>
void zeroes_initialization(std::vector<std::valarray<T>> &A,
const std::pair<size_t, size_t> &shape
) {
A.clear(); // Making A empty
for(size_t i = 0; i < shape.first; i++) {
std::valarray <T> row; // Making empty row which will be inserted in vector
row.resize(shape.second); // By default all elements are zero
A.push_back(row); // Insert new row in vector
}
return;
}
/**
* Function to get sum of all elements in 2D vector
* @tparam T typename of the vector
* @param A 2D vector for which sum is required
* @return returns sum of all elements of 2D vector
*/
template <typename T>
T sum(const std::vector<std::valarray<T>> &A) {
T cur_sum = 0; // Initially sum is zero
for(const auto &a : A) { // For every row in A
cur_sum += a.sum(); // Add sum of that row to current sum
}
return cur_sum; // Return sum
}
/**
* Function to get shape of given 2D vector
* @tparam T typename of the vector
* @param A 2D vector for which shape is required
* @return shape as pair
*/
template <typename T>
std::pair<size_t, size_t> get_shape(const std::vector<std::valarray<T>> &A) {
const size_t sub_size = (*A.begin()).size();
for(const auto &a : A) {
// If supplied vector don't have same shape in all rows
if(a.size() != sub_size) {
std::cerr << "ERROR: (get_shape) Supplied vector is not 2D Matrix" << std::endl;
std::exit(EXIT_FAILURE);
}
}
return std::make_pair(A.size(), sub_size); // Return shape as pair
}
/**
* Function to scale given 3D vector using min-max scaler
* @tparam T typename of the vector
* @param A 3D vector which will be scaled
* @param low new minimum value
* @param high new maximum value
* @return new scaled 3D vector
*/
template <typename T>
std::vector<std::vector<std::valarray<T>>>
minmax_scaler(const std::vector<std::vector<std::valarray<T>>> &A, const T &low, const T &high) {
std::vector<std::vector<std::valarray<T>>> B = A; // Copying into new vector B
const auto shape = get_shape(B[0]); // Storing shape of B's every element
// As this function is used for scaling training data vector should be of shape (1, X)
if(shape.first != 1) {
std::cerr << "ERROR: (MinMax Scaling) Supplied vector is not supported for minmax scaling, shape: ";
std::cerr << shape << std::endl;
std::exit(EXIT_FAILURE);
}
for(size_t i = 0; i < shape.second; i++) {
T min = B[0][0][i], max = B[0][0][i];
for(size_t j = 0; j < B.size(); j++) {
// Updating minimum and maximum values
min = std::min(min, B[j][0][i]);
max = std::max(max, B[j][0][i]);
}
for(size_t j = 0; j < B.size(); j++) {
// Applying min-max scaler formula
B[j][0][i] = ((B[j][0][i] - min) / (max - min)) * (high - low) + low;
}
}
return B; // Return new resultant 3D vector
}
/**
* Function to get index of maximum element in 2D vector
* @tparam T typename of the vector
* @param A 2D vector for which maximum index is required
* @return index of maximum element
*/
template <typename T>
size_t argmax(const std::vector<std::valarray<T>> &A) {
const auto shape = get_shape(A);
// As this function is used on predicted (or target) vector, shape should be (1, X)
if(shape.first != 1) {
std::cerr << "ERROR: (argmax) Supplied vector is ineligible for argmax" << std::endl;
std::exit(EXIT_FAILURE);
}
// Return distance of max element from first element (i.e. index)
return std::distance(std::begin(A[0]), std::max_element(std::begin(A[0]), std::end(A[0])));
}
/**
* Function which applys supplied function to every element of 2D vector
* @tparam T typename of the vector
* @param A 2D vector on which function will be applied
* @param func Function to be applied
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T>> apply_function(const std::vector <std::valarray <T>> &A,
T (*func) (const T &)) {
std::vector<std::valarray<double>> B = A; // New vector to store resultant vector
for(auto &b : B) { // For every row in vector
b = b.apply(func); // Apply function to that row
}
return B; // Return new resultant 2D vector
}
/**
* Overloaded operator "*" to multiply given 2D vector with scaler
* @tparam T typename of both vector and the scaler
* @param A 2D vector to which scaler will be multiplied
* @param val Scaler value which will be multiplied
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T> > operator * (const std::vector<std::valarray<T>> &A, const T& val) {
std::vector<std::valarray<double>> B = A; // New vector to store resultant vector
for(auto &b : B) { // For every row in vector
b = b * val; // Multiply row with scaler
}
return B; // Return new resultant 2D vector
}
/**
* Overloaded operator "/" to divide given 2D vector with scaler
* @tparam T typename of the vector and the scaler
* @param A 2D vector to which scaler will be divided
* @param val Scaler value which will be divided
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T> > operator / (const std::vector<std::valarray<T>> &A, const T& val) {
std::vector<std::valarray<double>> B = A; // New vector to store resultant vector
for(auto &b : B) { // For every row in vector
b = b / val; // Divide row with scaler
}
return B; // Return new resultant 2D vector
}
/**
* Function to get transpose of 2D vector
* @tparam T typename of the vector
* @param A 2D vector which will be transposed
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T>> transpose(const std::vector<std::valarray<T>> &A) {
const auto shape = get_shape(A); // Current shape of vector
std::vector <std::valarray <T> > B; // New vector to store result
// Storing transpose values of A in B
for(size_t j = 0; j < shape.second; j++) {
std::valarray <T> row;
row.resize(shape.first);
for(size_t i = 0; i < shape.first; i++) {
row[i] = A[i][j];
}
B.push_back(row);
}
return B; // Return new resultant 2D vector
}
/**
* Overloaded operator "+" to add two 2D vectors
* @tparam T typename of the vector
* @param A First 2D vector
* @param B Second 2D vector
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T> > operator + (const std::vector<std::valarray<T>> &A, const std::vector<std::valarray<T>> &B) {
const auto shape_a = get_shape(A);
const auto shape_b = get_shape(B);
// If vectors don't have equal shape
if(shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
std::cerr << "ERROR: (vector addition) Supplied vectors have different shapes ";
std::cerr << shape_a << " and " << shape_b << std::endl;
std::exit(EXIT_FAILURE);
}
std::vector<std::valarray <T>> C;
for(size_t i = 0; i < A.size(); i++) { // For every row
C.push_back(A[i] + B[i]); // Elementwise addition
}
return C; // Return new resultant 2D vector
}
/**
* Overloaded operator "-" to add subtract 2D vectors
* @tparam T typename of the vector
* @param A First 2D vector
* @param B Second 2D vector
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T>> operator - (const std::vector<std::valarray<T>> &A, const std::vector<std::valarray<T>> &B) {
const auto shape_a = get_shape(A);
const auto shape_b = get_shape(B);
// If vectors don't have equal shape
if(shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
std::cerr << "ERROR: (vector subtraction) Supplied vectors have different shapes ";
std::cerr << shape_a << " and " << shape_b << std::endl;
std::exit(EXIT_FAILURE);
}
std::vector<std::valarray<T>> C; // Vector to store result
for(size_t i = 0; i < A.size(); i++) { // For every row
C.push_back(A[i] - B[i]); // Elementwise substraction
}
return C; // Return new resultant 2D vector
}
/**
* Function to multiply two 2D vectors
* @tparam T typename of the vector
* @param A First 2D vector
* @param B Second 2D vector
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T>> multiply(const std::vector<std::valarray<T>> &A, const std::vector<std::valarray<T>> &B) {
const auto shape_a = get_shape(A);
const auto shape_b = get_shape(B);
// If vectors are not eligible for multiplication
if(shape_a.second != shape_b.first ) {
std::cerr << "ERROR: (multiply) Supplied vectors are not eligible for multiplication ";
std::cerr << shape_a << " and " << shape_b << std::endl;
std::exit(EXIT_FAILURE);
}
std::vector<std::valarray<T>> C; // Vector to store result
// Normal matrix multiplication
for (size_t i = 0; i < shape_a.first; i++) {
std::valarray<T> row;
row.resize(shape_b.second);
for(size_t j = 0; j < shape_b.second; j++) {
for(size_t k = 0; k < shape_a.second; k++) {
row[j] += A[i][k] * B[k][j];
}
}
C.push_back(row);
}
return C; // Return new resultant 2D vector
}
/**
* Function to get hadamard product of two 2D vectors
* @tparam T typename of the vector
* @param A First 2D vector
* @param B Second 2D vector
* @return new resultant vector
*/
template <typename T>
std::vector <std::valarray <T>> hadamard_product(const std::vector<std::valarray<T>> &A, const std::vector<std::valarray<T>> &B) {
const auto shape_a = get_shape(A);
const auto shape_b = get_shape(B);
// If vectors are not eligible for hadamard product
if(shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
std::cerr << "ERROR: (hadamard_product) Supplied vectors have different shapes ";
std::cerr << shape_a << " and " << shape_b << std::endl;
std::exit(EXIT_FAILURE);
}
std::vector<std::valarray<T>> C; // Vector to store result
for(size_t i = 0; i < A.size(); i++) {
C.push_back(A[i] * B[i]); // Elementwise multiplication
}
return C; // Return new resultant 2D vector
}
} // namespace machine_learning
#endif
number_of_digits
int number_of_digits(int num)
Definition: armstrong_number.cpp:21
double_hashing::Entry
Definition: double_hash_hash_table.cpp:36
std::showpoint
T showpoint(T... args)
stack::pop
void pop()
Definition: stack.h:99
is_armstrong
bool is_armstrong(int number)
Definition: armstrong_number.cpp:36
trie
Definition: trie_tree.cpp:8
std::srand
T srand(T... args)
graph::addEdge
void addEdge(std::vector< std::vector< std::pair< int, int >>> *adj, int u, int v, int w)
Function that add edge between two nodes or vertices of graph.
Definition: dijkstra.cpp:48
std::max_element
T max_element(T... args)
machine_learning::uniform_random_initialization
void uniform_random_initialization(std::vector< std::valarray< T >> &A, const std::pair< size_t, size_t > &shape, const T &low, const T &high)
Definition: vector_ops.hpp:162
machine_learning::equal_shuffle
void equal_shuffle(std::vector< std::vector< std::valarray< T >> > &A, std::vector< std::vector< std::valarray< T >> > &B)
Definition: vector_ops.hpp:133
std::setprecision
T setprecision(T... args)
graph::breadth_first_search
std::vector< bool > breadth_first_search(const std::vector< std::vector< int >> &graph, int start)
Function performs the breadth first search algorithm over the graph.
Definition: breadth_first_search.cpp:95
std::vector::resize
T resize(T... args)
std::bitset< MAXN >
linear_probing::Entry::key
int key
key value
Definition: linear_probing_hash_table.cpp:37
std::make_tuple
T make_tuple(T... args)
machine_learning::apply_function
std::vector< std::valarray< T > > apply_function(const std::vector< std::valarray< T >> &A, T(*func)(const T &))
Definition: vector_ops.hpp:315
geometry::jarvis::Convexhull::getConvexHull
std::vector< Point > getConvexHull() const
Definition: jarvis_algorithm.cpp:78
test
static void test()
Definition: shortest_common_supersequence.cpp:124
Graph::getAdjList
std::remove_reference< AdjList >::type const & getAdjList() const
Definition: cycle_check_directed_graph.cpp:103
machine_learning::neural_network::layers::DenseLayer::~DenseLayer
~DenseLayer()=default
CycleCheck::isCyclicBFS
static bool isCyclicBFS(Graph const &graph)
Definition: cycle_check_directed_graph.cpp:249
std::strlen
T strlen(T... args)
test
static void test()
Definition: jarvis_algorithm.cpp:151
quadratic_probing::removalInfo
void removalInfo(int key)
Definition: quadratic_probing_hash_table.cpp:222
graph::is_graph_bipartite::Graph::nax
static const int nax
stores the side of the vertex
Definition: is_graph_bipartite.cpp:57
machine_learning::transpose
std::vector< std::valarray< T > > transpose(const std::vector< std::valarray< T >> &A)
Definition: vector_ops.hpp:363
Graph::getVertices
unsigned int getVertices() const
Definition: cycle_check_directed_graph.cpp:110
double_hashing::addInfo
void addInfo(int key)
Definition: double_hash_hash_table.cpp:212
double_hashing::otherHashFxn
size_t otherHashFxn(int key)
Used for second hash function.
Definition: double_hash_hash_table.cpp:58
shortest_common_supersequence
Shortest Common Super Sequence algorithm.
std::string
STL class.
std::equal
T equal(T... args)
std::shared_ptr
STL class.
machine_learning::neural_network::layers::DenseLayer::operator=
DenseLayer & operator=(const DenseLayer &layer)=default
is_graph_bipartite
Functions for checking whether a graph is bipartite or not.
graph::Graph::Graph
Graph(size_t N, const std::vector< std::pair< int, int > > &undirected_edges)
Populate the adjacency list for each vertex in the graph. Assumes that evey edge is a pair of valid v...
Definition: lowest_common_ancestor.cpp:61
MAX
#define MAX
Definition: fibonacci_fast.cpp:27
machine_learning::pop_back
std::valarray< T > pop_back(const std::valarray< T > &A)
Definition: vector_ops.hpp:117
Graph::addVertices
void addVertices(unsigned int num=1)
Definition: cycle_check_directed_graph.cpp:118
std::list
STL class.
graph::LowestCommonAncestor::LowestCommonAncestor
LowestCommonAncestor(const RootedTree &tree_)
Stores the tree and precomputs "up lifts".
Definition: lowest_common_ancestor.cpp:151
std::inner_product
T inner_product(T... args)
linear_probing::Entry::Entry
Entry(int key=notPresent)
constructor
Definition: linear_probing_hash_table.cpp:36
std::clock_t
std::move
T move(T... args)
operator+
std::vector< T > operator+(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:204
linear_probing::putProber
bool putProber(const Entry &entry, int key)
Definition: linear_probing_hash_table.cpp:98
machine_learning::pop_front
std::valarray< T > pop_front(const std::valarray< T > &A)
Definition: vector_ops.hpp:101
double_hashing
An implementation of hash table using double hashing algorithm.
machine_learning::neural_network::layers::DenseLayer::DenseLayer
DenseLayer(const int &neurons, const std::string &activation, const std::pair< size_t, size_t > &kernal_shape, const bool &random_kernal)
Definition: neural_network.cpp:150
linear_probing::Entry
Definition: linear_probing_hash_table.cpp:35
std::pair
machine_learning::neural_network::NeuralNetwork::~NeuralNetwork
~NeuralNetwork()=default
graph::RootedTree::level
std::vector< int > level
Stores the distance from the root.
Definition: lowest_common_ancestor.cpp:105
double_hashing::removalInfo
void removalInfo(int key)
Definition: double_hash_hash_table.cpp:227
hash_chain::find
bool find(int x, int h) const
Find if a value and corresponding hash exist.
Definition: chaining.cpp:101
std::cos
T cos(T... args)
machine_learning::adaline::adaline
adaline(int num_features, const double eta=0.01f, const double accuracy=1e-5)
Definition: adaline_learning.cpp:55
geometry
Geometry algorithms.
Trie
Definition: trie_modern.cpp:16
linear_probing::rehash
void rehash()
Definition: linear_probing_hash_table.cpp:138
machine_learning::neural_network::NeuralNetwork::NeuralNetwork
NeuralNetwork(const std::vector< std::pair< int, std::string >> &config)
Definition: neural_network.cpp:322
std::vector
STL class.
std::map::find
T find(T... args)
quadratic_probing
An implementation of hash table using quadratic probing algorithm.
test1
void test1()
Definition: kohonen_som_topology.cpp:369
std::string::size
T size(T... args)
machine_learning::adaline::fit
double fit(const std::vector< double > &x, const int &y)
Definition: adaline_learning.cpp:119
main
int main()
Definition: double_hash_hash_table.cpp:250
machine_learning::operator/
std::vector< std::valarray< T > > operator/(const std::vector< std::valarray< T >> &A, const T &val)
Definition: vector_ops.hpp:348
geometry::jarvis::Convexhull::Convexhull
Convexhull(const std::vector< Point > &pointList)
Definition: jarvis_algorithm.cpp:66
ans
ll ans(ll n)
Definition: matrix_exponentiation.cpp:91
std::stack
STL class.
double_hashing::Entry::Entry
Entry(int key=notPresent)
constructor
Definition: double_hash_hash_table.cpp:37
machine_learning::neural_network::NeuralNetwork::load_model
NeuralNetwork load_model(const std::string &file_name)
Definition: neural_network.cpp:711
dynamic_programming::shortest_common_supersequence::scs
std::string scs(const std::string &str1, const std::string &str2)
Definition: shortest_common_supersequence.cpp:42
main
int main(int argc, char **argv)
Definition: kohonen_som_topology.cpp:582
Trie::hasChildren
static bool hasChildren(std::shared_ptr< TrieNode > node)
Definition: trie_modern.cpp:41
double_hashing::putProber
bool putProber(const Entry &entry, int key)
Definition: double_hash_hash_table.cpp:120
main
int main(int argc, char **argv)
Definition: spirograph.cpp:268
Graph::Graph
Graph(unsigned int vertices, AdjList adjList)
Definition: cycle_check_directed_graph.cpp:68
std::default_random_engine
std::queue::emplace
T emplace(T... args)
graph::getConnectedComponents
int getConnectedComponents(const std::vector< std::vector< int >> *adj)
Function that perfoms depth first search algorithm on graph and calculated the number of connected co...
Definition: connected_components.cpp:77
graph::LowestCommonAncestor::populate_up
void populate_up()
Definition: lowest_common_ancestor.cpp:212
std::stringstream
STL class.
test_3d_classes
void test_3d_classes(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:359
machine_learning::neural_network::NeuralNetwork::operator=
NeuralNetwork & operator=(const NeuralNetwork &model)=default
Trie::TrieNode
Definition: trie_modern.cpp:26
machine_learning::neural_network::activations::drelu
double drelu(const double &x)
Definition: neural_network.cpp:80
std::distance
T distance(T... args)
machine_learning::operator-
std::vector< std::valarray< T > > operator-(const std::vector< std::valarray< T >> &A, const std::vector< std::valarray< T >> &B)
Definition: vector_ops.hpp:410
node
Definition: avltree.cpp:13
graph::RootedTree
Definition: lowest_common_ancestor.cpp:84
std::search
T search(T... args)
quadratic_probing::putProber
bool putProber(const Entry &entry, int key)
Definition: quadratic_probing_hash_table.cpp:106
main
int main()
Definition: is_graph_bipartite.cpp:160
quadratic_probing::display
void display()
Definition: quadratic_probing_hash_table.cpp:142
quadratic_probing::Entry
Definition: quadratic_probing_hash_table.cpp:37
save_nd_data
int save_nd_data(const char *fname, const std::vector< std::valarray< double >> &X)
Definition: kohonen_som_trace.cpp:58
node
struct list node
hash_chain
Chain class with a given modulus.
Definition: chaining.cpp:16
machine_learning::operator+
std::vector< std::valarray< T > > operator+(const std::vector< std::valarray< T >> &A, const std::vector< std::valarray< T >> &B)
Definition: vector_ops.hpp:386
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Definition: kohonen_som_trace.cpp:452
test2
void test2(const std::string &text)
Self test 2 - using 8x8 randomly generated key.
Definition: hill_cipher.cpp:505
graph::add_directed_edge
void add_directed_edge(std::vector< std::vector< int >> *graph, int u, int v)
Adds a directed edge from vertex u to vertex v.
Definition: breadth_first_search.cpp:66
std::setfill
T setfill(T... args)
std::reverse
T reverse(T... args)
Graph::Graph
Graph(unsigned int vertices, std::vector< Edge > const &edges)
Definition: cycle_check_directed_graph.cpp:88
std::vector::back
T back(T... args)
test1
static void test1()
Definition: hamiltons_cycle.cpp:81
linear_probing::searchingProber
bool searchingProber(const Entry &entry, int key)
Definition: linear_probing_hash_table.cpp:110
machine_learning::adaline::predict
int predict(const std::vector< double > &x, double *out=nullptr)
Definition: adaline_learning.cpp:95
graph::RootedTree::populate_parents
void populate_parents()
Calculate the parents for all the vertices in the tree. Implements the breadth first search algorithm...
Definition: lowest_common_ancestor.cpp:116
machine_learning
Machine learning algorithms.
std::strerror
T strerror(T... args)
quadratic_probing::find
Entry find(int key)
Definition: quadratic_probing_hash_table.cpp:131
is_square
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:59
machine_learning::adaline::activation
int activation(double x)
Definition: adaline_learning.cpp:186
linear_probing::hashFxn
size_t hashFxn(int key)
Hash a key. Uses the STL library's std::hash() function.
Definition: linear_probing_hash_table.cpp:46
machine_learning::update_weights
double update_weights(const std::valarray< double > &X, std::vector< std::vector< std::valarray< double >>> *W, std::vector< std::valarray< double >> *D, double alpha, int R)
Definition: kohonen_som_topology.cpp:200
std::queue
STL class.
linear_probing::addInfo
void addInfo(int key)
Definition: linear_probing_hash_table.cpp:186
Graph
Definition: bellman_ford.cpp:13
Solution
Definition: bridge_finding_with_tarjan_algorithm.cpp:11
linear_probing::remove
void remove(int key)
Definition: linear_probing_hash_table.cpp:173
get_min_2d
void get_min_2d(const std::vector< std::valarray< double >> &X, double *val, int *x_idx, int *y_idx)
Definition: kohonen_som_topology.cpp:105
sorting::shuffle
std::array< T, N > shuffle(std::array< T, N > arr)
Definition: bogo_sort.cpp:36
hash_chain::head
std::vector< std::shared_ptr< Node > > head
array of nodes
Definition: chaining.cpp:24
std::queue::front
T front(T... args)
machine_learning::neural_network::NeuralNetwork::NeuralNetwork
NeuralNetwork(NeuralNetwork &&)=default
machine_learning::neural_network::NeuralNetwork::batch_predict
std::vector< std::vector< std::valarray< double > > > batch_predict(const std::vector< std::vector< std::valarray< double >>> &X)
Definition: neural_network.cpp:466
std::sort
T sort(T... args)
machine_learning::operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::valarray< T >> const &A)
Definition: vector_ops.hpp:31
machine_learning::adaline::check_size_match
bool check_size_match(const std::vector< double > &x)
Definition: adaline_learning.cpp:196
std::sqrt
T sqrt(T... args)
stack_idx
int stack_idx
pointer to track stack index
Definition: paranthesis_matching.cpp:23
machine_learning::neural_network::NeuralNetwork::evaluate_from_csv
void evaluate_from_csv(const std::string &file_name, const bool &last_label, const bool &normalize, const int &slip_lines=1)
Definition: neural_network.cpp:624
main
int main()
Definition: breadth_first_search.cpp:161
test1
void test1()
Definition: kohonen_som_trace.cpp:233
std::vector::clear
T clear(T... args)
hash_chain::add
void add(int x, int h)
create and add a new node with a give value and at a given height
Definition: chaining.cpp:45
machine_learning::hadamard_product
std::vector< std::valarray< T > > hadamard_product(const std::vector< std::valarray< T >> &A, const std::vector< std::valarray< T >> &B)
Definition: vector_ops.hpp:466
machine_learning::multiply
std::vector< std::valarray< T > > multiply(const std::vector< std::valarray< T >> &A, const std::vector< std::valarray< T >> &B)
Definition: vector_ops.hpp:434
quadratic_probing::remove
void remove(int key)
Definition: quadratic_probing_hash_table.cpp:194
std::uniform_real_distribution
linear_probing::linearProbe
int linearProbe(int key, bool searching)
Definition: linear_probing_hash_table.cpp:55
operator*
std::vector< std::vector< T > > operator*(std::vector< std::vector< T >> const &A, std::vector< std::vector< T >> const &B)
Definition: ordinary_least_squares_regressor.cpp:78
MAX_ITER
constexpr int MAX_ITER
Definition: adaline_learning.cpp:40
spirograph
test
static void test()
namespace graph
Definition: is_graph_bipartite.cpp:129
machine_learning::argmax
size_t argmax(const std::vector< std::valarray< T >> &A)
Definition: vector_ops.hpp:296
std::tie
T tie(T... args)
Node
Definition: linkedlist_implentation_usingarray.cpp:14
std::string::push_back
T push_back(T... args)
Point::y
int y
Point respect to x coordinate.
Definition: line_segment_intersection.cpp:14
test
static void test()
Definition: neural_network.cpp:766
std::clock
T clock(T... args)
main
int main(int argc, char **argv)
Definition: kohonen_som_trace.cpp:457
Trie::insert
void insert(const std::string &word)
Definition: trie_modern.cpp:109
operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:22
CycleCheck::isCyclicDFS
static bool isCyclicDFS(Graph const &graph)
Definition: cycle_check_directed_graph.cpp:212
tests
void tests()
Definition: dijkstra.cpp:113
test3
void test3()
Definition: kohonen_som_topology.cpp:537
createNode
node * createNode(int data)
Definition: avltree.cpp:21
CycleCheck
Definition: cycle_check_directed_graph.cpp:158
machine_learning::neural_network::NeuralNetwork::evaluate
void evaluate(const std::vector< std::vector< std::valarray< double >>> &X, const std::vector< std::vector< std::valarray< double >>> &Y)
Definition: neural_network.cpp:594
machine_learning::unit_matrix_initialization
void unit_matrix_initialization(std::vector< std::valarray< T >> &A, const std::pair< size_t, size_t > &shape)
Definition: vector_ops.hpp:189
graph::RootedTree::parent
std::vector< int > parent
Stores parent of every vertex and for root its own index. The root is technically not its own parent,...
Definition: lowest_common_ancestor.cpp:103
graph::dijkstra
int dijkstra(std::vector< std::vector< std::pair< int, int >>> *adj, int s, int t)
Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and return...
Definition: dijkstra.cpp:66
CycleCheck::isCyclicDFSHelper
static bool isCyclicDFSHelper(AdjList const &adjList, std::vector< nodeStates > *state, unsigned int node)
Definition: cycle_check_directed_graph.cpp:170
machine_learning::neural_network::NeuralNetwork::single_predict
std::vector< std::valarray< double > > single_predict(const std::vector< std::valarray< double >> &X)
Definition: neural_network.cpp:453
machine_learning::neural_network::layers::DenseLayer::DenseLayer
DenseLayer(const int &neurons, const std::string &activation, const std::vector< std::valarray< double >> &kernal)
Definition: neural_network.cpp:195
graph::RootedTree::RootedTree
RootedTree(const std::vector< std::pair< int, int > > &undirected_edges, int root_)
Constructs the tree by calculating parent for every vertex. Assumes a valid description of a tree is ...
Definition: lowest_common_ancestor.cpp:93
MinHeapNode
Definition: huffman.cpp:7
main
int main()
Definition: line_segment_intersection.cpp:92
quadratic_probing::Entry::key
int key
key value
Definition: quadratic_probing_hash_table.cpp:39
main
int main()
Definition: connected_components.cpp:127
test1
void test1(double eta=0.01)
Definition: adaline_learning.cpp:224
insert
node * insert(node *root, int item)
Definition: avltree.cpp:66
std::printf
T printf(T... args)
std::vector::at
T at(T... args)
neural_network
Neural Network or Multilayer Perceptron.
graph::depth_first_search
void depth_first_search(const std::vector< std::vector< size_t >> &adj, size_t start)
initiates depth first search algorithm.
Definition: depth_first_search.cpp:99
hash_chain::_mod
int _mod
modulus of the class
Definition: chaining.cpp:27
std::cout
h
int h(int key)
Definition: hash_search.cpp:45
std::ofstream
STL class.
SegmentIntersection::direction
int direction(Point first_point, Point second_point, Point third_point)
Definition: line_segment_intersection.cpp:63
main
int main()
Definition: depth_first_search.cpp:109
machine_learning::adaline::eta
const double eta
learning rate of the algorithm
Definition: adaline_learning.cpp:207
std::min_element
T min_element(T... args)
machine_learning::neural_network::NeuralNetwork::fit
void fit(const std::vector< std::vector< std::valarray< double >>> &X_, const std::vector< std::vector< std::valarray< double >>> &Y_, const int &epochs=100, const double &learning_rate=0.01, const size_t &batch_size=32, const bool &shuffle=true)
Definition: neural_network.cpp:485
graph::Graph::neighbors
std::vector< std::vector< int > > neighbors
for each vertex it stores a list indicies of its neighbors
Definition: lowest_common_ancestor.cpp:78
std::string::c_str
T c_str(T... args)
activations
Various activation functions used in Neural network.
graph::is_graph_bipartite::Graph::adj
std::vector< std::vector< int > > adj
size of the graph
Definition: is_graph_bipartite.cpp:53
machine_learning::neural_network::activations::sigmoid
double sigmoid(const double &x)
Definition: neural_network.cpp:53
double_hashing::hashFxn
size_t hashFxn(int key)
Hash a key. Uses the STL library's std::hash() function.
Definition: double_hash_hash_table.cpp:47
std::queue::pop
T pop(T... args)
std::priority_queue::top
T top(T... args)
machine_learning::neural_network::activations::relu
double relu(const double &x)
Definition: neural_network.cpp:71
Edge::Edge
Edge(unsigned int source, unsigned int destination)
Definition: cycle_check_directed_graph.cpp:40
Trie::Trie
Trie()
constructor to initialise the root of the trie.
Definition: trie_modern.cpp:103
mst
Definition: prims_minimum_spanning_tree.cpp:9
dynamic_programming
Dynamic Programming algorithms.
std::array
STL class.
Graph::addEdge
void addEdge(unsigned int source, unsigned int destination)
Definition: cycle_check_directed_graph.cpp:136
machine_learning::insert_element
std::valarray< T > insert_element(const std::valarray< T > &A, const T &ele)
Definition: vector_ops.hpp:84
test
void test()
Definition: armstrong_number.cpp:59
quadratic_probing::add
void add(int key)
Definition: quadratic_probing_hash_table.cpp:182
std::ofstream::close
T close(T... args)
machine_learning::neural_network::util_functions::square
double square(const double &x)
Definition: neural_network.cpp:111
main
int main()
Definition: chaining.cpp:133
test2
static void test2()
Definition: hamiltons_cycle.cpp:103
std::set::erase
T erase(T... args)
machine_learning::adaline::weights
std::vector< double > weights
weights of the neural network
Definition: adaline_learning.cpp:209
std::valarray< double >
SegmentIntersection
Definition: line_segment_intersection.cpp:22
main
int main()
Definition: ordinary_least_squares_regressor.cpp:423
height
int height(node *root)
Definition: avltree.cpp:31
predict_OLS_regressor
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:352
std::runtime_error
STL class.
std::ifstream::open
T open(T... args)
machine_learning::adaline::fit
void fit(std::array< std::vector< double >, N > const &X, std::array< int, N > const &Y)
Definition: adaline_learning.cpp:145
graph::addEdge
void addEdge(std::vector< std::vector< int >> *adj, int u, int v)
Function that add edge between two nodes or vertices of graph.
Definition: connected_components.cpp:46
test_3d_classes1
void test_3d_classes1(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:411
fib
uint64_t fib(uint64_t n)
Definition: fibonacci_fast.cpp:30
quadratic_probing::rehash
void rehash()
Definition: quadratic_probing_hash_table.cpp:160
test2
void test2()
Definition: kohonen_som_topology.cpp:451
SegmentIntersection::on_segment
bool on_segment(Point first_point, Point second_point, Point third_point)
Definition: line_segment_intersection.cpp:75
graph::is_graph_bipartite::Graph::is_bipartite
bool is_bipartite()
function to add edges to our graph
Definition: is_graph_bipartite.cpp:98
double_hashing::rehash
void rehash()
Definition: double_hash_hash_table.cpp:161
endl
#define endl
Definition: matrix_exponentiation.cpp:36
stack::push
void push(Type item)
Definition: stack.h:83
test2
void test2()
Definition: kohonen_som_trace.cpp:315
std::map< unsigned int, std::vector< unsigned int > >
hash_chain::hash
virtual int hash(int x) const
Compute the hash of a value for current chain.
Definition: chaining.cpp:91
quadratic_probing::addInfo
void addInfo(int key)
Definition: quadratic_probing_hash_table.cpp:207
double_hashing::display
void display()
Definition: double_hash_hash_table.cpp:143
double_hashing::remove
void remove(int key)
Definition: double_hash_hash_table.cpp:199
graph::add_undirected_edge
void add_undirected_edge(std::vector< std::vector< int >> *graph, int u, int v)
Adds an undirected edge from vertex u to vertex v. Essentially adds too directed edges to the adjacen...
Definition: breadth_first_search.cpp:81
main
int main()
Definition: jarvis_algorithm.cpp:176
machine_learning::neural_network::NeuralNetwork::fit_from_csv
void fit_from_csv(const std::string &file_name, const bool &last_label, const int &epochs, const double &learning_rate, const bool &normalize, const int &slip_lines=1, const size_t &batch_size=32, const bool &shuffle=true)
Definition: neural_network.cpp:574
print
void print(uint32_t N, const std::vector< bool > &is_prime)
Definition: sieve_of_eratosthenes.cpp:44
main
int main(int argc, char **argv)
Definition: hamiltons_cycle.cpp:142
machine_learning::neural_network::NeuralNetwork::NeuralNetwork
NeuralNetwork()=default
Graph::Graph
Graph(unsigned int vertices, AdjList &&adjList)
Definition: cycle_check_directed_graph.cpp:76
machine_learning::neural_network::NeuralNetwork
Definition: neural_network.cpp:261
machine_learning::neural_network::NeuralNetwork::__detailed_single_prediction
std::vector< std::vector< std::valarray< double > > > __detailed_single_prediction(const std::vector< std::valarray< double >> &X)
Definition: neural_network.cpp:299
std::priority_queue
STL class.
std::rand
T rand(T... args)
jarvis
Functions for Jarvis’s algorithm.
graph::is_graph_bipartite::Graph::side
std::vector< int > side
adj stores the graph as an adjacency list
Definition: is_graph_bipartite.cpp:55
save_2d_data
int save_2d_data(const char *fname, const std::vector< std::valarray< double >> &X)
Definition: kohonen_som_topology.cpp:65
linear_probing
An implementation of hash table using linear probing algorithm.
test_lamniscate
void test_lamniscate(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:277
std::swap
T swap(T... args)
main
int main()
Definition: trie_modern.cpp:160
machine_learning::neural_network::NeuralNetwork::NeuralNetwork
NeuralNetwork(const NeuralNetwork &model)=default
std::min
T min(T... args)
std::sin
T sin(T... args)
Edge
Definition: bellman_ford.cpp:7
machine_learning::minmax_scaler
std::vector< std::vector< std::valarray< T > > > minmax_scaler(const std::vector< std::vector< std::valarray< T >>> &A, const T &low, const T &high)
Definition: vector_ops.hpp:265
quadratic_probing::Entry::Entry
Entry(int key=notPresent)
constructor
Definition: quadratic_probing_hash_table.cpp:38
stack::top
Type top()
Definition: stack.h:93
geometry::jarvis::Convexhull
Definition: jarvis_algorithm.cpp:55
tests
void tests()
Definition: breadth_first_search.cpp:121
hamilton_cycle
bool hamilton_cycle(const std::vector< std::vector< bool >> &routes)
Definition: hamiltons_cycle.cpp:30
tests
void tests()
Definition: connected_components.cpp:93
machine_learning::neural_network::NeuralNetwork::NeuralNetwork
NeuralNetwork(const std::vector< std::pair< int, std::string >> &config, const std::vector< std::vector< std::valarray< double >>> &kernals)
Definition: neural_network.cpp:270
data
int data[MAX]
test data
Definition: hash_search.cpp:24
machine_learning::neural_network::layers::DenseLayer::DenseLayer
DenseLayer(DenseLayer &&)=default
linear_probing::add
void add(int key)
Definition: linear_probing_hash_table.cpp:161
machine_learning::neural_network::NeuralNetwork::summary
void summary()
Definition: neural_network.cpp:742
std::vector::emplace_back
T emplace_back(T... args)
std::round
T round(T... args)
spirograph::test
void test()
Test function to save resulting points to a CSV file.
Definition: spirograph.cpp:93
std::remove_reference
queue
Definition: queue.h:17
fit_OLS_regressor
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:321
operator-
std::vector< T > operator-(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:183
std::stod
T stod(T... args)
std::set::lower_bound
T lower_bound(T... args)
std::endl
T endl(T... args)
main
int main()
Definition: armstrong_number.cpp:77
get_inverse
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:226
machine_learning::neural_network::NeuralNetwork::get_XY_from_csv
std::pair< std::vector< std::vector< std::valarray< double > > >, std::vector< std::vector< std::valarray< double > > > > get_XY_from_csv(const std::string &file_name, const bool &last_label, const bool &normalize, const int &slip_lines=1)
Definition: neural_network.cpp:387
double_hashing::searchingProber
bool searchingProber(const Entry &entry, int key)
Definition: double_hash_hash_table.cpp:133
std::left
T left(T... args)
hash_chain::next
std::shared_ptr< struct Node > next
pointer to the next node
Definition: chaining.cpp:23
graph::LowestCommonAncestor
Definition: lowest_common_ancestor.cpp:145
machine_learning::adaline::operator<<
friend std::ostream & operator<<(std::ostream &out, const adaline &ada)
Definition: adaline_learning.cpp:76
std::exp
T exp(T... args)
std::string::begin
T begin(T... args)
std::getline
T getline(T... args)
machine_learning::save_u_matrix
int save_u_matrix(const char *fname, const std::vector< std::vector< std::valarray< double >>> &W)
Definition: kohonen_som_topology.cpp:142
std::greater
machine_learning::get_shape
std::pair< size_t, size_t > get_shape(const std::vector< std::valarray< T >> &A)
Definition: vector_ops.hpp:243
std
STL namespace.
std::set::insert
T insert(T... args)
machine_learning::neural_network::NeuralNetwork::save_model
void save_model(const std::string &_file_name)
Definition: neural_network.cpp:639
machine_learning::MIN_DISTANCE
constexpr double MIN_DISTANCE
Definition: kohonen_som_topology.cpp:129
linear_probing::removalInfo
void removalInfo(int key)
Definition: linear_probing_hash_table.cpp:201
show
void show(const struct tower *const F, const struct tower *const T, const struct tower *const U)
Definition: tower_of_hanoi.cpp:19
graph::Graph::number_of_vertices
int number_of_vertices() const
Definition: lowest_common_ancestor.cpp:73
compare
Definition: huffman.cpp:28
graph::is_graph_bipartite::Graph::Graph
Graph(int size=nax)
Constructor that initializes the graph on creation.
Definition: is_graph_bipartite.cpp:64
stack
Definition: stack.h:26
machine_learning::neural_network::activations::dsigmoid
double dsigmoid(const double &x)
Definition: neural_network.cpp:62
tests
static void tests()
Definition: lowest_common_ancestor.cpp:234
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Definition: kohonen_som_topology.cpp:577
double_hashing::add
void add(int key)
Definition: double_hash_hash_table.cpp:185
double_hashing::doubleHash
int doubleHash(int key, bool searching)
Performs double hashing to resolve collisions.
Definition: double_hash_hash_table.cpp:71
main
int main()
Definition: lowest_common_ancestor.cpp:256
graph
Graph algorithms.
hash_chain::hash_chain
hash_chain(int mod)
Construct a new chain object.
Definition: chaining.cpp:35
std::count
T count(T... args)
vector_ops.hpp
Various functions for vectors associated with NeuralNetwork (aka Multilayer Perceptron).
std::ptrdiff_t
Trie::search
bool search(const std::string &word)
Definition: trie_modern.cpp:132
graph::Graph
Definition: lowest_common_ancestor.cpp:52
machine_learning::neural_network::util_functions::identity_function
double identity_function(const double &x)
Definition: neural_network.cpp:119
std::fixed
T fixed(T... args)
graph::explore
void explore(const std::vector< std::vector< int >> *adj, int u, std::vector< bool > *visited)
Utility function for depth first seach algorithm this function explores the vertex which is passed in...
Definition: connected_components.cpp:59
Item
Definition: knapsack.cpp:4
main
int main()
Definition: linear_probing_hash_table.cpp:224
std::queue::empty
T empty(T... args)
std::vector::assign
T assign(T... args)
stack::display
void display()
Definition: stack.h:29
geometry::jarvis::Point
Definition: jarvis_algorithm.cpp:47
test3
void test3()
Definition: kohonen_som_trace.cpp:414
std::queue::push
T push(T... args)
ols_test
void ols_test()
Definition: ordinary_least_squares_regressor.cpp:369
stack::isEmptyStack
bool isEmptyStack()
Definition: stack.h:80
layers
This namespace contains layers used in MLP.
machine_learning::operator*
std::vector< std::valarray< T > > operator*(const std::vector< std::valarray< T >> &A, const T &val)
Definition: vector_ops.hpp:332
std::stringstream::str
T str(T... args)
machine_learning::neural_network::layers::DenseLayer::DenseLayer
DenseLayer(const DenseLayer &layer)=default
main
int main()
Definition: neural_network.cpp:786
std::make_pair
T make_pair(T... args)
std::time
T time(T... args)
quadratic_probing::hashFxn
size_t hashFxn(int key)
Definition: quadratic_probing_hash_table.cpp:46
std::malloc
T malloc(T... args)
std::set::end
T end(T... args)
quadratic_probing::quadraticProbe
int quadraticProbe(int key, bool searching)
Definition: quadratic_probing_hash_table.cpp:56
stack
char stack[MAX]
Definition: paranthesis_matching.cpp:20
double_hashing::Entry::key
int key
key value
Definition: double_hash_hash_table.cpp:38
geometry::jarvis::Convexhull::orientation
static int orientation(const Point &p, const Point &q, const Point &r)
Definition: jarvis_algorithm.cpp:133
std::setw
T setw(T... args)
machine_learning::adaline::accuracy
const double accuracy
model fit convergence accuracy
Definition: adaline_learning.cpp:208
std::max
T max(T... args)
main
int main()
Definition: dijkstra.cpp:152
machine_learning::neural_network::layers::DenseLayer
Definition: neural_network.cpp:134
test_2d_classes
void test_2d_classes(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:330
graph::RootedTree::root
int root
Index of the root vertex.
Definition: lowest_common_ancestor.cpp:107
std::range_error
STL class.
Point
Definition: line_segment_intersection.cpp:12
graph::is_graph_bipartite::Graph
Class for representing graph as an adjacency list.
Definition: is_graph_bipartite.cpp:49
machine_learning::kohonen_som
void kohonen_som(const std::vector< std::valarray< double >> &X, std::vector< std::vector< std::valarray< double >>> *W, double alpha_min)
Definition: kohonen_som_topology.cpp:269
push
void push(char ch)
push byte to stack variable
Definition: paranthesis_matching.cpp:26
Trie::removeWordHelper
std::shared_ptr< TrieNode > removeWordHelper(const std::string &word, std::shared_ptr< TrieNode > curr, size_t index)
Definition: trie_modern.cpp:64
test_3d_classes2
void test_3d_classes2(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:493
quadratic_probing::searchingProber
bool searchingProber(const Entry &entry, int key)
Definition: quadratic_probing_hash_table.cpp:119
pop
char pop()
pop a byte out of stack variable
Definition: paranthesis_matching.cpp:29
linear_probing::display
void display()
Definition: linear_probing_hash_table.cpp:120
_random
double _random(double a, double b)
Definition: kohonen_som_topology.cpp:53
Graph::addEdge
void addEdge(Edge const &edge)
Definition: cycle_check_directed_graph.cpp:124
spirograph::spirograph
void spirograph(std::array< std::pair< double, double >, N > *points, double l, double k, double rot)
Definition: spirograph.cpp:70
graph::LowestCommonAncestor::lowest_common_ancestor
int lowest_common_ancestor(int u, int v) const
Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...
Definition: lowest_common_ancestor.cpp:164
std::cin
graph::LowestCommonAncestor::up
std::vector< std::vector< int > > up
for every vertex stores a list of its ancestors by powers of two For each vertex, the first element o...
Definition: lowest_common_ancestor.cpp:206
hash_chain::display
void display()
Display the chain.
Definition: chaining.cpp:63
main
int main()
Definition: shortest_common_supersequence.cpp:164
sorting::quickSort
void quickSort(int arr[], int low, int high)
Definition: quick_sort.cpp:63
test2
void test2(double eta=0.01)
Definition: adaline_learning.cpp:262
std::partition
T partition(T... args)
test3
void test3(double eta=0.01)
Definition: adaline_learning.cpp:313
machine_learning::adaline
Definition: adaline_learning.cpp:46
test3
static void test3()
Definition: hamiltons_cycle.cpp:122
std::vector::data
T data(T... args)
machine_learning::zeroes_initialization
void zeroes_initialization(std::vector< std::valarray< T >> &A, const std::pair< size_t, size_t > &shape)
Definition: vector_ops.hpp:209
std::ofstream::is_open
T is_open(T... args)
std::set
STL class.
operator/
std::vector< float > operator/(std::vector< T > const &A, float const scalar)
Definition: ordinary_least_squares_regressor.cpp:174
machine_learning::kohonen_som_tracer
void kohonen_som_tracer(const std::vector< std::valarray< double >> &X, std::vector< std::valarray< double >> *W, double alpha_min)
Definition: kohonen_som_trace.cpp:149
util_functions
Various utility functions used in Neural network.
graph::is_graph_bipartite::Graph::addEdge
void addEdge(int u, int v)
Function that add an edge between two nodes or vertices of graph.
Definition: is_graph_bipartite.cpp:81
std::ifstream::eof
T eof(T... args)
std::exit
T exit(T... args)
stack::clear
void clear()
Definition: stack.h:112
main
int main(int argc, char **argv)
Definition: adaline_learning.cpp:357
list
Definition: list_array.cpp:8
std::ostream::precision
T precision(T... args)
std::hash
test_circle
void test_circle(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:196
main
int main()
Definition: quadratic_probing_hash_table.cpp:246
machine_learning::sum
T sum(const std::vector< std::valarray< T >> &A)
Definition: vector_ops.hpp:228
stack.h
This class specifies the basic operation on a stack as a linked list.
main
int main()
Definition: graph_coloring.cpp:96
std::ifstream
STL class.
std::pow
T pow(T... args)
get_transpose
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:300
machine_learning::neural_network::activations::dtanh
double dtanh(const double &x)
Definition: neural_network.cpp:98
std::chrono::high_resolution_clock::now
T now(T... args)