diff --git a/COPYING b/LICENSE similarity index 100% rename from COPYING rename to LICENSE diff --git a/Makefile b/Makefile index 307763b..8c1bb62 100644 --- a/Makefile +++ b/Makefile @@ -2,23 +2,23 @@ default: all all: cd code; cc -ggdb -Wall -shared -fPIC -c *.c - cd test; cc -ggdb -Wall -lm matrix.c -o matrix \ + cd test; cc -ggdb -Wall matrix.c -o matrix \ ../code/matrix.o \ ../code/clann.o \ - ../code/reader.o - cd test; cc -ggdb -Wall -lm fft.c -o fft \ + ../code/reader.o -lm + cd test; cc -ggdb -Wall fft.c -o fft \ ../code/fft.o \ ../code/matrix.o \ ../code/clann.o \ ../code/statistic.o \ - ../code/reader.o - cd test; cc -ggdb -Wall -lm lms.c -o lms \ + ../code/reader.o -lm + cd test; cc -ggdb -Wall lms.c -o lms \ ../code/matrix.o \ ../code/clann.o \ ../code/function.o \ ../code/lms.o \ - ../code/neuron.o - cd test; cc -ggdb -Wall -lm rbf.c -o rbf \ + ../code/neuron.o -lm + cd test; cc -ggdb -Wall rbf.c -o rbf \ ../code/rbf.o \ ../code/kmeans.o \ ../code/matrix.o \ @@ -27,15 +27,15 @@ all: ../code/function.o \ ../code/clann.o \ ../code/lms.o \ - ../code/reader.o - cd test; cc -ggdb -Wall -lm svm.c -o svm \ + ../code/reader.o -lm + cd test; cc -ggdb -Wall svm.c -o svm \ ../code/svm.o \ ../code/ilpso.o \ ../code/matrix.o \ ../code/neuron.o \ ../code/function.o \ ../code/clann.o \ - ../code/reader.o + ../code/reader.o -lm cd test; cc -Wall som.c -lpthread -lglut -o som \ ../code/clann.o \ ../code/som.o \ @@ -53,6 +53,6 @@ clean: rbf \ svm \ som - cd bind; rm -rf clann/*.so \ + cd bind; rm -rf clann/*.so clann/*.pyc \ rm -rf build/ diff --git a/README b/README index 08ff907..ab80e34 100644 --- a/README +++ b/README @@ -3,11 +3,11 @@ INTRODUCTION CLANN stands for `C library for Learning Appliance and Neural Networks'. Its was developed in a mastering engineering course of Artificial Neural -Networks at the Federal University of Rio Grande do Norte (UFRN) [0]. In this +Networks at the Federal University of Rio Grande do Norte (UFRN). In this course we have a very extensive and intensive teaching in both supervised and non-supervised learning techniques. The choice of C language was made based on -its fastness, portability and embeddable capabilities. Mode information about -CLANN could be find on its site [1] and repository [2]. +its fastness, portability and embeddable capabilities. More information about +CLANN could be find on its repository [0]. BUILD @@ -24,12 +24,10 @@ CONTACT If you have any question about CLANN, send an e-mail to the contact below. -Joao Paulo de Souza Medeiros +Joao Paulo de Souza Medeiros REFERENCES ========== -[0] http://www.ufrn.br/ -[1] http://labepi.cerescaico.ufrn.br/~jpsm/clann/ -[2] http://labepi.cerescaico.ufrn.br/redmine/projects/clann/ +[0] https://github.com/jpzm/clann/ diff --git a/bind/clann/__init__.py b/bind/clann/__init__.py index 89bc69d..7195f45 100644 --- a/bind/clann/__init__.py +++ b/bind/clann/__init__.py @@ -1,6 +1,6 @@ -# Copyright (C) 2009 Adriano Monteiro Marques +# Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros # -# Author: Joao Paulo de Souza Medeiros +# Author(s): Joao Paulo de Souza Medeiros # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/bind/clann/matrix.py b/bind/clann/matrix.py index 27fff1e..0ea3369 100644 --- a/bind/clann/matrix.py +++ b/bind/clann/matrix.py @@ -1,6 +1,6 @@ -# Copyright (C) 2009 Adriano Monteiro Marques +# Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros # -# Author: Joao Paulo de Souza Medeiros +# Author(s): Joao Paulo de Souza Medeiros # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,24 +21,25 @@ import clann.matrix + class Matrix(object): """ """ def __init__(self, rows=0, cols=0, fill=0): """ """ - self.matrix = clann.matrix.new(rows, cols) - clann.matrix.fill(self.matrix, fill) + self.__matrix = clann.matrix.new(rows, cols) + clann.matrix.fill(self.__matrix, fill) def __nonzero__(self): """ """ - return clann.matrix.isnull(self.matrix) + return clann.matrix.isnull(self.__matrix) def __len__(self): """ """ - return sum(clann.matrix.size(self.matrix)) + return sum(clann.matrix.size(self.__matrix)) def __getitem__(self, key): """ @@ -47,7 +48,7 @@ def __getitem__(self, key): raise IndexError, "invalid index size" i, j = key - return clann.matrix.get(self.matrix, i, j) + return clann.matrix.get(self.__matrix, i, j) def __setitem__(self, key, value): """ @@ -56,28 +57,28 @@ def __setitem__(self, key, value): raise IndexError, "invalid index size" i, j = key - return clann.matrix.set(self.matrix, i, j, value) + return clann.matrix.set(self.__matrix, i, j, value) def __add__(self, m): """ """ n = Matrix() - n.matrix = clann.matrix.add(self.matrix, m.matrix) - + n.matrix = clann.matrix.add(self.__matrix, m.matrix) + return n def __sub__(self, m): """ """ n = Matrix() - n.matrix = clann.matrix.subtract(self.matrix, m.matrix) - + n.matrix = clann.matrix.subtract(self.__matrix, m.matrix) + return n def __mul__(self, m): """ """ n = Matrix() - n.matrix = clann.matrix.product(self.matrix, m.matrix) - + n.matrix = clann.matrix.product(self.__matrix, m.matrix) + return n diff --git a/bind/matrix.c b/bind/matrix.c index 79e48e7..936a0e8 100644 --- a/bind/matrix.c +++ b/bind/matrix.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/bind/matrix.h b/bind/matrix.h index 98d4072..b749cc6 100644 --- a/bind/matrix.h +++ b/bind/matrix.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -119,8 +119,7 @@ inverse(PyObject *self, PyObject *args); /** * */ -static char pseudo_inverse__doc__[] = "Create a pseudo inverse for a given \ -matrix"; +static char pseudo_inverse__doc__[] = "Compute the pseudo inverse of a matrix"; static PyObject* pseudo_inverse(PyObject *self, PyObject *args); diff --git a/bind/metric.c b/bind/metric.c index 3ca5ec7..e66d07b 100644 --- a/bind/metric.c +++ b/bind/metric.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/bind/metric.h b/bind/metric.h index 1860e21..651de71 100644 --- a/bind/metric.h +++ b/bind/metric.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/bind/setup.py b/bind/setup.py index 8b032a8..07ace27 100644 --- a/bind/setup.py +++ b/bind/setup.py @@ -1,6 +1,6 @@ -# Copyright (C) 2009 Adriano Monteiro Marques +# Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros # -# Author: Joao Paulo de Souza Medeiros +# Author(s): Joao Paulo de Souza Medeiros # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,8 @@ metric_module = Extension('metric', include_dirs = ['../'], extra_objects = ['../code/metric.o', - '../code/matrix.o'], + '../code/matrix.o', + '../code/clann.o'], extra_compile_args = ['-Wall', '-ggdb'], sources = ['metric.c']) diff --git a/code/backprop.c b/code/backprop.c index 9fa184f..daddfbe 100644 --- a/code/backprop.c +++ b/code/backprop.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/backprop.h b/code/backprop.h index 88de3d0..dda2672 100644 --- a/code/backprop.h +++ b/code/backprop.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,7 +31,7 @@ /** * Adjust weights function */ -inline void +void backprop_adjust_weights(struct neuron *n, const clann_real_type *y, const clann_real_type *g, @@ -42,7 +41,7 @@ backprop_adjust_weights(struct neuron *n, /** * */ -inline void +void backprop_learn(struct mlp *ann, const clann_real_type *x, const clann_real_type *d, @@ -52,7 +51,7 @@ backprop_learn(struct mlp *ann, /** * */ -inline void +void backprop_learn_epoch(struct mlp *ann, const struct matrix *x, const struct matrix *d, @@ -88,7 +87,7 @@ backprop_train_with_validation(struct mlp *ann, /** * */ -inline void +void backprop_backward_computation(struct mlp *ann, const clann_real_type *x, const clann_real_type *d, @@ -98,7 +97,7 @@ backprop_backward_computation(struct mlp *ann, /** * */ -inline void +void backprop_compute_gradient(struct mlp *ann, const unsigned int l, const unsigned int j, diff --git a/code/clann.c b/code/clann.c index 6d0e4d5..f6a4d91 100644 --- a/code/clann.c +++ b/code/clann.c @@ -1,6 +1,5 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/code/clann.h b/code/clann.h index 4abb020..7974abf 100644 --- a/code/clann.h +++ b/code/clann.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008--2011 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,26 +59,26 @@ typedef enum {off, on} clann_key_type; /** * */ -inline void +void clann_shuffle(clann_int_type *list, clann_size_type length); /** * */ -inline void +void clann_initialize(void); /** * */ -inline clann_real_type +clann_real_type clann_nrand(void); /** * */ -inline clann_real_type +clann_real_type clann_rand(const clann_real_type min, const clann_real_type max); @@ -93,20 +92,20 @@ clann_randint(const clann_int_type min, /** * */ -inline clann_real_type +clann_real_type clann_factorial(const clann_uint_type v); /** * */ -inline clann_real_type +clann_real_type clann_binomial(const clann_uint_type n, const clann_uint_type k); /** * */ -inline clann_uint_type +clann_uint_type clann_nextpow2(clann_uint_type n); #endif diff --git a/code/dprog.c b/code/dprog.c index ec6f14e..c389c30 100644 --- a/code/dprog.c +++ b/code/dprog.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/dprog.h b/code/dprog.h index c0e5992..c30c153 100644 --- a/code/dprog.h +++ b/code/dprog.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,14 +44,14 @@ dprog_value_iteration(struct fmdp *mdp, /** * */ -inline clann_real_type +clann_real_type dprog_state_value_function(struct fmdp *mdp, unsigned int state); /** * */ -inline clann_real_type +clann_real_type dprog_action_value_function(struct fmdp *mdp, unsigned int state, unsigned int action); @@ -60,7 +59,7 @@ dprog_action_value_function(struct fmdp *mdp, /** * */ -inline clann_real_type +clann_real_type dprog_deterministic_state_value_function(struct fmdp *mdp, unsigned int state, unsigned int action); diff --git a/code/fft.c b/code/fft.c index f3e46d2..d93a111 100644 --- a/code/fft.c +++ b/code/fft.c @@ -1,6 +1,5 @@ /** - * Copyright (C) 2009 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/code/fft.h b/code/fft.h index 7151232..5167a8a 100644 --- a/code/fft.h +++ b/code/fft.h @@ -1,6 +1,5 @@ /** - * Copyright (C) 2009 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -32,7 +31,7 @@ /** * FFT function */ -inline void +void fft(complex **x, unsigned int *n, const unsigned char mode); @@ -40,14 +39,14 @@ fft(complex **x, /** * */ -inline void +void fft_reverse(complex *x, const unsigned int n); /** * */ -inline void +void fft_perform(complex *x, const unsigned int n, const unsigned char mode); diff --git a/code/fmdp.c b/code/fmdp.c index 4941d39..b7bc4e5 100644 --- a/code/fmdp.c +++ b/code/fmdp.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/fmdp.h b/code/fmdp.h index 2c72f14..be025f2 100644 --- a/code/fmdp.h +++ b/code/fmdp.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,7 +59,7 @@ struct fmdp /** * */ -inline void +void fmdp_initialize(struct fmdp *mdp, clann_real_type discount_rate, unsigned int number_of_states, @@ -69,7 +68,7 @@ fmdp_initialize(struct fmdp *mdp, /** * */ -inline void +void fmdp_finalize(struct fmdp *mdp); /** diff --git a/code/function.c b/code/function.c index 56aa324..1aea258 100644 --- a/code/function.c +++ b/code/function.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/function.h b/code/function.h index e842ebd..7194e3d 100644 --- a/code/function.h +++ b/code/function.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,32 +38,32 @@ /** * Activation step function */ -inline clann_real_type +clann_real_type function_step(const clann_real_type value); /** * Activation signal function */ -inline clann_real_type +clann_real_type function_signal(const clann_real_type value); /** * Activation sigmoid function */ -inline clann_real_type +clann_real_type function_sigmoid(const clann_real_type value); /** * Activation hyperbolic tangent function */ -inline clann_real_type +clann_real_type function_tanh(const clann_real_type value); /** * Green Gaussian function */ -inline clann_real_type +clann_real_type function_green_gaussian(const clann_real_type sigma, const clann_real_type value); diff --git a/code/hopfield.c b/code/hopfield.c index e64fadd..4348e3c 100644 --- a/code/hopfield.c +++ b/code/hopfield.c @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/hopfield.h b/code/hopfield.h index 3158eeb..2e9083c 100644 --- a/code/hopfield.h +++ b/code/hopfield.h @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ struct hopfield /** * Initialize an given Hopfield network */ -inline void +void hopfield_initialize(struct hopfield *ann, clann_size_type n_neurons, clann_size_type n_memories); @@ -49,7 +49,7 @@ hopfield_initialize(struct hopfield *ann, /** * Finalize an given Hopfield network */ -inline void +void hopfield_finalize(struct hopfield *ann); /** diff --git a/code/ilpso.c b/code/ilpso.c index 60d5712..8703c78 100644 --- a/code/ilpso.c +++ b/code/ilpso.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/ilpso.h b/code/ilpso.h index 01d09df..80a5899 100644 --- a/code/ilpso.h +++ b/code/ilpso.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,7 +63,7 @@ struct ilpso /** * */ -inline void +void ilpso_initialize(struct ilpso *s, void *problem, const unsigned int particle_length); @@ -72,13 +71,13 @@ ilpso_initialize(struct ilpso *s, /** * */ -inline void +void ilpso_finalize(struct ilpso *s); /** * */ -inline void +void ilpso_run(struct ilpso *s, const unsigned int max_iterations, const clann_real_type noticeable_change_rate); @@ -86,13 +85,13 @@ ilpso_run(struct ilpso *s, /** * */ -inline void +void ilpso_initialize_positions_and_velocities(struct ilpso *s); /** * */ -inline clann_real_type +clann_real_type ilpso_compute_probability_of_mutation(struct ilpso *s); #endif diff --git a/code/kalman.c b/code/kalman.c index 412cf4a..4baae6a 100644 --- a/code/kalman.c +++ b/code/kalman.c @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,33 +32,40 @@ kalman_initialize(struct kalman *k, k->n_measure = n_measure; k->n_control = n_control; + matrix_initialize(&k->control, k->n_control, 1); + matrix_initialize(&k->m_control, k->n_state, k->n_control); + matrix_initialize(&k->state[KALMAN_A_PRI], k->n_state, 1); matrix_initialize(&k->state[KALMAN_A_POS], k->n_state, 1); matrix_initialize(&k->measure, k->n_measure, 1); - matrix_initialize(&k->control, k->n_control, 1); matrix_initialize(&k->m_process, k->n_state, k->n_state); matrix_initialize(&k->m_measure, k->n_measure, k->n_state); - matrix_initialize(&k->m_control, k->n_state, k->n_control); matrix_initialize(&k->m_gain, k->n_state, k->n_measure); matrix_initialize(&k->m_predict[KALMAN_A_PRI], k->n_state, k->n_state); matrix_initialize(&k->m_predict[KALMAN_A_POS], k->n_state, k->n_state); matrix_initialize(&k->process_noise_cov, k->n_state, k->n_state); matrix_initialize(&k->measure_noise_cov, k->n_measure, k->n_measure); + + kalman_default(k); } void kalman_finalize(struct kalman *k) { + /* + * NOTE: maybe there is bug here. + */ matrix_finalize(&k->state[KALMAN_A_PRI]); matrix_finalize(&k->state[KALMAN_A_POS]); matrix_finalize(&k->measure); + matrix_finalize(&k->control); + matrix_finalize(&k->m_control); matrix_finalize(&k->m_process); matrix_finalize(&k->m_measure); - matrix_finalize(&k->m_control); matrix_finalize(&k->m_gain); matrix_finalize(&k->m_predict[KALMAN_A_PRI]); matrix_finalize(&k->m_predict[KALMAN_A_POS]); @@ -68,15 +75,103 @@ kalman_finalize(struct kalman *k) } void -kalman_predict(struct kalman *k, - const clann_real_type *c) +kalman_default(struct kalman *k) { - // TODO + matrix_fill(&k->state[KALMAN_A_POS], 0); + matrix_identity(&k->m_predict[KALMAN_A_POS], k->n_state); + + matrix_identity(&k->process_noise_cov, k->process_noise_cov.rows); + matrix_identity(&k->measure_noise_cov, k->measure_noise_cov.rows); + + // should be defined by application + if (k->n_control > 0) + { + matrix_fill(&k->control, 0); + matrix_fill(&k->m_control, 0); + } + matrix_identity(&k->m_process, k->m_process.rows); + matrix_fill(&k->m_measure, 0); } void -kalman_correct(struct kalman *k, - const clann_real_type *m) +kalman_predict(struct kalman *k) { - // TODO + struct matrix m; + struct matrix t; + + matrix_initialize(&m, 0, 0); + matrix_initialize(&t, 0, 0); + + /* + * Predict the next state using the process equation: + * ~^x[k] = A ^x[k-1] + B u[k-1] + */ + matrix_product(&k->m_process, &k->state[KALMAN_A_POS], &t); + + if (k->n_control > 0) + { + matrix_product(&k->m_control, &k->control, &m); + matrix_add(&m, &t, &k->state[KALMAN_A_PRI]); + } + else + matrix_copy(&t, &k->state[KALMAN_A_PRI]); + + /* + * Predict the error covariance using equation: + * ~P[k] = A P[k-1] A' + Q + */ + matrix_transpose(&k->m_process, &t); // t = A' + matrix_product(&k->m_predict[KALMAN_A_POS], &t, &m); // m = P[k-1] A' + matrix_product(&k->m_process, &m, &t); // t = A P[k-1] A' + matrix_add(&t, &k->process_noise_cov, &k->m_predict[KALMAN_A_PRI]); + + matrix_finalize(&m); + matrix_finalize(&t); +} + +void +kalman_correct(struct kalman *k) +{ + struct matrix m; + struct matrix t; + struct matrix s; + + matrix_initialize(&m, 0, 0); + matrix_initialize(&t, 0, 0); + matrix_initialize(&s, 0, 0); + + /* + * Compute Kalman gain using equation: + * K[k] = ~P[k] C' inv(C ~P[k] C' + R) + */ + matrix_transpose(&k->m_measure, &t); + matrix_product(&k->m_predict[KALMAN_A_PRI], &t, &m); // m = ~P[k] C' + matrix_product(&k->m_measure, &m, &t); // t = C ~P[k] C' + matrix_add(&t, &k->measure_noise_cov, &s); // s = C ~P[k] C' + R + matrix_inverse(&s, &t); + matrix_product(&m, &t, &k->m_gain); + + /* + * Update the estimate state using measurement: + * ^x[k] = ~^x[k] + K[k] (y[k] - C ~^x[k]) + */ + matrix_product(&k->m_measure, &k->state[KALMAN_A_PRI], &t); + matrix_subtract(&k->measure, &t, &m); + matrix_product(&k->m_gain, &m, &t); + matrix_add(&k->state[KALMAN_A_PRI], &t, &k->state[KALMAN_A_POS]); + + /* + * Update the error covariance: + * P[k] = (I - K[k] C) ~P[k] + */ + matrix_product(&k->m_gain, &k->m_measure, &t); + matrix_identity(&m, t.rows); + matrix_subtract(&m, &t, &s); + matrix_product(&s, + &k->m_predict[KALMAN_A_PRI], + &k->m_predict[KALMAN_A_POS]); + + matrix_finalize(&m); + matrix_finalize(&t); + matrix_finalize(&s); } diff --git a/code/kalman.h b/code/kalman.h index 8b6407b..049dbd3 100644 --- a/code/kalman.h +++ b/code/kalman.h @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,25 +39,25 @@ struct kalman clann_size_type n_measure; clann_size_type n_control; - struct matrix state[2]; - struct matrix measure; - struct matrix control; + struct matrix state[2]; // state, x + struct matrix measure; // measure, y + struct matrix control; // control (input), u - struct matrix m_process; // state transition matrix - struct matrix m_measure; // measurement matrix - struct matrix m_control; // control matrix - struct matrix m_gain; // kalman gain matrix - struct matrix m_predict[2]; // kalman prediction error covariance matrix + struct matrix m_process; // state transition matrix, A + struct matrix m_control; // control (input) matrix, B + struct matrix m_measure; // measurement matrix, C + struct matrix m_gain; // kalman gain matrix, K + struct matrix m_predict[2]; // prediction error covariance matrix, P - struct matrix process_noise_cov; - struct matrix measure_noise_cov; + struct matrix process_noise_cov; // process noise covariance, Q + struct matrix measure_noise_cov; // measurement noise covariance, R }; /** * Initialize an given kalman structure description */ -inline void +void kalman_initialize(struct kalman *k, clann_size_type n_state, clann_size_type n_measure, @@ -66,21 +66,25 @@ kalman_initialize(struct kalman *k, /** * Finalize an given kalman structure description */ -inline void +void kalman_finalize(struct kalman *k); /** * */ -inline void -kalman_predict(struct kalman *k, - const clann_real_type *c); +void +kalman_default(struct kalman *k); /** * */ -inline void -kalman_correct(struct kalman *kf, - const clann_real_type *m); +void +kalman_predict(struct kalman *k); + +/** + * + */ +void +kalman_correct(struct kalman *k); #endif diff --git a/code/kmeans.c b/code/kmeans.c index aa56af1..3000a32 100644 --- a/code/kmeans.c +++ b/code/kmeans.c @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/kmeans.h b/code/kmeans.h index 0dfb5ab..c90cd58 100644 --- a/code/kmeans.h +++ b/code/kmeans.h @@ -1,7 +1,7 @@ /** - * Copyright (C) 2011 Joao Paulo de Souza Medeiros + * Copyright (C) 2011-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/lms.c b/code/lms.c index 39d56ba..6847a79 100644 --- a/code/lms.c +++ b/code/lms.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/lms.h b/code/lms.h index 3206f67..658aa0e 100644 --- a/code/lms.h +++ b/code/lms.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,14 +38,14 @@ struct lms /** * Initialize LMS structure */ -inline void +void lms_initialize(struct lms *l, const clann_real_type learing_rate); /** * LMS function */ -inline void +void lms_learn(struct neuron *n, struct lms *l, const clann_real_type *x, diff --git a/code/matrix.c b/code/matrix.c index 4a9ef23..e982c86 100644 --- a/code/matrix.c +++ b/code/matrix.c @@ -1,6 +1,5 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -43,12 +42,22 @@ matrix_initialize(struct matrix *a, } } +struct matrix * +matrix_new(clann_size_type rows, + clann_size_type cols) +{ + struct matrix *m = (struct matrix *) malloc(sizeof(struct matrix)); + matrix_initialize(m, rows, cols); + return m; +} + void matrix_finalize(struct matrix *a) { if (a->values != NULL) free((void *) a->values); + a->values = (clann_real_type *) NULL; a->rows = 0; a->cols = 0; } @@ -83,16 +92,22 @@ matrix_fill_rand(struct matrix *a, a->values[i] = clann_rand(min, max); } -void +struct matrix * matrix_identity(struct matrix *a, const clann_size_type n) { - matrix_initialize(a, n, n); + if (a->rows != n || a->cols != n) + { + matrix_finalize(a); + matrix_initialize(a, n, n); + } clann_size_type i, j; for (i = 0; i < a->rows; i++) for (j = 0; j < a->cols; j++) *matrix_value(a, i, j) = (clann_real_type) (i == j) ? 1 : 0; + + return a; } void @@ -125,7 +140,11 @@ void matrix_transpose(const struct matrix *a, struct matrix *b) { - matrix_initialize(b, a->cols, a->rows); + if (b->rows != a->cols || b->cols != a->rows) + { + matrix_finalize(b); + matrix_initialize(b, a->cols, a->rows); + } clann_size_type i, j; for (i = 0; i < b->rows; i++) @@ -141,16 +160,17 @@ matrix_add(const struct matrix *a, if (a->rows != b->rows || a->cols != b->cols) return (struct matrix*) NULL; - matrix_initialize(c, a->rows, a->cols); - matrix_fill(c, 0); + if (c->rows != a->rows || c->cols != b->cols) + { + matrix_finalize(c); + matrix_initialize(c, a->rows, b->cols); + } clann_size_type i, j; for (i = 0; i < a->rows; i++) for (j = 0; j < a->cols; j++) - { - *matrix_value(c, i, j) += *matrix_value(a, i, j); - *matrix_value(c, i, j) += *matrix_value(b, i, j); - } + *matrix_value(c, i, j) = *matrix_value(a, i, j) + + *matrix_value(b, i, j); return c; } @@ -163,16 +183,17 @@ matrix_subtract(const struct matrix *a, if (a->rows != b->rows || a->cols != b->cols) return (struct matrix*) NULL; - matrix_initialize(c, a->rows, a->cols); - matrix_fill(c, 0); + if (c->rows != a->rows || c->cols != b->cols) + { + matrix_finalize(c); + matrix_initialize(c, a->rows, b->cols); + } clann_size_type i, j; for (i = 0; i < a->rows; i++) for (j = 0; j < a->cols; j++) - { - *matrix_value(c, i, j) += *matrix_value(a, i, j); - *matrix_value(c, i, j) -= *matrix_value(b, i, j); - } + *matrix_value(c, i, j) = *matrix_value(a, i, j) - + *matrix_value(b, i, j); return c; } @@ -183,9 +204,14 @@ matrix_product(const struct matrix *a, struct matrix *c) { if (a->cols != b->rows) - return (struct matrix*) NULL; + return (struct matrix *) NULL; + + if (c->rows != a->rows || c->cols != b->cols) + { + matrix_finalize(c); + matrix_initialize(c, a->rows, b->cols); + } - matrix_initialize(c, a->rows, b->cols); matrix_fill(c, 0); clann_size_type i, j, s; @@ -245,6 +271,8 @@ matrix_inverse(const struct matrix *a, p++; } + matrix_finalize(&c); + return b; } @@ -254,6 +282,10 @@ matrix_pseudo_inverse(const struct matrix *a, { struct matrix c, d, e; + matrix_initialize(&c, 0, 0); + matrix_initialize(&d, 0, 0); + matrix_initialize(&e, 0, 0); + matrix_transpose(a, &c); if (matrix_product(&c, a, &d) == NULL) @@ -282,6 +314,15 @@ matrix_isnull(const struct matrix *a) return 0; } +void +matrix_scale(const struct matrix *a, + clann_real_type s) +{ + clann_size_type i; + for (i = 0; i < a->rows * a->cols; i++) + a->values[i] = a->values[i] * s; +} + void matrix_print(const struct matrix *a) { diff --git a/code/matrix.h b/code/matrix.h index 3f066f2..d766505 100644 --- a/code/matrix.h +++ b/code/matrix.h @@ -1,6 +1,5 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -42,21 +41,28 @@ struct matrix /** * Initialize an given matrix */ -inline void +void matrix_initialize(struct matrix *a, clann_size_type rows, clann_size_type cols); +/** + * Create a new matrix + */ +struct matrix * +matrix_new(clann_size_type rows, + clann_size_type cols); + /** * Finalize an given matrix */ -inline void +void matrix_finalize(struct matrix *a); /** * Return an matrix element */ -inline clann_real_type* +clann_real_type* matrix_value(const struct matrix *a, const clann_size_type i, const clann_size_type j); @@ -64,14 +70,14 @@ matrix_value(const struct matrix *a, /** * */ -inline void +void matrix_fill(struct matrix *a, const clann_real_type v); /** * */ -inline void +void matrix_fill_rand(struct matrix *a, clann_real_type min, clann_real_type max); @@ -79,34 +85,34 @@ matrix_fill_rand(struct matrix *a, /** * */ -inline void +struct matrix * matrix_identity(struct matrix *a, const clann_size_type n); /** * */ -inline void +void matrix_copy(const struct matrix *a, struct matrix *b); /** * */ -inline struct matrix * +struct matrix * matrix_copy_new(const struct matrix *a); /** * */ -inline void +void matrix_transpose(const struct matrix *a, struct matrix *b); /** * */ -inline struct matrix* +struct matrix* matrix_add(const struct matrix *a, const struct matrix *b, struct matrix *c); @@ -114,7 +120,7 @@ matrix_add(const struct matrix *a, /** * */ -inline struct matrix* +struct matrix* matrix_subtract(const struct matrix *a, const struct matrix *b, struct matrix *c); @@ -122,7 +128,7 @@ matrix_subtract(const struct matrix *a, /** * */ -inline struct matrix* +struct matrix* matrix_product(const struct matrix *a, const struct matrix *b, struct matrix *c); @@ -130,23 +136,30 @@ matrix_product(const struct matrix *a, /** * */ -inline struct matrix* +struct matrix* matrix_inverse(const struct matrix *a, struct matrix *b); /** * */ -inline struct matrix* +struct matrix* matrix_pseudo_inverse(const struct matrix *a, struct matrix *b); /** * */ -inline int +int matrix_isnull(const struct matrix *a); +/** + * + */ +void +matrix_scale(const struct matrix *a, + clann_real_type s); + /** * */ diff --git a/code/metric.c b/code/metric.c index c412d11..b0c604b 100644 --- a/code/metric.c +++ b/code/metric.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/metric.h b/code/metric.h index cb96ee6..e4e5570 100644 --- a/code/metric.h +++ b/code/metric.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +30,7 @@ /** * Normalize */ -inline clann_real_type +clann_real_type metric_scale(clann_real_type value, clann_real_type *from, clann_real_type *to); @@ -39,7 +38,7 @@ metric_scale(clann_real_type value, /** * */ -inline clann_real_type +clann_real_type metric_euclidean_pow2(const clann_real_type *a, const clann_real_type *b, const unsigned int length); @@ -47,7 +46,7 @@ metric_euclidean_pow2(const clann_real_type *a, /** * */ -inline clann_real_type +clann_real_type metric_euclidean(const clann_real_type *a, const clann_real_type *b, const unsigned int length); @@ -55,14 +54,14 @@ metric_euclidean(const clann_real_type *a, /** * */ -inline clann_real_type +clann_real_type metric_norm(const clann_real_type *a, const unsigned int length); /** * */ -inline clann_real_type +clann_real_type metric_dot_product(const clann_real_type *a, const clann_real_type *b, const unsigned int length); @@ -70,21 +69,21 @@ metric_dot_product(const clann_real_type *a, /** * */ -inline clann_real_type +clann_real_type metric_hausdorff(const struct matrix *a, const struct matrix *b); /** * */ -inline clann_real_type +clann_real_type metric_hausdorff_symmetric(const struct matrix *a, const struct matrix *b); /** * */ -inline unsigned int +unsigned int metric_hausdorff_limit(const struct matrix *a, const struct matrix *b, clann_real_type limit); @@ -92,7 +91,7 @@ metric_hausdorff_limit(const struct matrix *a, /** * */ -inline unsigned int +unsigned int metric_hausdorff_limit_symmetric(const struct matrix *a, const struct matrix *b, clann_real_type limit); @@ -100,21 +99,21 @@ metric_hausdorff_limit_symmetric(const struct matrix *a, /** * */ -inline clann_real_type +clann_real_type metric_hausdorff_mean(const struct matrix *a, const struct matrix *b); /** * */ -inline clann_real_type +clann_real_type metric_hausdorff_mean_symmetric(const struct matrix *a, const struct matrix *b); /** * */ -inline unsigned int +unsigned int metric_hausdorff_angle(const struct matrix *a, const struct matrix *b, clann_real_type limit); @@ -122,7 +121,7 @@ metric_hausdorff_angle(const struct matrix *a, /** * */ -inline unsigned int +unsigned int metric_hausdorff_angle_symmetric(const struct matrix *a, const struct matrix *b, clann_real_type limit); diff --git a/code/mlp.c b/code/mlp.c index af2def5..724f296 100644 --- a/code/mlp.c +++ b/code/mlp.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/mlp.h b/code/mlp.h index a6ec6db..c0ef52e 100644 --- a/code/mlp.h +++ b/code/mlp.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,20 +54,20 @@ struct mlp /** * Initialize an given layer */ -inline void +void mlp_layer_initialize(struct mlp_layer *l, const unsigned int input_size, const unsigned int number_of_neurons); /** * Finalize an given layer */ -inline void +void mlp_layer_finalize(struct mlp_layer *l); /** * */ -inline void +void mlp_initialize(struct mlp *ann, unsigned int *architecture, const unsigned int number_of_layers); @@ -76,47 +75,47 @@ mlp_initialize(struct mlp *ann, /** * */ -inline void +void mlp_finalize(struct mlp *ann); /** * */ -inline void +void mlp_forward_computation(struct mlp *ann, const clann_real_type *x); /** * */ -inline void +void mlp_compute_layer_output(struct mlp_layer *l, const clann_real_type *x); /** * */ -inline void +void mlp_compute_instantaneous_error(struct mlp *ann); /** * */ -inline void +void mlp_compute_avarage_error(struct mlp *ann, const unsigned int n); /** * */ -inline void +void mlp_compute_output_error(struct mlp *ann, const clann_real_type *d); /** * */ -inline void +void mlp_validate(struct mlp *ann, const clann_real_type *x, const clann_real_type *d); @@ -124,7 +123,7 @@ mlp_validate(struct mlp *ann, /** * */ -inline void +void mlp_validate_epoch(struct mlp *ann, const struct matrix *x, const struct matrix *d); diff --git a/code/narx.c b/code/narx.c index f04fa4b..12c1ba7 100644 --- a/code/narx.c +++ b/code/narx.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/narx.h b/code/narx.h index 38a29f4..aeb6648 100644 --- a/code/narx.h +++ b/code/narx.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,7 +49,7 @@ struct narx /** * */ -inline void +void narx_initialize(struct narx *ann, unsigned int *architecture, const unsigned int number_of_layers, @@ -59,13 +58,13 @@ narx_initialize(struct narx *ann, /** * */ -inline void +void narx_finalize(struct narx *ann); /** * */ -inline void +void narx_insert_input(struct narx *ann, const clann_real_type x); diff --git a/code/neuron.c b/code/neuron.c index 1dbb1a2..bbd9e0b 100644 --- a/code/neuron.c +++ b/code/neuron.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/neuron.h b/code/neuron.h index 1a9c0dc..2872a1c 100644 --- a/code/neuron.h +++ b/code/neuron.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,20 +43,20 @@ struct neuron /** * Initialize an given neuron */ -inline void +void neuron_initialize(struct neuron *n, const unsigned int n_weights); /** * Initialize an given neuron */ -inline void +void neuron_finalize(struct neuron *n); /** * Compute neuron output given a neuron and its input */ -inline void +void neuron_compute_output(struct neuron *n, const clann_real_type *x); diff --git a/code/perceptron.c b/code/perceptron.c index 3d13f94..4aa9403 100644 --- a/code/perceptron.c +++ b/code/perceptron.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/perceptron.h b/code/perceptron.h index 9a3b1a9..dff64c1 100644 --- a/code/perceptron.h +++ b/code/perceptron.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +30,7 @@ /** * Adjust weights function */ -inline void +void perceptron_adjust_weights(struct neuron *n, const clann_real_type *x, const clann_real_type *d, @@ -40,7 +39,7 @@ perceptron_adjust_weights(struct neuron *n, /** * Perceptron learning function */ -inline void +void perceptron_learn(struct neuron *n, const clann_real_type *x, const clann_real_type *d, diff --git a/code/periodogram.c b/code/periodogram.c index ed11ac1..a6abbd6 100644 --- a/code/periodogram.c +++ b/code/periodogram.c @@ -1,6 +1,5 @@ /** - * Copyright (C) 2009 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/code/periodogram.h b/code/periodogram.h index cf7e102..dafa822 100644 --- a/code/periodogram.h +++ b/code/periodogram.h @@ -1,6 +1,5 @@ /** - * Copyright (C) 2009 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -44,7 +43,7 @@ struct periodogram /** * Initialize an given periodogram */ -inline void +void periodogram_initialize(struct periodogram *p, unsigned int q, unsigned int l, @@ -53,13 +52,13 @@ periodogram_initialize(struct periodogram *p, /** * Finalize an given periodogram */ -inline void +void periodogram_finalize(struct periodogram *a); /** * Periodogram averaging function */ -inline void +void periodogram(struct periodogram *p, complex const *x, unsigned int n); diff --git a/code/rbf.c b/code/rbf.c index 3957792..5a15f0f 100644 --- a/code/rbf.c +++ b/code/rbf.c @@ -1,9 +1,8 @@ /** - * Copyright (C) 2008-2011 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros - * José Macedo Firmino Filho + * Author(s): Joao Paulo de Souza Medeiros + * Jose Macedo Firmino Filho * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/rbf.h b/code/rbf.h index 4469209..2402e9a 100644 --- a/code/rbf.h +++ b/code/rbf.h @@ -1,9 +1,8 @@ /** - * Copyright (C) 2008-2011 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros - * José Macedo Firmino Filho + * Author(s): Joao Paulo de Souza Medeiros + * Jose Macedo Firmino Filho * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +66,7 @@ struct rbf /** * Initialize an given RBF */ -inline void +void rbf_initialize(struct rbf *ann, clann_size_type input_size, clann_size_type output_size, @@ -76,13 +75,13 @@ rbf_initialize(struct rbf *ann, /** * */ -inline void +void rbf_finalize(struct rbf *ann); /** * */ -inline void +void rbf_learn(struct rbf *ann, const struct matrix *x, const struct matrix *d); @@ -90,7 +89,7 @@ rbf_learn(struct rbf *ann, /** * */ -inline void +void rbf_learning_with_fixed_centers(struct rbf *ann, const struct matrix *x, const struct matrix *d); @@ -98,7 +97,7 @@ rbf_learning_with_fixed_centers(struct rbf *ann, /** * */ -inline void +void rbf_learning_supervised(struct rbf *ann, const struct matrix *x, const struct matrix *d); @@ -106,7 +105,7 @@ rbf_learning_supervised(struct rbf *ann, /** * */ -inline void +void rbf_learning_self_organized(struct rbf *ann, const struct matrix *x, const struct matrix *d); @@ -114,35 +113,35 @@ rbf_learning_self_organized(struct rbf *ann, /** * */ -inline void +void rbf_compute_green(struct rbf *ann, const struct matrix *x); /** * */ -inline void +void rbf_compute_weights(struct rbf *ann, const struct matrix *d); /** * */ -inline void +void rbf_compute_output(struct rbf *ann, clann_real_type *x); /** * */ -inline void +void rbf_initialize_centers_at_random(struct rbf *ann, const struct matrix *x); /** * */ -inline void +void rbf_compute_center_widths(struct rbf *ann); #endif diff --git a/code/reader.c b/code/reader.c index 7dd5b86..c1d78b3 100644 --- a/code/reader.c +++ b/code/reader.c @@ -1,9 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques - * Copyright (C) 2010 Joao Paulo de Souza Medeiros + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/reader.h b/code/reader.h index e40a43e..4d9df7a 100644 --- a/code/reader.h +++ b/code/reader.h @@ -1,9 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques - * Copyright (C) 2010 Joao Paulo de Souza Medeiros + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/smatrix.h b/code/smatrix.h index 0d1bd06..303ac0b 100644 --- a/code/smatrix.h +++ b/code/smatrix.h @@ -51,7 +51,7 @@ struct smatrix /** * Initialize a given matrix */ -inline void +void matrix_initialize(struct smatrix *a, const unsigned long int rows, const unsigned long int cols); @@ -59,13 +59,13 @@ matrix_initialize(struct smatrix *a, /** * Finalize a given matrix */ -inline void +void matrix_finalize(struct smatrix *a); /** * Return a matrix element */ -inline clann_real_type* +clann_real_type* matrix_value(const struct smatrix *a, const unsigned int i, const unsigned int j); @@ -73,35 +73,35 @@ matrix_value(const struct smatrix *a, /** * */ -inline void +void matrix_fill(struct smatrix *a, const clann_real_type v); /** * */ -inline void +void matrix_identity(struct smatrix *a, const unsigned int n); /** * */ -inline void +void matrix_copy(const struct smatrix *a, struct smatrix *b); /** * */ -inline void +void matrix_transpose(const struct smatrix *a, struct smatrix *b); /** * */ -inline struct smatrix* +struct smatrix* matrix_add(const struct smatrix *a, const struct smatrix *b, struct smatrix *c); @@ -109,7 +109,7 @@ matrix_add(const struct smatrix *a, /** * */ -inline struct smatrix* +struct smatrix* matrix_subtract(const struct smatrix *a, const struct smatrix *b, struct smatrix *c); @@ -117,7 +117,7 @@ matrix_subtract(const struct smatrix *a, /** * */ -inline struct smatrix* +struct smatrix* matrix_product(const struct smatrix *a, const struct smatrix *b, struct smatrix *c); @@ -125,21 +125,21 @@ matrix_product(const struct smatrix *a, /** * */ -inline struct smatrix* +struct smatrix* matrix_inverse(const struct smatrix *a, struct smatrix *b); /** * */ -inline struct smatrix* +struct smatrix* matrix_pseudo_inverse(const struct smatrix *a, struct smatrix *b); /** * */ -inline int +int matrix_isnull(const struct smatrix *a); #endif diff --git a/code/som.c b/code/som.c index c8c7f42..bc66880 100644 --- a/code/som.c +++ b/code/som.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/som.h b/code/som.h index 228cd0e..2bdbc71 100644 --- a/code/som.h +++ b/code/som.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -77,7 +76,7 @@ struct som /** * */ -inline void +void som_initialize(struct som *ann, som_grid_type grid_type, clann_size_type input_size, @@ -86,7 +85,7 @@ som_initialize(struct som *ann, /** * */ -inline void +void som_finalize(struct som *ann); /** @@ -117,7 +116,7 @@ som_train_batch(struct som *ann, /** * */ -inline void +void som_incremental_adjust_of_weights(struct som *ann, clann_real_type *x, clann_real_type *winner); @@ -125,7 +124,7 @@ som_incremental_adjust_of_weights(struct som *ann, /** * */ -inline void +void som_batch_adjust_of_weights(struct som *ann, clann_real_type *x, clann_real_type *winner); @@ -133,26 +132,26 @@ som_batch_adjust_of_weights(struct som *ann, /** * */ -inline void +void som_adjust_width(struct som *ann); /** * */ -inline void +void som_adjust_learning_rate(struct som *ann); /** * */ -inline clann_real_type* +clann_real_type* som_grid_get_weights(struct som *ann, unsigned int index); /** * */ -inline void +void som_find_winner_neuron(struct som *ann, clann_real_type *x, clann_real_type **winner); diff --git a/code/statistic.c b/code/statistic.c index c7a40ca..e4510e3 100644 --- a/code/statistic.c +++ b/code/statistic.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/statistic.h b/code/statistic.h index d4a4c30..5ff7b3c 100644 --- a/code/statistic.h +++ b/code/statistic.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,34 +28,34 @@ /** * */ -inline clann_real_type +clann_real_type statistic_mean(const clann_real_type *list, const unsigned int length); /** * */ -inline clann_real_type +clann_real_type statistic_mean_matrix(const struct matrix *m); /** * */ -inline clann_real_type +clann_real_type statistic_mean_matrix_row(const struct matrix *m, const unsigned int row); /** * */ -inline clann_real_type +clann_real_type statistic_mean_matrix_col(const struct matrix *m, const unsigned int col); /** * */ -inline clann_real_type +clann_real_type statistic_variance(const clann_real_type *list, const clann_real_type *probability, const unsigned int length); @@ -64,14 +63,14 @@ statistic_variance(const clann_real_type *list, /** * */ -inline clann_real_type +clann_real_type statistic_variance_matrix(const struct matrix *m, const clann_real_type *probability); /** * */ -inline clann_real_type +clann_real_type statistic_variance_matrix_row(const struct matrix *m, const clann_real_type *probability, const unsigned int row); @@ -79,7 +78,7 @@ statistic_variance_matrix_row(const struct matrix *m, /** * */ -inline clann_real_type +clann_real_type statistic_variance_matrix_col(const struct matrix *m, const clann_real_type *probability, const unsigned int col); diff --git a/code/svm.c b/code/svm.c index 79a774f..c73f6af 100644 --- a/code/svm.c +++ b/code/svm.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/svm.h b/code/svm.h index 0d08f5d..2568483 100644 --- a/code/svm.h +++ b/code/svm.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,7 +73,7 @@ struct svm /** * Initialize an given SVM */ -inline void +void svm_initialize(struct svm *s, const unsigned int input_size, const unsigned int number_of_inputs); @@ -82,7 +81,7 @@ svm_initialize(struct svm *s, /** * */ -inline void +void svm_compute_weights(struct svm *s, const struct matrix *x, const struct matrix *d); @@ -90,35 +89,35 @@ svm_compute_weights(struct svm *s, /** * */ -inline void +void svm_compute_output(struct svm *s, const clann_real_type *x); /** * */ -inline clann_real_type +clann_real_type svm_compute_fitness_function(struct svm *s, const clann_real_type *l); /** * */ -inline void +void svm_constraint_function(struct svm *s, clann_real_type *l); /** * */ -inline void +void svm_solve_by_ilpso(struct svm *s, clann_real_type *l); /** * */ -inline clann_real_type +clann_real_type svm_compute_kernel(struct svm *s, const clann_real_type *a, const clann_real_type *b); diff --git a/code/tlfn.c b/code/tlfn.c index 2518921..82bce53 100644 --- a/code/tlfn.c +++ b/code/tlfn.c @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/code/tlfn.h b/code/tlfn.h index 6f444b1..6077703 100644 --- a/code/tlfn.h +++ b/code/tlfn.h @@ -1,8 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +47,7 @@ struct tlfn /** * */ -inline void +void tlfn_initialize(struct tlfn *ann, unsigned int *architecture, const unsigned int number_of_layers); @@ -56,13 +55,13 @@ tlfn_initialize(struct tlfn *ann, /** * */ -inline void +void tlfn_finalize(struct tlfn *ann); /** * */ -inline void +void tlfn_insert_input(struct tlfn *ann, const clann_real_type x); diff --git a/test/fft.c b/test/fft.c index 6ae835a..779162b 100644 --- a/test/fft.c +++ b/test/fft.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/test/lms.c b/test/lms.c index 5956e63..9130b66 100644 --- a/test/lms.c +++ b/test/lms.c @@ -1,7 +1,7 @@ /** - * Copyright (C) 2008 Joao Paulo de Souza Medeiros. + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * - * Author(s): João Paulo de Souza Medeiros + * Author(s): Joao Paulo de Souza Medeiros * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/test/matrix.c b/test/matrix.c index 614b67b..341b57d 100644 --- a/test/matrix.c +++ b/test/matrix.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * @@ -29,12 +29,15 @@ int main(int argc, char** argv) { struct matrix a, b; - unsigned i, j; clann_initialize(); matrix_initialize(&a, M, N); + matrix_initialize(&b, 0, 0); + matrix_fill_rand(&a, -9, 9); + + /* *matrix_value(&a, 0, 0) = 1; *matrix_value(&a, 0, 1) = 2; *matrix_value(&a, 0, 2) = 6; @@ -50,17 +53,15 @@ int main(int argc, char** argv) *matrix_value(&a, 3, 0) = 1; *matrix_value(&a, 3, 1) = 0; *matrix_value(&a, 3, 2) = 2; + */ + + printf("Matrix:\n"); + matrix_print(&a); if (matrix_pseudo_inverse(&a, &b) != NULL) { printf("Pseudo-inverse:\n"); - for (i = 0; i < N; i++) - { - for (j = 0; j < M; j++) - printf(CLANN_PRINTF " ", *matrix_value(&b, i, j)); - - printf("\n"); - } + matrix_print(&b); } else printf("No pseudo-inverse.\n"); diff --git a/test/rbf.c b/test/rbf.c index 8b0544b..4af9ec5 100644 --- a/test/rbf.c +++ b/test/rbf.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/test/som.c b/test/som.c index a9afd3d..556336b 100644 --- a/test/som.c +++ b/test/som.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2008-2011 Joao Paulo de Souza Medeiros. + * Copyright (C) 2008-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros * diff --git a/test/svm.c b/test/svm.c index a1d947e..bb4c257 100644 --- a/test/svm.c +++ b/test/svm.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Adriano Monteiro Marques + * Copyright (C) 2009-2014 Joao Paulo de Souza Medeiros * * Author(s): Joao Paulo de Souza Medeiros *