CCL Library  1.0
ccl_learn_nhat.h
Go to the documentation of this file.
1 
6 #ifndef __CCL_LEARN_NHAT_H
7 #define __CCL_LEARN_NHAT_H
8 
9 #include <ccl_math.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 
15 #define NUM_SEARCH 27000 // NUM_SEARCH = num_theta^{dim_t};
16 
18 #define NUM_CONSTRAINT 4 //NUM_CONSTRAINT = dim_u
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 #include <gsl/gsl_linalg.h>
23 #include <gsl/gsl_blas.h>
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_sf.h>
26 
34 typedef struct {
35  int dim_u;
36  int dim_n;
37  int num_theta;
38  int dim_t;
39  int dim_s;
40  double epsilon;
41  double *min_theta;
42  double *max_theta;
43  double *list;
44  double *I_u;
45  double *theta[NUM_SEARCH];
46  double *alpha[NUM_SEARCH];
47 } NHAT_search;
48 
56 typedef struct{
57  int dim_u;
58  int dim_n;
59  int dim_t;
60  int dim_c;
62  double *theta;
63  double *alpha;
64  double *P;
65  double variance;
66  double umse_j;
67  double nmse_j;
68 }NHAT_Model;
69 
77 typedef struct{
80 
91 int init_search_param(NHAT_search *search, int dim_u, int dim_n, int num_theta);
92 
101 
109 int nhat_mem_free_search(NHAT_search *search);
110 
119 int nhat_mem_alloc_model(NHAT_Model *model,const NHAT_search *search);
120 
128 int nhat_mem_free_model(NHAT_Model *model);
129 
138 int nhat_duplicate_model(NHAT_Model *dest, const NHAT_Model * src);
139 
146 void get_unit_vector(const double* theta, int dim_t,double *alpha);
147 
153 void generate_search_space(NHAT_search *search);
154 
163 void search_first_alpha(const double *Vn, const double *Un, NHAT_Model *model, const NHAT_search *search, double *stats);
164 
174 void search_alpha_nhat(const double *Vn, const double *Un, NHAT_Model *model, const NHAT_search *search, NHAT_Model *model_out,double *stats);
175 
183 void learn_nhat(const double *Un, const int dim_u, const int dim_n, NHAT_Model *optimal);
184 
192 void calclate_N(double * N, const double *A, int row, int col);
193 
203 int nhat_mem_alloc_result(NHAT_Model *model, const NHAT_search search, int dim_c);
204 
213 int nhat_mem_free_result(NHAT_result *result, int n_models);
214 
224 int nhat_mem_alloc_optimal(NHAT_Model *optimal,const NHAT_search search,int dim_c);
225 
233 int nhat_mem_free_optimal(NHAT_Model *optimal);
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif
238 
double * I_u
The identity matrix.
Definition: ccl_learn_nhat.h:44
void get_unit_vector(const double *theta, int dim_t, double *alpha)
Computation routine for generating unit vector for row vector alpha by given theta anlges...
int dim_u
The dimensionality of action space.
Definition: ccl_learn_nhat.h:57
This structure defines the searching parameters for NHAT_search.
Definition: ccl_learn_nhat.h:34
int nhat_mem_free_result(NHAT_result *result, int n_models)
Free the memory for model results.
double * list
A dictionary of search space and theta angles.
Definition: ccl_learn_nhat.h:43
int nhat_mem_alloc_model(NHAT_Model *model, const NHAT_search *search)
Allocates the memory for NHAT_Model.
int init_search_param(NHAT_search *search, int dim_u, int dim_n, int num_theta)
Initialisation of the searching parameters.
void learn_nhat(const double *Un, const int dim_u, const int dim_n, NHAT_Model *optimal)
Main computation routine for learn nhat.
int dim_c
The dimensionality of constraints.
Definition: ccl_learn_nhat.h:60
#define NUM_CONSTRAINT
Definition: ccl_learn_nhat.h:18
int nhat_mem_alloc_result(NHAT_Model *model, const NHAT_search search, int dim_c)
Allocates the memory for model results.
void search_alpha_nhat(const double *Vn, const double *Un, NHAT_Model *model, const NHAT_search *search, NHAT_Model *model_out, double *stats)
Search the rest rows of A matrix.
double * theta
Returned optimal theta parameters.
Definition: ccl_learn_nhat.h:62
double * alpha
Returned optimal alpha in unit vector.
Definition: ccl_learn_nhat.h:63
#define NUM_SEARCH
Definition: ccl_learn_nhat.h:15
void calclate_N(double *N, const double *A, int row, int col)
Calculation of nullspace projection matrix.
double nmse_j
The normalised mean sqaure error of residual error.
Definition: ccl_learn_nhat.h:67
int nhat_mem_free_model(NHAT_Model *model)
Free the memory for NHAT_Model.
This structure defines the model parameters for NHAT_Model.
Definition: ccl_learn_nhat.h:56
int dim_n
The number of data points.
Definition: ccl_learn_nhat.h:36
void search_first_alpha(const double *Vn, const double *Un, NHAT_Model *model, const NHAT_search *search, double *stats)
Search first row of A matrix.
int nhat_mem_free_search(NHAT_search *search)
Free the memory for NHAT_search.
CCL header file for math.
int nhat_duplicate_model(NHAT_Model *dest, const NHAT_Model *src)
Duplicate the NHAT_Model model from src to dest.
double * max_theta
The upper bound of theta angle.
Definition: ccl_learn_nhat.h:42
int dim_u
The dimensionality of action space.
Definition: ccl_learn_nhat.h:35
int dim_t
Number of parameters needed to represent a unit vector.
Definition: ccl_learn_nhat.h:38
double umse_j
The mean sqaure error of residual error.
Definition: ccl_learn_nhat.h:66
int nhat_mem_alloc_optimal(NHAT_Model *optimal, const NHAT_search search, int dim_c)
Allocates the memory for optimal model.
int dim_s
The dimensionality of the searching space.
Definition: ccl_learn_nhat.h:39
int nhat_mem_free_optimal(NHAT_Model *optimal)
Free the memory for optimal model.
int num_theta
Number of candidate constraints (from 0 to pi)
Definition: ccl_learn_nhat.h:37
int nhat_mem_alloc_search(NHAT_search *search)
Allocates the memory for NHAT_search.
double epsilon
Tolerance of seraching.
Definition: ccl_learn_nhat.h:40
double * P
Returned optimal projection matrix.
Definition: ccl_learn_nhat.h:64
double variance
Variance of nullspace components.
Definition: ccl_learn_nhat.h:65
int dim_t
Number of parameters needed to represent a unit vector.
Definition: ccl_learn_nhat.h:59
This structure defines the model parameters for NHAT_result.
Definition: ccl_learn_nhat.h:77
int dim_n
The number of data points.
Definition: ccl_learn_nhat.h:58
double * min_theta
The lower bound of theta angle.
Definition: ccl_learn_nhat.h:41
void generate_search_space(NHAT_search *search)
Generate search space.