CCL Library  1.0
ccl_learn_alpha.h
Go to the documentation of this file.
1 /*********************************************************************
2 CCL:A library for Constraint Consistent learning
3 Copyright (C) 2018 Matthew Howard
4 Contact:matthew.j.howard@kcl.ac.uk
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *********************************************************************/
19 
20 
103 #ifndef __CCL_LEARN_ALPHA_H
104 #define __CCL_LEARN_ALPHA_H
105 
106 #include <ccl_math.h>
107 #include <gsl/gsl_linalg.h>
108 #include <gsl/gsl_blas.h>
109 #include <gsl/gsl_math.h>
110 #include <gsl/gsl_sf.h>
111 #include <stdio.h>
112 #include <string.h>
113 #include <stdlib.h>
115 #define NUM_CONSTRAINT 3
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
125 typedef struct{
126  int dim_b;
127  int dim_r;
128  int dim_x;
129  int dim_u;
130  int dim_t;
131  int dim_k;
132  int dim_n;
133  double var;
134  double nmse;
135  double *w[NUM_CONSTRAINT];
136  double * c;
137  double s2;
138 } LEARN_A_MODEL;
139 
145 typedef struct{
146  int MaxIter;
147  double Tolfun;
148  double Tolx;
149  double Jacob;
150 } OPTION;
151 
159 typedef struct{
160  int dim_x;
161  int dim_u;
162  int dim_n;
163  int dim_b;
164  int dim_k;
165  double * xc;
166  double * x;
167  double * xf;
168  double * epsx;
169  double epsf;
170  double * r;
171  double * J;
172  double S;
173  double * A;
174  double * v;
175  double * D;
176  double Rlo;
177  double Rhi;
178  double l;
179  double lc;
180  double * d;
181  int iter;
182  int r_ok;
183  int x_ok;
184  double * xd;
185  double * rd;
186  double Sd;
187  double dS;
188  double R;
189  double nu;
190  double* d_T;
191  double* J_T;
192  double* tmp;
193  double* rd_T;
194  gsl_matrix* D_pinv;
195  gsl_vector* A_d;
196  gsl_matrix* A_inv;
197  gsl_vector* A_inv_diag;
198  gsl_vector* r_T;
199 } SOLVE_LM_WS;
200 
209 
218 
227 int ccl_solve_lm_ws_alloc(const LEARN_A_MODEL *model,SOLVE_LM_WS * lm_ws);
228 
236 int ccl_solve_lm_ws_free(SOLVE_LM_WS * lm_ws);
237 
249 void ccl_learn_alpha(const double * Un,const double *X,const int dim_b,const int dim_r,const int dim_n,const int dim_x,const int dim_u,LEARN_A_MODEL optimal);
250 
258 void search_learn_alpha(const double *BX,const double *RnUn, LEARN_A_MODEL* model);
266 void obj_AUn (const LEARN_A_MODEL* model, const double* W, const double* BX,const double * RnUn,double* fun_out);
267 
275 void ccl_get_unit_vector_from_matrix(const double *theta, int dim_n, int dim_t, double *alpha);
276 
286 void ccl_solve_lm(const LEARN_A_MODEL* model,const double* RnUn,const double* BX, const OPTION option,SOLVE_LM_WS * lm_ws_param, double* W);
287 
299 void findjac(const LEARN_A_MODEL* model, const int dim_x,const double* BX, const double * RnUn,const double *y,const double*x,double epsx,double* J);
300 
309 void ccl_get_rotation_matrix(const double*theta,const double*currentRn,const LEARN_A_MODEL* model,const int alpha_id,double*Rn);
310 
319 void ccl_make_given_matrix(const double theta,int i,int j,int dim,double*G);
320 
330 void predict_proj_alpha(double* x, LEARN_A_MODEL* model,double* centres,double variance,double* Iu, double*A);
331 #ifdef __cplusplus
332 }
333 #endif
334 #endif
335 
int dim_t
Number of parameters needed to represent an unit vector.
Definition: ccl_learn_alpha.h:130
double Sd
The squared error if xd is taken.
Definition: ccl_learn_alpha.h:186
double R
The reduction if xd is taken.
Definition: ccl_learn_alpha.h:188
int dim_k
The dimensionality of the constraints.
Definition: ccl_learn_alpha.h:164
gsl_matrix * D_pinv
The peudo-inverse of D.
Definition: ccl_learn_alpha.h:194
void predict_proj_alpha(double *x, LEARN_A_MODEL *model, double *centres, double variance, double *Iu, double *A)
Computation routine for prediction of the A matrix.
void ccl_get_rotation_matrix(const double *theta, const double *currentRn, const LEARN_A_MODEL *model, const int alpha_id, double *Rn)
Computation routine for rotation matrix after finding the k^th constraint vector. ...
double * J_T
The matrix transpose of J.
Definition: ccl_learn_alpha.h:191
int iter
The iteration number.
Definition: ccl_learn_alpha.h:181
gsl_vector * A_inv_diag
The vector of diagonal elements of A matrix.
Definition: ccl_learn_alpha.h:197
int dim_n
The number of data points.
Definition: ccl_learn_alpha.h:162
double var
The variance of the Un.
Definition: ccl_learn_alpha.h:133
double epsf
The tolerence fo the objective functions.
Definition: ccl_learn_alpha.h:169
gsl_vector * A_d
The A matrix at xd.
Definition: ccl_learn_alpha.h:195
double * xd
The next x.
Definition: ccl_learn_alpha.h:184
double * x
The flattened and updated model parameters.
Definition: ccl_learn_alpha.h:166
int dim_k
The dimensionality of the constraints.
Definition: ccl_learn_alpha.h:131
gsl_vector * r_T
The vector transpose of r.
Definition: ccl_learn_alpha.h:198
gsl_matrix * A_inv
The peudo-inverse of A.
Definition: ccl_learn_alpha.h:196
double * rd
The residual error at xd.
Definition: ccl_learn_alpha.h:185
int dim_r
The dimensionality of the task space.
Definition: ccl_learn_alpha.h:127
#define NUM_CONSTRAINT
Definition: ccl_learn_alpha.h:115
double l
The adaptive learning rate.
Definition: ccl_learn_alpha.h:178
int dim_u
The dimensionality of the action space.
Definition: ccl_learn_alpha.h:161
double Rhi
The upper bound of R.
Definition: ccl_learn_alpha.h:177
int ccl_solve_lm_ws_alloc(const LEARN_A_MODEL *model, SOLVE_LM_WS *lm_ws)
Allocates the workspace memory for the LM solver.
double * d
The parameter improvement gradient.
Definition: ccl_learn_alpha.h:180
double * D
Automatic scaling.
Definition: ccl_learn_alpha.h:175
int dim_x
The dimensionality of the state space.
Definition: ccl_learn_alpha.h:128
int ccl_solve_lm_ws_free(SOLVE_LM_WS *lm_ws)
Free the memory for the LM solver.
double dS
The denomitor of the sqaured error is xd is taken.
Definition: ccl_learn_alpha.h:187
double * c
The mean of the rbf.
Definition: ccl_learn_alpha.h:136
double Rlo
The lower bound of R.
Definition: ccl_learn_alpha.h:176
double * d_T
The matrix transpose of d.
Definition: ccl_learn_alpha.h:190
int dim_b
The number of basis functions.
Definition: ccl_learn_alpha.h:163
This structure defines the workspace variables for solving the non-linear LM optimization.
Definition: ccl_learn_alpha.h:159
void search_learn_alpha(const double *BX, const double *RnUn, LEARN_A_MODEL *model)
Main computation routine for learning a model of A.
int x_ok
check if the model parameters are belowed the tolerence
Definition: ccl_learn_alpha.h:183
void findjac(const LEARN_A_MODEL *model, const int dim_x, const double *BX, const double *RnUn, const double *y, const double *x, double epsx, double *J)
Computation routine for numerical approximation of the objevtive jacobian matrix. ...
int ccl_learn_alpha_model_free(LEARN_A_MODEL *model)
Free the memory for the learn_alpha model.
double * A
The dot product of J_T and J.
Definition: ccl_learn_alpha.h:173
double * r
The returned value of the residual error.
Definition: ccl_learn_alpha.h:170
int dim_x
The dimensionality of the state variable.
Definition: ccl_learn_alpha.h:160
CCL header file for math.
int dim_n
The number of data points.
Definition: ccl_learn_alpha.h:132
double S
The sqaure root if x is taken.
Definition: ccl_learn_alpha.h:172
void ccl_make_given_matrix(const double theta, int i, int j, int dim, double *G)
Computation routine for generating roation matrix of a plane rotation of degree theta in an arbitrary...
int dim_u
The dimensionality of the action space.
Definition: ccl_learn_alpha.h:129
double nmse
The normalised mean square error of the model.
Definition: ccl_learn_alpha.h:134
double s2
The variance of the rbf.
Definition: ccl_learn_alpha.h:137
int ccl_learn_alpha_model_alloc(LEARN_A_MODEL *model)
Allocates the memory for the learn_alpha model.
void ccl_get_unit_vector_from_matrix(const double *theta, int dim_n, int dim_t, double *alpha)
Computation routine for generating unit vector for row vector alpha by given theta anlges...
void obj_AUn(const LEARN_A_MODEL *model, const double *W, const double *BX, const double *RnUn, double *fun_out)
Computation routine for learning constraint by increasing the dimensionality of k.
double nu
The coefficient of changing learning rate.
Definition: ccl_learn_alpha.h:189
double * tmp
The temporal variable.
Definition: ccl_learn_alpha.h:192
double * xc
A copy of the initial model parameters.
Definition: ccl_learn_alpha.h:165
void ccl_solve_lm(const LEARN_A_MODEL *model, const double *RnUn, const double *BX, const OPTION option, SOLVE_LM_WS *lm_ws_param, double *W)
Computation routine for optimizing non-linear objective functions using LM approach.
This structure defines the OPTION for the optimizer.
Definition: ccl_learn_alpha.h:145
double * J
The jacobian at x.
Definition: ccl_learn_alpha.h:171
double * rd_T
The matrix transpose of rd.
Definition: ccl_learn_alpha.h:193
double lc
Handling situation when learning rate happends to be 0.
Definition: ccl_learn_alpha.h:179
double * xf
The finalised model parameters.
Definition: ccl_learn_alpha.h:167
void ccl_learn_alpha(const double *Un, const double *X, const int dim_b, const int dim_r, const int dim_n, const int dim_x, const int dim_u, LEARN_A_MODEL optimal)
Main computation routine for learning state dependent constraint A.
This structure describes a "LEARN_A_MODEL" (a learn alpha model). This structure constains the diment...
Definition: ccl_learn_alpha.h:125
double * v
The dot product of J_T and r.
Definition: ccl_learn_alpha.h:174
int r_ok
check if the objective function is belowed the tolerence
Definition: ccl_learn_alpha.h:182
int dim_b
The number of basis functions.
Definition: ccl_learn_alpha.h:126
double * epsx
The tolerence of the model paramters.
Definition: ccl_learn_alpha.h:168