CCL Library  1.0
ccl_learn_ncl.h
Go to the documentation of this file.
1 
6 #ifndef __CCL_LEARN_NCL_H
7 #define __CCL_LEARN_NCL_H
8 
9 #include <ccl_math.h>
10 #include <ccl_learn_alpha.h>
11 #include <gsl/gsl_linalg.h>
12 #include <gsl/gsl_blas.h>
13 #include <gsl/gsl_math.h>
14 #include <gsl/gsl_eigen.h>
15 #include <gsl/gsl_sf.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <time.h>
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
30 typedef struct {
31  int dim_b;
32  int dim_x;
33  int dim_y;
34  int dim_n;
35  double* c;
36  double s2;
37  double* w;
39 
48 typedef struct {
49  gsl_matrix* HS;
50  gsl_matrix* g;
51  gsl_matrix* Y_T;
52  gsl_matrix* Y_;
53  gsl_matrix* H;
54  gsl_matrix* BX_T;
55  gsl_matrix* BX_;
56  gsl_matrix* w_;
57  gsl_matrix* pinvH1;
58  gsl_vector* V;
59  gsl_matrix* D;
60  int * idx;
62 
70 typedef struct {
71  double* W;
72  double* W_;
73  gsl_matrix* J;
74  gsl_vector* b_n;
75  gsl_matrix* b_n_T;
76  gsl_vector* u_n;
77  gsl_matrix* u_n_T;
78  gsl_matrix* BX_;
79  gsl_matrix* Y_;
80  gsl_vector* Wb;
81  gsl_matrix* Wb_T;
82  double c;
83  double a;
84  gsl_matrix* j_n;
85  gsl_vector* j_n_flt;
86  gsl_matrix* tmp2;
87  double tmp;
88 } OBJ_WS;
89 
97 typedef struct{
98  int dim_x;
99  int dim_n;
100  int dim_b;
101  int dim_y;
102  int r_ok;
103  int d_ok;
104  double * xc;
105  double * x;
106  double * xf;
107  double * epsx;
108  double epsf;
109  double * r;
110  double * J;
111  double S;
112  double * A;
113  double * v;
114  double * D;
115  double Rlo;
116  double Rhi;
117  double l;
118  double lc;
119  double * d;
120  int iter;
121  double * xd;
122  double * rd;
123  double Sd;
124  double dS;
125  double R;
126  double nu;
127  double* d_T;
128  double* J_T;
129  double* tmp;
130  double* rd_T;
131  gsl_matrix* D_pinv;
132  gsl_vector* A_d;
133  gsl_matrix* A_inv;
134  gsl_vector* A_inv_diag;
135  gsl_vector* r_T;
137 
146 
155 
166 void ccl_learn_ncl(const double * X, const double *Y, const int dim_x, const int dim_y, const int dim_n, const int dim_b, LEARN_NCL_MODEL *model);
167 
175 void ccl_learn_model_dir(LEARN_NCL_MODEL *model, const double *BX, const double *Y);
176 
185 
194 
204 void obj_ncl(const LEARN_NCL_MODEL *model, const double* W, const double*BX, const double*Y, double*fun,double* J);
205 
213 void obj_ws_alloc(const LEARN_NCL_MODEL *model,OBJ_WS* ws);
214 
222 void obj_ws_free(OBJ_WS* ws);
223 
233 void ccl_lsqnonlin(const LEARN_NCL_MODEL* model,const double* BX, const double*Y, const OPTION option,SOLVE_NONLIN_WS * lm_ws_param, double* W);
234 
243 
252 
259 void predict_ncl(const LEARN_NCL_MODEL* model, const double* BX, double* Unp);
260 
265 int ccl_write_ncl_model(char* filename, LEARN_NCL_MODEL *model);
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif
270 
void obj_ws_free(OBJ_WS *ws)
Free the memory for OBJ_WS structure.
int ccl_learn_ncl_model_free(LEARN_NCL_MODEL *model)
Free the memory for the learn_ncl model.
gsl_matrix * D
Diagobal matrix with eigen values of H.
Definition: ccl_learn_ncl.h:59
int dim_y
The dimensionality of the action space.
Definition: ccl_learn_ncl.h:33
double dS
The denomitor of the sqaured error is xd is taken.
Definition: ccl_learn_ncl.h:124
gsl_vector * b_n
A col vector of BX.
Definition: ccl_learn_ncl.h:74
void obj_ws_alloc(const LEARN_NCL_MODEL *model, OBJ_WS *ws)
Allocates the memory for OBJ_WS structure.
int dim_n
The number of data points.
Definition: ccl_learn_ncl.h:99
double * rd
The residual error at xd.
Definition: ccl_learn_ncl.h:122
gsl_matrix * w_
Model parameters.
Definition: ccl_learn_ncl.h:56
double * r
The returned value of the residual error.
Definition: ccl_learn_ncl.h:109
double S
The sqaure root if x is taken.
Definition: ccl_learn_ncl.h:111
double * v
The dot product of J_T and r.
Definition: ccl_learn_ncl.h:113
gsl_matrix * H
Dot product of BX and BX'.
Definition: ccl_learn_ncl.h:53
int ccl_solve_nonlin_ws_alloc(const LEARN_NCL_MODEL *model, SOLVE_NONLIN_WS *lm_ws)
Allocates the memory for SOLVE_NONLIN_WS structure.
gsl_vector * j_n_flt
Flattened jacobian vector.
Definition: ccl_learn_ncl.h:85
double Rlo
The lower bound of R.
Definition: ccl_learn_ncl.h:115
void ccl_lsqnonlin(const LEARN_NCL_MODEL *model, const double *BX, const double *Y, const OPTION option, SOLVE_NONLIN_WS *lm_ws_param, double *W)
Computation routine for optimizing non-linear objective functions using LM approach.
gsl_matrix * Y_T
Transpose of Y_.
Definition: ccl_learn_ncl.h:51
This structure describes workspace for directly learning the model parameters using linear regression...
Definition: ccl_learn_ncl.h:48
double * c
The mean of the rbf.
Definition: ccl_learn_ncl.h:35
gsl_vector * V
Eigen vector of H.
Definition: ccl_learn_ncl.h:58
int dim_x
The dimensionality of the state space.
Definition: ccl_learn_ncl.h:32
gsl_matrix * tmp2
A temporal matrix.
Definition: ccl_learn_ncl.h:86
double * d_T
The matrix transpose of d.
Definition: ccl_learn_ncl.h:127
int ccl_learn_model_ws_alloc(LEARN_NCL_MODEL *model, LEARN_MODEL_WS *ws)
Allocates the memory for LEARN_MODEL_WS structure.
void ccl_learn_ncl(const double *X, const double *Y, const int dim_x, const int dim_y, const int dim_n, const int dim_b, LEARN_NCL_MODEL *model)
Computation routine for learn nullspace component .
gsl_matrix * j_n
Row vector of analytic jacobian.
Definition: ccl_learn_ncl.h:84
double * x
The flattened and updated model parameters.
Definition: ccl_learn_ncl.h:105
double l
The adaptive learning rate.
Definition: ccl_learn_ncl.h:117
double * epsx
The tolerence of the model paramters.
Definition: ccl_learn_ncl.h:107
gsl_vector * A_inv_diag
The vector of diagonal elements of A matrix.
Definition: ccl_learn_ncl.h:134
int iter
The iteration number.
Definition: ccl_learn_ncl.h:120
double * A
The dot product of J_T and J.
Definition: ccl_learn_ncl.h:112
double R
The reduction if xd is taken.
Definition: ccl_learn_ncl.h:125
gsl_matrix * Y_
Observation actions.
Definition: ccl_learn_ncl.h:79
double a
Dot product of u_n' and Wb.
Definition: ccl_learn_ncl.h:83
gsl_matrix * g
Dot product of BX and U.
Definition: ccl_learn_ncl.h:50
int dim_b
The number of basis functions.
Definition: ccl_learn_ncl.h:31
int ccl_solve_nonlin_ws_free(SOLVE_NONLIN_WS *lm_ws)
Free the memory for SOLVE_NONLIN_WS structure.
double tmp
A temporal scalar.
Definition: ccl_learn_ncl.h:87
int dim_b
The number of basis functions.
Definition: ccl_learn_ncl.h:100
double Sd
The squared error if xd is taken.
Definition: ccl_learn_ncl.h:123
double * w
The model parameters for learning nullspace component.
Definition: ccl_learn_ncl.h:37
gsl_matrix * Wb_T
Transpose of Wb.
Definition: ccl_learn_ncl.h:81
gsl_matrix * HS
Regularization basis for the H matrix.
Definition: ccl_learn_ncl.h:49
double epsf
The tolerence fo the objective functions.
Definition: ccl_learn_ncl.h:108
double * J_T
The matrix transpose of J.
Definition: ccl_learn_ncl.h:128
gsl_matrix * A_inv
The peudo-inverse of A.
Definition: ccl_learn_ncl.h:133
double c
Dot product of Wb' and Wb.
Definition: ccl_learn_ncl.h:82
int d_ok
check if the model parameters are belowed the tolerence
Definition: ccl_learn_ncl.h:103
double * xd
The next x.
Definition: ccl_learn_ncl.h:121
gsl_matrix * BX_T
Transpose of BX_.
Definition: ccl_learn_ncl.h:54
gsl_matrix * u_n_T
Transpose of u_n.
Definition: ccl_learn_ncl.h:77
gsl_matrix * pinvH1
Peuso inverse of H1.
Definition: ccl_learn_ncl.h:57
int dim_y
The dimensionality of the action space.
Definition: ccl_learn_ncl.h:101
int r_ok
check if the objective function is belowed the tolerence
Definition: ccl_learn_ncl.h:102
double s2
The variance of the rbf.
Definition: ccl_learn_ncl.h:36
double * W_
A copy of model parameters.
Definition: ccl_learn_ncl.h:72
This structure describes a "LEARN_NCL_MODEL" (a learn ncl model). This structure constains the diment...
Definition: ccl_learn_ncl.h:30
double * D
Automatic scaling.
Definition: ccl_learn_ncl.h:114
int dim_x
The dimensionality of the state variable.
Definition: ccl_learn_ncl.h:98
CCL header file for math.
gsl_matrix * J
Jacobian matrix.
Definition: ccl_learn_ncl.h:73
double * W
Model parameters.
Definition: ccl_learn_ncl.h:71
double * xc
A copy of the initial model parameters.
Definition: ccl_learn_ncl.h:104
gsl_matrix * BX_
High dimensionality of the input data.
Definition: ccl_learn_ncl.h:55
This structure defines the workspace variables for calculating objective functions.
Definition: ccl_learn_ncl.h:70
int ccl_learn_ncl_model_alloc(LEARN_NCL_MODEL *model)
Allocates the memory for the learn_ncl model.
gsl_matrix * D_pinv
The peudo-inverse of D.
Definition: ccl_learn_ncl.h:131
double nu
The coefficient of changing learning rate.
Definition: ccl_learn_ncl.h:126
CCL header file for learning state dependent constraint.
int * idx
index
Definition: ccl_learn_ncl.h:60
void obj_ncl(const LEARN_NCL_MODEL *model, const double *W, const double *BX, const double *Y, double *fun, double *J)
Computation routine for calculating residual errors.
gsl_matrix * b_n_T
Transpose of BX.
Definition: ccl_learn_ncl.h:75
double lc
Handling situation when learning rate happends to be 0.
Definition: ccl_learn_ncl.h:118
gsl_matrix * BX_
Higher dimensionality of input variable.
Definition: ccl_learn_ncl.h:78
int ccl_learn_model_ws_free(LEARN_MODEL_WS *ws)
Free the memory for LEARN_MODEL_WS structure.
This structure defines the OPTION for the optimizer.
Definition: ccl_learn_alpha.h:145
void ccl_learn_model_dir(LEARN_NCL_MODEL *model, const double *BX, const double *Y)
Computation routine for calculating residual errors.
double * rd_T
The matrix transpose of rd.
Definition: ccl_learn_ncl.h:130
double * xf
The finalised model parameters.
Definition: ccl_learn_ncl.h:106
gsl_matrix * Y_
Output variable.
Definition: ccl_learn_ncl.h:52
This structure defines the workspace variables for solving the non-linear LM optimization.
Definition: ccl_learn_ncl.h:97
int dim_n
The number of data points.
Definition: ccl_learn_ncl.h:34
double * tmp
The temporal variable.
Definition: ccl_learn_ncl.h:129
int ccl_write_ncl_model(char *filename, LEARN_NCL_MODEL *model)
Write model parameters to .txt file.
double Rhi
The upper bound of R.
Definition: ccl_learn_ncl.h:116
void predict_ncl(const LEARN_NCL_MODEL *model, const double *BX, double *Unp)
Prediction of nullspace components.
gsl_vector * A_d
The A matrix at xd.
Definition: ccl_learn_ncl.h:132
gsl_vector * Wb
Dot product of w and b.
Definition: ccl_learn_ncl.h:80
double * d
The parameter improvement gradient.
Definition: ccl_learn_ncl.h:119
gsl_vector * u_n
A col vector of u.
Definition: ccl_learn_ncl.h:76
gsl_vector * r_T
The vector transpose of r.
Definition: ccl_learn_ncl.h:135
double * J
The jacobian at x.
Definition: ccl_learn_ncl.h:110