Algorithms_in_C
1.0.0
Set of algorithms implemented in C.
|
Go to the documentation of this file.
10 #define QR_DECOMPOSE_H
26 for (
int row = 0; row < M; row++)
28 for (
int col = 0; col <
N; col++) printf(
"% 9.3g\t", A[row][col]);
49 #pragma omp parallel for reduction(+ : mag)
51 for (i = 0; i <
L; i++) mag += a[i] * b[i];
83 const double scalar = num / deno;
89 for (i = 0; i <
L; i++) out[i] = scalar * b[i];
112 for (i = 0; i <
L; i++) out[i] = a[i] - b[i];
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;
160 for (j = 0; j < i; j++)
168 for (j = 0; j < M; j++)
170 tmp_vector[j] = A[j][i];
171 col_vector[j] = A[j][i];
173 for (j = 0; j < i; j++)
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);
185 for (j = 0; j < M; j++) Q[j][i] = tmp_vector[j] / mag;
188 for (
int kk = 0; kk < M; kk++) col_vector[kk] = Q[kk][i];
189 for (
int k = i; k <
N; k++)
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);
201 #endif // QR_DECOMPOSE_H
int main(int argc, char *argv[])
Main function.
Definition: collatz.c:16
dynamically large number
Definition: factorial_large_number.c:15
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:347
#define MAX_ITER
Maximum number of iterations to learn.
Definition: adaline_learning.c:34
char * get_weights_str(struct adaline *ada)
Operator to print the weights of the model.
Definition: adaline_learning.c:100
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:64
double * weights
weights of the neural network
Definition: adaline_learning.c:40
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
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_trace.c:26
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:596
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_midpoint_euler.c:67
struct _cantor_set * next
pointer to next set
Definition: cantor_set.c:15
int main(int argc, char const *argv[])
Main function.
Definition: cantor_set.c:84
int compare(const void *a, const void *b)
comparison function for use with internal qsort algorithm
Definition: sol1.c:19
int main(int argc, char **argv)
Main function.
Definition: lu_decompose.c:79
int main(int argc, char *argv[])
Main Function.
Definition: ode_semi_implicit_euler.c:147
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_topology.c:36
void propagate(CantorSet *head)
Iterative constructor of all sets in the current level.
Definition: cantor_set.c:23
double vector_mag(double *vector, int L)
Compute magnitude of vector.
Definition: qr_decompose.h:64
void delete_adaline(struct adaline *ada)
delete dynamically allocated memory
Definition: adaline_learning.c:82
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:212
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
double update_weights(const double *X, struct 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:227
double * data
pointer to data
Definition: kohonen_som_topology.c:45
Definition: prime_factoriziation.c:25
PID Controller.
Definition: pid.c:31
double complex d_func(double complex x)
Return first order derivative of the function.
Definition: newton_raphson_root.c:32
struct _cantor_set CantorSet
structure to define Cantor set
int main(int argc, char **argv)
Main function.
Definition: kohonen_som_topology.c:656
int main(int argc, char **argv)
Main function.
Definition: adaline_learning.c:379
double * data_3d(const struct 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:60
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:173
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:452
void 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:123
Definition for a binary tree node.
Definition: 173.c:13
Kyler Smith, 2017 Stack data structure implementation.
Definition: binary_search_tree.c:14
double * vector_proj(double *a, double *b, double *out, int L)
Compute projection of vector on defined as.
Definition: qr_decompose.h:76
void free_memory(CantorSet *head)
Clear memory allocated by propagate function.
Definition: cantor_set.c:72
unsigned int num_digits
number of digits in the number
Definition: factorial_large_number.c:17
void test3()
Test that creates a random set of points distributed in six clusters in 3D space.
Definition: kohonen_som_trace.c:451
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:551
#define N
number of digits of the large number
Definition: sol1.c:109
void 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:98
void qr_decompose(double **A, double **Q, double **R, int M, int N)
Decompose matrix using Gram-Schmidt process.
Definition: qr_decompose.h:142
const char * complex_str(long double complex x)
create a textual form of complex number
Definition: durand_kerner_roots.c:66
int main(int argc, char *argv[])
main function
Definition: fibonacci_fast.c:61
struct _large_num large_num
dynamically large number
int save_u_matrix(const char *fname, struct array_3d *W)
Create the distance matrix or U-matrix from the trained weights and save to disk.
Definition: kohonen_som_topology.c:132
large_num * new_number(void)
create a new large number
Definition: factorial_large_number.c:24
char check_termination(long double delta)
check for termination condition
Definition: durand_kerner_roots.c:83
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
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
int main(int argc, char *argv[])
main function
Definition: factorial_large_number.c:94
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
double _random(double a, double b)
Helper function to generate a random number in a given interval.
Definition: kohonen_som_trace.c:48
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:308
unsigned long lcm(unsigned long a, unsigned long b)
Compute Least Common Multiple (LCM) of two numbers.
Definition: sol.c:31
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
int main(int argc, char **argv)
main function
Definition: newton_raphson_root.c:37
int main(int argc, char **argv)
Main function.
Definition: kohonen_som_trace.c:506
void fib(unsigned long n, unsigned long *C, unsigned long *D)
Returns the and Fibonacci number.
Definition: fibonacci_fast.c:20
double start
start of interval
Definition: cantor_set.c:13
double end
end of interval
Definition: cantor_set.c:14
void print_matrix(double **A, int M, int N)
function to display matrix on stdout
Definition: qr_decompose.h:22
double vector_dot(double *a, double *b, int L)
Compute dot product of two vectors of equal lengths.
Definition: qr_decompose.h:43
double eta
learning rate of the algorithm
Definition: adaline_learning.c:39
int dim3
lengths of thirddimension
Definition: kohonen_som_topology.c:44
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_semi_implicit_euler.c:71
int main(int argc, char *argv[])
Main Function.
Definition: ode_midpoint_euler.c:144
int dim1
lengths of first dimension
Definition: kohonen_som_topology.c:42
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:493
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
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:197
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
double _random(double a, double b)
Helper function to generate a random number in a given interval.
Definition: kohonen_som_topology.c:80
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:500
#define order
number of dependent variables in problem
Definition: ode_semi_implicit_euler.c:47
#define MAX_LEN
length of resulting recurring fraction number
Definition: sol1.c:15
struct Node node
Node, the basic data structure of the tree.
void search(node *root, int ele)
searches for the element
Definition: threaded_binary_trees.c:98
unsigned long gcd(unsigned long a, unsigned long b)
Compute Greatest Common Divisor (GCD) of two numbers using Euclids algorithm.
Definition: sol.c:11
int predict(struct adaline *ada, const double *x, double *out)
predict the output of the model for given set of features
Definition: adaline_learning.c:124
void delete_number(large_num *num)
delete all memory allocated for large number
Definition: factorial_large_number.c:37
int lu_decomposition(double **A, double **L, double **U, int mat_size)
Perform LU decomposition on matrix.
Definition: lu_decompose.c:20
to store info regarding 3D arrays
Definition: kohonen_som_topology.c:41
struct adaline new_adaline(const int num_features, const double eta)
Default constructor.
Definition: adaline_learning.c:52
double * vector_sub(double *a, double *b, double *out, int L)
Compute vector subtraction.
Definition: qr_decompose.h:101
int main(int argc, char **argv)
Definition: durand_kerner_roots.c:95
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:317
int main(int argc, char **argv)
the main function take one argument of type char* example : .
Definition: c_atoi_str_to_integer.c:72
void display(double **A, int N)
Function to display square matrix.
Definition: lu_decompose.c:66
#define order
number of dependent variables in problem
Definition: ode_midpoint_euler.c:43
void exact_solution(const double *x, double *y)
Exact solution of the problem.
Definition: ode_forward_euler.c:68
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:250
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_trace.c:30
int main(int argc, char *argv[])
Main Function.
Definition: ode_forward_euler.c:137
double 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:145
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:95
double complex func(double complex x)
Return value of the function to find the root for.
Definition: newton_raphson_root.c:22
int activation(double x)
Heaviside activation function
Definition: adaline_learning.c:95
void test()
Test implementations.
Definition: binary_search.c:75
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:206
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:254
#define ACCURACY
maximum accuracy limit
Definition: durand_kerner_roots.c:41
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
#define ACCURACY
solution accuracy
Definition: newton_raphson_root.c:16
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:399
void swap(int *a, int *b)
Function to swap values of two integers.
Definition: shell_sort2.c:19
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:32
void 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:171
structure to hold adaline model parameters
Definition: adaline_learning.c:38
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
#define ACCURACY
convergence accuracy
Definition: adaline_learning.c:44
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:393
int dim2
lengths of second dimension
Definition: kohonen_som_topology.c:43
structure to define Cantor set
Definition: cantor_set.c:12
char * digits
array to store individual digits
Definition: factorial_large_number.c:16
void kohonen_som(double **X, struct 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:306
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
void print(CantorSet *head)
Print sets in the current range to stdout
Definition: cantor_set.c:55
#define order
number of dependent variables in problem
Definition: ode_forward_euler.c:44
int num_weights
number of weights of the neural network
Definition: adaline_learning.c:41
void add_digit(large_num *num, unsigned int value)
add a digit to the large number
Definition: factorial_large_number.c:48
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:650
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:353