SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Plif.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2008 Gunnar Raetsch
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef __PLIF_H__
12 #define __PLIF_H__
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/lib/common.h>
17 #include <shogun/lib/SGVector.h>
20 
21 namespace shogun
22 {
23 
26 {
37 };
38 
40 class CPlif: public CPlifBase
41 {
42  public:
47  CPlif(int32_t len=0);
48  virtual ~CPlif();
49 
52 
60  float64_t p_value, float64_t *d_values) const;
61 
69  float64_t p_value, float64_t* svm_values) const;
70 
77  float64_t lookup_penalty(int32_t p_value, float64_t* svm_values) const;
78 
84  inline float64_t lookup(float64_t p_value)
85  {
86  ASSERT(use_svm == 0)
87  return lookup_penalty(p_value, NULL);
88  }
89 
92 
100  float64_t p_value, float64_t* svm_values, float64_t factor) ;
101 
108  void penalty_add_derivative(float64_t p_value, float64_t* svm_values, float64_t factor);
109 
115  const float64_t * get_cum_derivative(int32_t & p_len) const
116  {
117  p_len = len;
118  return cum_derivatives.vector;
119  }
120 
126  bool set_transform_type(const char *type_str);
127 
132  const char* get_transform_type()
133  {
134  if (transform== T_LINEAR)
135  return "linear";
136  else if (transform== T_LOG)
137  return "log";
138  else if (transform== T_LOG_PLUS1)
139  return "log(+1)";
140  else if (transform== T_LOG_PLUS3)
141  return "log(+3)";
142  else if (transform== T_LINEAR_PLUS3)
143  return "(+3)";
144  else
145  SG_ERROR("wrong type")
146  return "";
147  }
148 
149 
154  void set_id(int32_t p_id)
155  {
156  id=p_id;
157  }
158 
163  int32_t get_id() const
164  {
165  return id;
166  }
167 
172  int32_t get_max_id() const
173  {
174  return get_id();
175  }
176 
181  void set_use_svm(int32_t p_use_svm)
182  {
184  use_svm=p_use_svm;
185  }
186 
191  int32_t get_use_svm() const
192  {
193  return use_svm;
194  }
195 
200  virtual bool uses_svm_values() const
201  {
202  return (get_use_svm()!=0);
203  }
204 
209  void set_use_cache(int32_t p_use_cache)
210  {
212  use_cache=p_use_cache;
213  }
214 
218  {
219  SG_FREE(cache);
220  cache=NULL;
221  }
222 
227  int32_t get_use_cache()
228  {
229  return use_cache;
230  }
231 
238  void set_plif(
239  int32_t p_len, float64_t *p_limits, float64_t* p_penalties)
240  {
241  ASSERT(len==p_len)
242 
243  for (int32_t i=0; i<len; i++)
244  {
245  limits[i]=p_limits[i];
246  penalties[i]=p_penalties[i];
247  }
248 
251  }
252 
258  {
259  ASSERT(len==p_limits.vlen)
260 
261  limits = p_limits;
262 
265  }
266 
267 
273  {
274  ASSERT(len==p_penalties.vlen)
275 
276  penalties = p_penalties;
277 
280  }
281 
286  void set_plif_length(int32_t p_len)
287  {
288  if (len!=p_len)
289  {
290  len=p_len;
291 
292  SG_DEBUG("set_plif len=%i\n", p_len)
296  }
297 
298  for (int32_t i=0; i<len; i++)
299  {
300  limits[i]=0.0;
301  penalties[i]=0.0;
302  cum_derivatives[i]=0.0;
303  }
304 
307  }
308 
314  {
315  return limits;
316  }
317 
323  {
324  return penalties;
325  }
326 
331  inline void set_max_value(float64_t p_max_value)
332  {
333  max_value=p_max_value;
335  }
336 
341  virtual float64_t get_max_value() const
342  {
343  return max_value;
344  }
345 
350  inline void set_min_value(float64_t p_min_value)
351  {
352  min_value=p_min_value;
354  }
355 
360  virtual float64_t get_min_value() const
361  {
362  return min_value;
363  }
364 
369  void set_plif_name(char *p_name);
370 
375  char* get_plif_name() const;
376 
381  bool get_do_calc();
382 
387  void set_do_calc(bool b);
388 
392  void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
393 
398  inline int32_t get_plif_len()
399  {
400  return len;
401  }
402 
407  virtual void list_plif() const
408  {
409  SG_PRINT("CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n", min_value, max_value, use_svm)
410  }
411 
417  static void delete_penalty_struct(CPlif** PEN, int32_t P);
418 
420  virtual const char* get_name() const { return "Plif"; }
421 
422  protected:
424  int32_t len;
440  int32_t id;
442  char * name;
444  int32_t use_svm;
446  bool use_cache;
450  bool do_calc;
451 };
452 }
453 #endif
ETransformType
Definition: Plif.h:25
bool use_cache
Definition: Plif.h:446
Logarithmic.
Definition: Plif.h:30
void set_plif_penalty(SGVector< float64_t > p_penalties)
Definition: Plif.h:272
void penalty_clear_derivative()
Definition: Plif.cpp:283
void set_max_value(float64_t p_max_value)
Definition: Plif.h:331
void set_plif_name(char *p_name)
Definition: Plif.cpp:97
const char * get_transform_type()
Definition: Plif.h:132
char * get_plif_name() const
Definition: Plif.cpp:103
int32_t id
Definition: Plif.h:440
virtual bool uses_svm_values() const
Definition: Plif.h:200
#define SG_ERROR(...)
Definition: SGIO.h:129
int32_t get_plif_len()
Definition: Plif.h:398
void set_plif_limits(SGVector< float64_t > p_limits)
Definition: Plif.h:257
class Plif
Definition: Plif.h:40
float64_t lookup_penalty_svm(float64_t p_value, float64_t *d_values) const
Definition: Plif.cpp:122
Linear (3+x)
Definition: Plif.h:36
SGVector< float64_t > limits
Definition: Plif.h:426
virtual ~CPlif()
Definition: Plif.cpp:43
virtual void list_plif() const
Definition: Plif.h:407
Logarithmic (log(3+x))
Definition: Plif.h:34
index_t vlen
Definition: SGVector.h:492
#define SG_PRINT(...)
Definition: SGIO.h:137
#define ASSERT(x)
Definition: SGIO.h:201
virtual float64_t get_max_value() const
Definition: Plif.h:341
void invalidate_cache()
Definition: Plif.h:217
void get_used_svms(int32_t *num_svms, int32_t *svm_ids)
Definition: Plif.cpp:388
int32_t get_use_cache()
Definition: Plif.h:227
Logarithmic (log(1+x))
Definition: Plif.h:32
void set_use_cache(int32_t p_use_cache)
Definition: Plif.h:209
const float64_t * get_cum_derivative(int32_t &p_len) const
Definition: Plif.h:115
char * name
Definition: Plif.h:442
double float64_t
Definition: common.h:50
void penalty_add_derivative_svm(float64_t p_value, float64_t *svm_values, float64_t factor)
Definition: Plif.cpp:341
float64_t min_value
Definition: Plif.h:434
int32_t get_max_id() const
Definition: Plif.h:172
enum ETransformType transform
Definition: Plif.h:438
virtual const char * get_name() const
Definition: Plif.h:420
int32_t len
Definition: Plif.h:424
bool set_transform_type(const char *type_str)
Definition: Plif.cpp:49
int32_t get_use_svm() const
Definition: Plif.h:191
int32_t use_svm
Definition: Plif.h:444
class PlifBase
Definition: PlifBase.h:23
virtual float64_t get_min_value() const
Definition: Plif.h:360
void set_id(int32_t p_id)
Definition: Plif.h:154
SGVector< float64_t > get_plif_limits()
Definition: Plif.h:313
void set_plif(int32_t p_len, float64_t *p_limits, float64_t *p_penalties)
Definition: Plif.h:238
#define SG_DEBUG(...)
Definition: SGIO.h:107
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
SGVector< float64_t > get_plif_penalties()
Definition: Plif.h:322
void set_use_svm(int32_t p_use_svm)
Definition: Plif.h:181
void set_plif_length(int32_t p_len)
Definition: Plif.h:286
float64_t lookup(float64_t p_value)
Definition: Plif.h:84
bool do_calc
Definition: Plif.h:450
bool get_do_calc()
Definition: Plif.cpp:398
float64_t lookup_penalty(float64_t p_value, float64_t *svm_values) const
Definition: Plif.cpp:205
CPlif(int32_t len=0)
Definition: Plif.cpp:23
float64_t max_value
Definition: Plif.h:432
void set_min_value(float64_t p_min_value)
Definition: Plif.h:350
void penalty_add_derivative(float64_t p_value, float64_t *svm_values, float64_t factor)
Definition: Plif.cpp:289
int32_t get_id() const
Definition: Plif.h:163
Linear.
Definition: Plif.h:28
float64_t * cache
Definition: Plif.h:436
static void delete_penalty_struct(CPlif **PEN, int32_t P)
Definition: Plif.cpp:115
SGVector< float64_t > cum_derivatives
Definition: Plif.h:430
void set_do_calc(bool b)
Definition: Plif.cpp:403
SGVector< float64_t > penalties
Definition: Plif.h:428
void init_penalty_struct_cache()
Definition: Plif.cpp:73

SHOGUN Machine Learning Toolbox - Documentation