Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
qr_decompose.h
Go to the documentation of this file.
1 /**
2  * @file
3  * \brief Library functions to compute [QR
4  * decomposition](https://en.wikipedia.org/wiki/QR_decomposition) of a given
5  * matrix.
6  * \author [Krishna Vedala](https://github.com/kvedala)
7  */
8 
9 #ifndef QR_DECOMPOSE_H
10 #define QR_DECOMPOSE_H
11 
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #ifdef _OPENMP
16 #include <omp.h>
17 #endif
18 
19 /**
20  * function to display matrix on stdout
21  */
22 void print_matrix(double **A, /**< matrix to print */
23  int M, /**< number of rows of matrix */
24  int N) /**< number of columns of matrix */
25 {
26  for (int row = 0; row < M; row++)
27  {
28  for (int col = 0; col < N; col++) printf("% 9.3g\t", A[row][col]);
29  putchar('\n');
30  }
31  putchar('\n');
32 }
33 
34 /**
35  * Compute dot product of two vectors of equal lengths
36  *
37  * If \f$\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\f$ and
38  * \f$\vec{b}=\left[b_0,b_1,b_1,...,b_L\right]\f$ then
39  * \f$\vec{a}\cdot\vec{b}=\displaystyle\sum_{i=0}^L a_i\times b_i\f$
40  *
41  * \returns \f$\vec{a}\cdot\vec{b}\f$
42  */
43 double vector_dot(double *a, double *b, int L)
44 {
45  double mag = 0.f;
46  int i;
47 #ifdef _OPENMP
48 // parallelize on threads
49 #pragma omp parallel for reduction(+ : mag)
50 #endif
51  for (i = 0; i < L; i++) mag += a[i] * b[i];
52 
53  return mag;
54 }
55 
56 /**
57  * Compute magnitude of vector.
58  *
59  * If \f$\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\f$ then
60  * \f$\left|\vec{a}\right|=\sqrt{\displaystyle\sum_{i=0}^L a_i^2}\f$
61  *
62  * \returns \f$\left|\vec{a}\right|\f$
63  */
64 double vector_mag(double *vector, int L)
65 {
66  double dot = vector_dot(vector, vector, L);
67  return sqrt(dot);
68 }
69 
70 /**
71  * Compute projection of vector \f$\vec{a}\f$ on \f$\vec{b}\f$ defined as
72  * \f[\text{proj}_\vec{b}\vec{a}=\frac{\vec{a}\cdot\vec{b}}{\left|\vec{b}\right|^2}\vec{b}\f]
73  *
74  * \returns NULL if error, otherwise pointer to output
75  */
76 double *vector_proj(double *a, double *b, double *out, int L)
77 {
78  const double num = vector_dot(a, b, L);
79  const double deno = vector_dot(b, b, L);
80  if (deno == 0) /*! check for division by zero */
81  return NULL;
82 
83  const double scalar = num / deno;
84  int i;
85 #ifdef _OPENMP
86 // parallelize on threads
87 #pragma omp for
88 #endif
89  for (i = 0; i < L; i++) out[i] = scalar * b[i];
90 
91  return out;
92 }
93 
94 /**
95  * Compute vector subtraction
96  *
97  * \f$\vec{c}=\vec{a}-\vec{b}\f$
98  *
99  * \returns pointer to output vector
100  */
101 double *vector_sub(double *a, /**< minuend */
102  double *b, /**< subtrahend */
103  double *out, /**< resultant vector */
104  int L /**< length of vectors */
105 )
106 {
107  int i;
108 #ifdef _OPENMP
109 // parallelize on threads
110 #pragma omp for
111 #endif
112  for (i = 0; i < L; i++) out[i] = a[i] - b[i];
113 
114  return out;
115 }
116 
117 /**
118  * Decompose matrix \f$A\f$ using [Gram-Schmidt
119  *process](https://en.wikipedia.org/wiki/QR_decomposition).
120  *
121  * \f{eqnarray*}{
122  * \text{given that}\quad A &=&
123  *\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\
124  * \text{where}\quad\mathbf{a}_i &=&
125  *\left[a_{0i},a_{1i},a_{2i},\ldots,a_{(M-1)i}\right]^T\quad\ldots\mbox{(column
126  *vectors)}\\
127  * \text{then}\quad\mathbf{u}_i &=& \mathbf{a}_i
128  *-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\
129  * \mathbf{e}_i &=&\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\
130  * Q &=& \begin{bmatrix}\mathbf{e}_0 & \mathbf{e}_1 & \mathbf{e}_2 & \dots &
131  *\mathbf{e}_{N-1}\end{bmatrix}\\
132  * R &=& \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle &
133  *\langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &
134  *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots \\
135  * 0 & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &
136  *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\
137  * 0 & 0 & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\
138  * \vdots & \vdots & \vdots & \ddots
139  * \end{bmatrix}\\
140  * \f}
141  */
142 void qr_decompose(double **A, /**< input matrix to decompose */
143  double **Q, /**< output decomposed matrix */
144  double **R, /**< output decomposed matrix */
145  int M, /**< number of rows of matrix A */
146  int N /**< number of columns of matrix A */
147 )
148 {
149  double *col_vector = (double *)malloc(M * sizeof(double));
150  double *col_vector2 = (double *)malloc(M * sizeof(double));
151  double *tmp_vector = (double *)malloc(M * sizeof(double));
152  for (int i = 0; i < N;
153  i++) /* for each column => R is a square matrix of NxN */
154  {
155  int j;
156 #ifdef _OPENMP
157 // parallelize on threads
158 #pragma omp for
159 #endif
160  for (j = 0; j < i; j++) /* second dimension of column */
161  R[i][j] = 0.; /* make R upper triangular */
162 
163  /* get corresponding Q vector */
164 #ifdef _OPENMP
165 // parallelize on threads
166 #pragma omp for
167 #endif
168  for (j = 0; j < M; j++)
169  {
170  tmp_vector[j] = A[j][i]; /* accumulator for uk */
171  col_vector[j] = A[j][i];
172  }
173  for (j = 0; j < i; j++)
174  {
175  for (int k = 0; k < M; k++) col_vector2[k] = Q[k][j];
176  vector_proj(col_vector, col_vector2, col_vector2, M);
177  vector_sub(tmp_vector, col_vector2, tmp_vector, M);
178  }
179  double mag = vector_mag(tmp_vector, M);
180 
181 #ifdef _OPENMP
182 // parallelize on threads
183 #pragma omp for
184 #endif
185  for (j = 0; j < M; j++) Q[j][i] = tmp_vector[j] / mag;
186 
187  /* compute upper triangular values of R */
188  for (int kk = 0; kk < M; kk++) col_vector[kk] = Q[kk][i];
189  for (int k = i; k < N; k++)
190  {
191  for (int kk = 0; kk < M; kk++) col_vector2[kk] = A[kk][k];
192  R[i][k] = vector_dot(col_vector, col_vector2, M);
193  }
194  }
195 
196  free(col_vector);
197  free(col_vector2);
198  free(tmp_vector);
199 }
200 
201 #endif // QR_DECOMPOSE_H
main
int main(int argc, char *argv[])
Main function.
Definition: collatz.c:16
observation
Definition: k_means_clustering.c:39
_large_num
dynamically large number
Definition: factorial_large_number.c:15
test2
void test2()
Test that creates a random set of points distributed near the locus of the Lamniscate of Gerono and t...
Definition: kohonen_som_trace.c:358
MAX_SIZE
#define MAX_SIZE
maximum number of elements in the set
Definition: union_find.c:8
L
Definition: list.h:8
adaline::weights
double * weights
weights of the neural network
Definition: adaline_learning.c:46
forward_euler_step
void forward_euler_step(const double dx, const double *x, double *y, double *dy)
Compute next step approximation using the forward-Euler method.
Definition: ode_forward_euler.c:82
print
void print(const struct sudoku *a)
Print the matrix to stdout.
Definition: sudoku_solver.c:126
test3
void test3()
Test that creates a random set of points distributed in eight clusters in 3D space and trains an SOM ...
Definition: kohonen_som_topology.c:609
test
void test()
Test function.
Definition: decimal_to_binary_recursion.c:20
exact_solution
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_midpoint_euler.c:67
test_adler32
void test_adler32()
Test function for adler32.
Definition: hash_adler32.c:38
_cantor_set::next
struct _cantor_set * next
pointer to next set
Definition: cantor_set.c:15
observation::group
int group
the group no in which this observation would go
Definition: k_means_clustering.c:42
sudoku::N2
uint8_t N2
block of elements
Definition: sudoku_solver.c:36
main
int main(int argc, char const *argv[])
Main function.
Definition: cantor_set.c:84
compare
int compare(const void *a, const void *b)
comparison function for use with internal qsort algorithm
Definition: sol1.c:19
main
int main(int argc, char **argv)
Main function.
Definition: lu_decompose.c:79
main
int main(int argc, char *argv[])
Main Function.
Definition: ode_semi_implicit_euler.c:147
propagate
void propagate(CantorSet *head)
Iterative constructor of all sets in the current level.
Definition: cantor_set.c:23
vector_mag
double vector_mag(double *vector, int L)
Compute magnitude of vector.
Definition: qr_decompose.h:64
kMeans
cluster * kMeans(observation observations[], size_t size, int k)
Definition: k_means_clustering.c:134
adaline_fit
void adaline_fit(struct adaline *ada, double **X, const int *y, const int N)
Update the weights of the model using supervised learning for an array of vectors.
Definition: adaline_learning.c:184
join
void join(int *p, int x, int y)
Function to join.
Definition: union_find.c:42
test_circle
void test_circle(double *const *data, int N)
Creates a random set of points distributed near the circumference of a circle and trains an SOM that ...
Definition: kohonen_som_trace.c:223
forward_euler
double forward_euler(double dx, double x0, double x_max, double *y, char save_to_file)
Compute approximation using the forward-Euler method in the given limits.
Definition: ode_forward_euler.c:99
data
Definition: prime_factoriziation.c:25
pid
PID Controller.
Definition: pid.c:31
adaline_activation
int adaline_activation(double x)
Heaviside activation function
Definition: adaline_learning.c:105
calculateNearst
int calculateNearst(observation *o, cluster clusters[], int k)
Definition: k_means_clustering.c:69
d_func
double complex d_func(double complex x)
Return first order derivative of the function.
Definition: newton_raphson_root.c:32
CantorSet
struct _cantor_set CantorSet
structure to define Cantor set
main
int main(int argc, char **argv)
Main function.
Definition: kohonen_som_topology.c:669
main
int main(int argc, char **argv)
Main function.
Definition: adaline_learning.c:398
kohonen_array_3d::data
double * data
pointer to data
Definition: kohonen_som_topology.c:52
test_3d_classes1
void test_3d_classes1(double *const *data, int N)
Creates a random set of points distributed in four clusters in 3D space with centroids at the points.
Definition: kohonen_som_topology.c:465
save_2d_data
int save_2d_data(const char *fname, double **X, int num_points, int num_features)
Save a given n-dimensional data martix to file.
Definition: kohonen_som_topology.c:102
BSTIterator
Definition for a binary tree node.
Definition: 173.c:13
_random
double _random(double a, double b)
Helper function to generate a random number in a given interval.
Definition: kohonen_som_topology.c:87
node
Node, the basic data structure in the tree.
Definition: binary_search_tree.c:15
vector_proj
double * vector_proj(double *a, double *b, double *out, int L)
Compute projection of vector on defined as.
Definition: qr_decompose.h:76
free_memory
void free_memory(CantorSet *head)
Clear memory allocated by propagate function.
Definition: cantor_set.c:72
main
int main()
Definition: k_means_clustering.c:384
_large_num::num_digits
unsigned int num_digits
number of digits in the number
Definition: factorial_large_number.c:17
test3
void test3()
Test that creates a random set of points distributed in six clusters in 3D space.
Definition: kohonen_som_trace.c:462
calculateCentroid
void calculateCentroid(observation observations[], size_t size, cluster *centroid)
Definition: k_means_clustering.c:97
save_nd_data
int save_nd_data(const char *fname, double **X, int num_points, int num_features)
Save a given n-dimensional data martix to file.
Definition: kohonen_som_trace.c:70
kohonen_array_3d::dim2
int dim2
lengths of second dimension
Definition: kohonen_som_topology.c:50
test_3d_classes2
void test_3d_classes2(double *const *data, int N)
Creates a random set of points distributed in four clusters in 3D space with centroids at the points.
Definition: kohonen_som_topology.c:564
kohonen_array_3d::dim3
int dim3
lengths of thirddimension
Definition: kohonen_som_topology.c:51
observation::x
double x
abscissa of 2D data point
Definition: k_means_clustering.c:40
sudoku::N
uint8_t N
number of elements
Definition: sudoku_solver.c:35
qr_decompose
void qr_decompose(double **A, double **Q, double **R, int M, int N)
Decompose matrix using Gram-Schmidt process.
Definition: qr_decompose.h:142
complex_str
const char * complex_str(long double complex x)
create a textual form of complex number
Definition: durand_kerner_roots.c:66
T
Definition: stack.c:16
main
int main()
Main function.
Definition: cartesian_to_polar.c:118
main
int main(int argc, char *argv[])
main function
Definition: fibonacci_fast.c:65
large_num
struct _large_num large_num
dynamically large number
newNode
node * newNode(int data)
The node constructor, which receives the key value input and returns a node pointer.
Definition: binary_search_tree.c:28
new_number
large_num * new_number(void)
create a new large number
Definition: factorial_large_number.c:24
cluster
Definition: k_means_clustering.c:53
check_termination
char check_termination(long double delta)
check for termination condition
Definition: durand_kerner_roots.c:83
semi_implicit_euler
double semi_implicit_euler(double dx, double x0, double x_max, double *y, char save_to_file)
Compute approximation using the semi-implicit-Euler method in the given limits.
Definition: ode_semi_implicit_euler.c:109
isPalindrome
bool isPalindrome(int number)
Check given number whether is palindrome number or not.
Definition: palindrome.c:29
xor8
uint8_t xor8(const char *s)
8-bit XOR algorithm implementation
Definition: hash_xor8.c:19
poly_function
long double complex poly_function(long double *coeffs, unsigned int degree, long double complex x)
Evaluate the value of a polynomial with given coefficients.
Definition: durand_kerner_roots.c:50
main
int main()
Main function.
Definition: union_find.c:45
main
int main(int argc, char *argv[])
main function
Definition: factorial_large_number.c:94
test2
void test2()
Definition: k_means_clustering.c:356
ADALINE_ACCURACY
#define ADALINE_ACCURACY
convergence accuracy
Definition: adaline_learning.c:51
multiply
void multiply(large_num *num, unsigned long n)
multiply large number with another integer and store the result in the same large number
Definition: factorial_large_number.c:66
cluster::y
double y
ordinate of centroid of this cluster
Definition: k_means_clustering.c:55
kohonen_update_weights
void kohonen_update_weights(double const *x, double *const *W, double *D, int num_out, int num_features, double alpha, int R)
Update weights of the SOM using Kohonen algorithm.
Definition: kohonen_som_trace.c:129
test_lamniscate
void test_lamniscate(double *const *data, int N)
Creates a random set of points distributed near the locus of the Lamniscate of Gerono.
Definition: kohonen_som_trace.c:319
djb2
uint64_t djb2(const char *s)
DJB2 algorithm implementation.
Definition: hash_djb2.c:18
lcm
unsigned long lcm(unsigned long a, unsigned long b)
Compute Least Common Multiple (LCM) of two numbers.
Definition: sol.c:31
get_next_unknown
bool get_next_unknown(const struct sudoku *a, int *x, int *y)
Find and get the location for next empty cell.
Definition: sudoku_solver.c:144
cluster::count
size_t count
count of observations present in this cluster
Definition: k_means_clustering.c:56
crc32
uint32_t crc32(const char *s)
32-bit CRC algorithm implementation
Definition: hash_crc32.c:20
main
int main()
Driver code.
Definition: client.c:70
swap
void swap(int *first, int *second)
Swap two values by using pointer.
Definition: bubble_sort.c:31
spirograph
void spirograph(double *x, double *y, double l, double k, size_t N, double rot)
Generate spirograph curve into arrays x and y such that the i^th point in 2D is represented by (x[i],...
Definition: spirograph.c:57
midpoint_euler_step
void midpoint_euler_step(double dx, double *x, double *y, double *dy)
Compute next step approximation using the midpoint-Euler method.
Definition: ode_midpoint_euler.c:83
main
int main(int argc, char **argv)
main function
Definition: newton_raphson_root.c:37
main
int main(int argc, char **argv)
Main function.
Definition: kohonen_som_trace.c:517
fib
void fib(unsigned long n, unsigned long *C, unsigned long *D)
Get the and Fibonacci number using recursive half-interval decimation.
Definition: fibonacci_fast.c:23
solve
bool solve(struct sudoku *a)
Function to solve a partially filled sudoku matrix.
Definition: sudoku_solver.c:172
_cantor_set::start
double start
start of interval
Definition: cantor_set.c:13
_cantor_set::end
double end
end of interval
Definition: cantor_set.c:14
test_crc32
void test_crc32()
Test function for crc32.
Definition: hash_crc32.c:42
test_djb2
void test_djb2(void)
Test function for djb2.
Definition: hash_djb2.c:34
adaline_fit_sample
double adaline_fit_sample(struct adaline *ada, const double *x, const int y)
Update the weights of the model using supervised learning for one feature vector.
Definition: adaline_learning.c:158
OKrow
bool OKrow(const struct sudoku *a, int x, int y, int v)
Check if x^th row is valid.
Definition: sudoku_solver.c:48
print_matrix
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition: qr_decompose.h:22
vector_dot
double vector_dot(double *a, double *b, int L)
Compute dot product of two vectors of equal lengths.
Definition: qr_decompose.h:43
adaline::eta
double eta
learning rate of the algorithm
Definition: adaline_learning.c:45
main
int main()
Main function.
Definition: hash_xor8.c:47
exact_solution
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_semi_implicit_euler.c:71
OKcol
bool OKcol(const struct sudoku *a, int x, int y, int v)
Check if y^th column is valid.
Definition: sudoku_solver.c:67
main
int main()
Main function.
Definition: hash_adler32.c:50
main
int main(int argc, char *argv[])
Main Function.
Definition: ode_midpoint_euler.c:144
cluster::x
double x
abscissa centroid of this cluster
Definition: k_means_clustering.c:54
delete_adaline
void delete_adaline(struct adaline *ada)
delete dynamically allocated memory
Definition: adaline_learning.c:89
kohonen_som_tracer
void kohonen_som_tracer(double **X, double *const *W, int num_samples, int num_features, int num_out, double alpha_min)
Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given...
Definition: kohonen_som_trace.c:179
test2
void test2()
Test that creates a random set of points distributed in 4 clusters in 3D space and trains an SOM that...
Definition: kohonen_som_topology.c:506
find
int find(int *p, int x)
Find index of or value in an array.
Definition: union_find.c:17
problem
void problem(const double *x, double *y, double *dy)
Problem statement for a system with first-order differential equations.
Definition: ode_forward_euler.c:55
problem
void problem(const double *x, double *y, double *dy)
Problem statement for a system with first-order differential equations.
Definition: ode_semi_implicit_euler.c:58
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Convert clock cycle difference to time in seconds.
Definition: kohonen_som_trace.c:511
min
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_trace.c:36
order
#define order
number of dependent variables in problem
Definition: ode_semi_implicit_euler.c:47
get_min_2d
void get_min_2d(double **X, int N, double *val, int *x_idx, int *y_idx)
Get minimum value and index of the value in a matrix.
Definition: kohonen_som_topology.c:204
MAX_LEN
#define MAX_LEN
length of resulting recurring fraction number
Definition: sol1.c:15
to_polar
void to_polar(double x, double y, double *r, double *theta)
Function to convert cartesian coordinates to polar.
Definition: cartesian_to_polar.c:22
search
void search(node *root, int ele)
searches for the element
Definition: threaded_binary_trees.c:98
test
void test(void)
Test function to save resulting points to a CSV file.
Definition: spirograph.c:74
max
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_trace.c:32
OKbox
bool OKbox(const struct sudoku *a, int x, int y, int v)
Check if a 3x3 box is valid.
Definition: sudoku_solver.c:85
gcd
unsigned long gcd(unsigned long a, unsigned long b)
Compute Greatest Common Divisor (GCD) of two numbers using Euclids algorithm.
Definition: sol.c:11
test_sdbm
void test_sdbm()
Test function for sdbm.
Definition: hash_sdbm.c:34
MAX_ADALINE_ITER
#define MAX_ADALINE_ITER
Maximum number of iterations to learn.
Definition: adaline_learning.c:40
delete_number
void delete_number(large_num *num)
delete all memory allocated for large number
Definition: factorial_large_number.c:37
lu_decomposition
int lu_decomposition(double **A, double **L, double **U, int mat_size)
Perform LU decomposition on matrix.
Definition: lu_decompose.c:20
kohonen_array_3d
to store info regarding 3D arrays
Definition: kohonen_som_topology.c:48
MAX
#define MAX
max.
Definition: client.c:28
min
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_topology.c:43
vector_sub
double * vector_sub(double *a, double *b, double *out, int L)
Compute vector subtraction.
Definition: qr_decompose.h:101
kohonen_som
void kohonen_som(double **X, struct kohonen_array_3d *W, int num_samples, int num_features, int num_out, double alpha_min)
Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given...
Definition: kohonen_som_topology.c:314
main
int main(int argc, char **argv)
Definition: durand_kerner_roots.c:95
max
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
main
int main()
Main function.
Definition: hash_djb2.c:46
test3
void test3(double eta)
test function to predict points in a 3D coordinate system lying within the sphere of radius 1 and cen...
Definition: adaline_learning.c:336
display
void display(double **A, int N)
Function to display square matrix.
Definition: lu_decompose.c:66
OK
bool OK(const struct sudoku *a, int x, int y, int v)
Check if element v is valid to place at (x,y) location.
Definition: sudoku_solver.c:111
order
#define order
number of dependent variables in problem
Definition: ode_midpoint_euler.c:43
exact_solution
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_forward_euler.c:68
test_xor8
void test_xor8()
Test function for xor8.
Definition: hash_xor8.c:35
test1
void test1()
Test that creates a random set of points distributed near the circumference of a circle and trains an...
Definition: kohonen_som_trace.c:261
main
int main(int argc, char *argv[])
Main Function.
Definition: ode_forward_euler.c:137
main
int main(int argc, char **argv)
Main function.
Definition: spirograph.c:271
_random
double _random(double a, double b)
Helper function to generate a random number in a given interval.
Definition: kohonen_som_trace.c:54
kohonen_array_3d::dim1
int dim1
lengths of first dimension
Definition: kohonen_som_topology.c:49
func
double complex func(double complex x)
Return value of the function to find the root for.
Definition: newton_raphson_root.c:22
sudoku::a
uint8_t * a
matrix as a flattened 1D row-major array
Definition: sudoku_solver.c:34
node::left
struct node * left
left child
Definition: binary_search_tree.c:16
sdbm
uint64_t sdbm(const char *s)
SDBM algorithm implementation.
Definition: hash_sdbm.c:18
test1
void test1(double eta)
test function to predict points in a 2D coordinate system above the line as +1 and others as -1.
Definition: adaline_learning.c:225
printEPS
void printEPS(observation pts[], size_t len, cluster cent[], int k)
Definition: k_means_clustering.c:237
test2
void test2(double eta)
test function to predict points in a 2D coordinate system above the line as +1 and others as -1.
Definition: adaline_learning.c:273
ACCURACY
#define ACCURACY
maximum accuracy limit
Definition: durand_kerner_roots.c:41
sudoku
Structure to hold the matrix and dimensions.
Definition: sudoku_solver.c:33
midpoint_euler
double midpoint_euler(double dx, double x0, double x_max, double *y, char save_to_file)
Compute approximation using the midpoint-Euler method in the given limits.
Definition: ode_midpoint_euler.c:106
kohonen_update_weights
double kohonen_update_weights(const double *X, struct kohonen_array_3d *W, double **D, int num_out, int num_features, double alpha, int R)
Update weights of the SOM using Kohonen algorithm.
Definition: kohonen_som_topology.c:234
node
struct node node
Node, the basic data structure in the tree.
ACCURACY
#define ACCURACY
solution accuracy
Definition: newton_raphson_root.c:16
test_3d_classes
void test_3d_classes(double *const *data, int N)
Creates a random set of points distributed in four clusters in 3D space with centroids at the points.
Definition: kohonen_som_trace.c:410
test
void test()
Test implementation.
Definition: cartesian_to_polar.c:98
adler32
uint32_t adler32(const char *s)
32-bit Adler algorithm implementation
Definition: hash_adler32.c:18
test
static void test()
Definition: k_means_clustering.c:321
adaline_predict
int adaline_predict(struct adaline *ada, const double *x, double *out)
predict the output of the model for given set of features
Definition: adaline_learning.c:136
main
int main()
Driver Code.
Definition: palindrome.c:14
main
int main()
Main function.
Definition: hash_crc32.c:58
adaline
structure to hold adaline model parameters
Definition: adaline_learning.c:44
get_rand
double get_rand(double lim1, double lim2)
Generate a random number in the given limits.
Definition: cartesian_to_polar.c:88
height
int height(node *root)
Utilitary procedure to measure the height of the binary tree.
Definition: binary_search_tree.c:187
save_u_matrix
int save_u_matrix(const char *fname, struct kohonen_array_3d *W)
Create the distance matrix or U-matrix from the trained weights and save to disk.
Definition: kohonen_som_topology.c:139
semi_implicit_euler_step
void semi_implicit_euler_step(double dx, double *x, double *y, double *dy)
Compute next step approximation using the semi-implicit-Euler method.
Definition: ode_semi_implicit_euler.c:85
node::right
struct node * right
right child
Definition: binary_search_tree.c:17
test1
void test1()
Test that creates a random set of points distributed in four clusters in 2D space and trains an SOM t...
Definition: kohonen_som_topology.c:406
_cantor_set
structure to define Cantor set
Definition: cantor_set.c:12
observation::y
double y
ordinate of 2D data point
Definition: k_means_clustering.c:41
_large_num::digits
char * digits
array to store individual digits
Definition: factorial_large_number.c:16
adaline_get_weights_str
char * adaline_get_weights_str(const struct adaline *ada)
Operator to print the weights of the model.
Definition: adaline_learning.c:112
kohonen_data_3d
double * kohonen_data_3d(const struct kohonen_array_3d *arr, int x, int y, int z)
Function that returns the pointer to (x, y, z) ^th location in the linear 3D array given by:
Definition: kohonen_som_topology.c:67
main
int main()
Main function.
Definition: sudoku_solver.c:246
main
int main()
Main function.
Definition: hash_sdbm.c:46
kohonen_get_min_1d
void kohonen_get_min_1d(double const *X, int N, double *val, int *idx)
Get minimum value and index of the value in a vector.
Definition: kohonen_som_trace.c:104
problem
void problem(const double *x, double *y, double *dy)
Problem statement for a system with first-order differential equations.
Definition: ode_midpoint_euler.c:54
new_adaline
struct adaline new_adaline(const int num_features, const double eta)
Default constructor.
Definition: adaline_learning.c:59
print
void print(CantorSet *head)
Print sets in the current range to stdout
Definition: cantor_set.c:55
order
#define order
number of dependent variables in problem
Definition: ode_forward_euler.c:44
adaline::num_weights
int num_weights
number of weights of the neural network
Definition: adaline_learning.c:47
add_digit
void add_digit(large_num *num, unsigned int value)
add a digit to the large number
Definition: factorial_large_number.c:48
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Convert clock cycle difference to time in seconds.
Definition: kohonen_som_topology.c:663
test_2d_classes
void test_2d_classes(double *const *data, int N)
Creates a random set of points distributed in four clusters in 3D space with centroids at the points.
Definition: kohonen_som_topology.c:366