Plif.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __PLIF_H__
00012 #define __PLIF_H__
00013
00014 #include "lib/common.h"
00015 #include "lib/Mathematics.h"
00016 #include "structure/PlifBase.h"
00017
00018 #include "lib/matlab.h"
00019
00020 enum ETransformType
00021 {
00022 T_LINEAR,
00023 T_LOG,
00024 T_LOG_PLUS1,
00025 T_LOG_PLUS3,
00026 T_LINEAR_PLUS3
00027 };
00028
00030 class CPlif: public CPlifBase
00031 {
00032 public:
00037 CPlif(int32_t len=0);
00038 ~CPlif();
00039
00041 void init_penalty_struct_cache();
00042
00049 float64_t lookup_penalty_svm(
00050 float64_t p_value, float64_t *d_values) const;
00051
00058 float64_t lookup_penalty(
00059 float64_t p_value, float64_t* svm_values) const;
00060
00067 float64_t lookup_penalty(int32_t p_value, float64_t* svm_values) const;
00068
00074 inline float64_t lookup(float64_t p_value)
00075 {
00076 ASSERT(use_svm == 0);
00077 return lookup_penalty(p_value, NULL);
00078 }
00079
00081 void penalty_clear_derivative();
00082
00088 void penalty_add_derivative_svm(
00089 float64_t p_value, float64_t* svm_values) ;
00090
00096 void penalty_add_derivative(float64_t p_value, float64_t* svm_values);
00097
00103 const float64_t * get_cum_derivative(int32_t & p_len) const
00104 {
00105 p_len = len;
00106 return cum_derivatives;
00107 }
00108
00114 bool set_transform_type(const char *type_str);
00115
00120 const char* get_transform_type()
00121 {
00122 if (transform== T_LINEAR)
00123 return "linear";
00124 else if (transform== T_LOG)
00125 return "log";
00126 else if (transform== T_LOG_PLUS1)
00127 return "log(+1)";
00128 else if (transform== T_LOG_PLUS3)
00129 return "log(+3)";
00130 else if (transform== T_LINEAR_PLUS3)
00131 return "(+3)";
00132 else
00133 SG_ERROR("wrong type");
00134 return "";
00135 }
00136
00137
00142 void set_id(int32_t p_id)
00143 {
00144 id=p_id;
00145 }
00146
00151 int32_t get_id() const
00152 {
00153 return id;
00154 }
00155
00160 int32_t get_max_id() const
00161 {
00162 return get_id();
00163 }
00164
00169 void set_use_svm(int32_t p_use_svm)
00170 {
00171 delete[] cache;
00172 cache=NULL;
00173 use_svm=p_use_svm;
00174 }
00175
00180 int32_t get_use_svm() const
00181 {
00182 return use_svm;
00183 }
00184
00189 virtual bool uses_svm_values() const
00190 {
00191 return (get_use_svm()!=0);
00192 }
00193
00198 void set_use_cache(int32_t p_use_cache)
00199 {
00200 delete[] cache;
00201 cache=NULL;
00202 use_cache=p_use_cache;
00203 }
00204
00209 int32_t get_use_cache()
00210 {
00211 return use_cache;
00212 }
00213
00222 void set_plif(
00223 int32_t p_len, float64_t *p_limits, float64_t* p_penalties)
00224 {
00225 len=p_len;
00226 delete[] limits;
00227 delete[] penalties;
00228 delete[] cum_derivatives;
00229 delete[] cache;
00230 cache=NULL;
00231
00232 limits=new float64_t[len];
00233 penalties=new float64_t[len];
00234 cum_derivatives=new float64_t[len];
00235
00236 for (int32_t i=0; i<len; i++)
00237 {
00238 limits[i]=p_limits[i];
00239 penalties[i]=p_penalties[i];
00240 }
00241
00242 penalty_clear_derivative();
00243 }
00244
00249 void set_plif_length(int32_t p_len)
00250 {
00251 if (len!=p_len)
00252 {
00253 len=p_len;
00254 delete[] limits;
00255 delete[] penalties;
00256 delete[] cum_derivatives;
00257 SG_DEBUG( "set_plif len=%i\n", p_len);
00258 limits=new float64_t[len];
00259 penalties=new float64_t[len];
00260 cum_derivatives=new float64_t[len];
00261 }
00262 delete[] cache;
00263 cache=NULL;
00264 for (int32_t i=0; i<len; i++)
00265 {
00266 limits[i]=0.0;
00267 penalties[i]=0.0;
00268 }
00269 penalty_clear_derivative();
00270 }
00271
00277 void set_plif_limits(float64_t* p_limits, int32_t p_len)
00278 {
00279 delete[] cache;
00280 cache=NULL;
00281 ASSERT(len==p_len);
00282
00283 for (int32_t i=0; i<len; i++)
00284 limits[i]=p_limits[i];
00285
00286 penalty_clear_derivative();
00287 }
00288
00293 float64_t* get_plif_limits()
00294 {
00295 return limits;
00296 }
00297
00303 void set_plif_penalty(float64_t* p_penalties, int32_t p_len)
00304 {
00305 delete[] cache;
00306 cache=NULL;
00307 ASSERT(len==p_len);
00308
00309 for (int32_t i=0; i<len; i++)
00310 penalties[i]=p_penalties[i];
00311
00312 penalty_clear_derivative();
00313 }
00318 float64_t* get_plif_penalties()
00319 {
00320 return penalties;
00321 }
00326 inline void set_max_value(float64_t p_max_value)
00327 {
00328 delete[] cache;
00329 cache=NULL;
00330 max_value=p_max_value;
00331 }
00332
00337 virtual float64_t get_max_value() const
00338 {
00339 return max_value;
00340 }
00341
00346 inline void set_min_value(float64_t p_min_value)
00347 {
00348 delete[] cache;
00349 cache=NULL;
00350 min_value=p_min_value;
00351 }
00352
00357 virtual float64_t get_min_value() const
00358 {
00359 return min_value;
00360 }
00361
00366 void set_name(char *p_name);
00367
00372 inline char * get_name() const
00373 {
00374 if (name)
00375 return name;
00376 else
00377 {
00378 char buf[20];
00379 sprintf(buf, "plif%i", id);
00380
00381 return strdup(buf);
00382 }
00383 }
00384
00389 bool get_do_calc();
00390
00395 void set_do_calc(bool b);
00396
00400 void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
00401
00406 inline int32_t get_plif_len()
00407 {
00408 return len;
00409 }
00410
00411 protected:
00413 int32_t len;
00415 float64_t *limits;
00417 float64_t *penalties;
00419 float64_t *cum_derivatives;
00421 float64_t max_value;
00423 float64_t min_value;
00425 float64_t *cache;
00427 enum ETransformType transform;
00429 int32_t id;
00431 char * name;
00433 int32_t use_svm;
00435 bool use_cache;
00439 bool do_calc;
00440 };
00441
00442 #ifdef HAVE_MATLAB
00443 CPlif** read_penalty_struct_from_cell(
00444 const mxArray * mx_penalty_info, int32_t P);
00445 #endif
00446
00447 void delete_penalty_struct(CPlif** PEN, int32_t P);
00448
00449 #endif