SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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/common.h>
17 
18 namespace shogun
19 {
20 
23 {
34 };
35 
37 class CPlif: public CPlifBase
38 {
39  public:
44  CPlif(int32_t len=0);
45  virtual ~CPlif();
46 
49 
57  float64_t p_value, float64_t *d_values) const;
58 
66  float64_t p_value, float64_t* svm_values) const;
67 
74  float64_t lookup_penalty(int32_t p_value, float64_t* svm_values) const;
75 
81  inline float64_t lookup(float64_t p_value)
82  {
83  ASSERT(use_svm == 0);
84  return lookup_penalty(p_value, NULL);
85  }
86 
89 
97  float64_t p_value, float64_t* svm_values, float64_t factor) ;
98 
105  void penalty_add_derivative(float64_t p_value, float64_t* svm_values, float64_t factor);
106 
112  const float64_t * get_cum_derivative(int32_t & p_len) const
113  {
114  p_len = len;
115  return cum_derivatives;
116  }
117 
123  bool set_transform_type(const char *type_str);
124 
129  const char* get_transform_type()
130  {
131  if (transform== T_LINEAR)
132  return "linear";
133  else if (transform== T_LOG)
134  return "log";
135  else if (transform== T_LOG_PLUS1)
136  return "log(+1)";
137  else if (transform== T_LOG_PLUS3)
138  return "log(+3)";
139  else if (transform== T_LINEAR_PLUS3)
140  return "(+3)";
141  else
142  SG_ERROR("wrong type");
143  return "";
144  }
145 
146 
151  void set_id(int32_t p_id)
152  {
153  id=p_id;
154  }
155 
160  int32_t get_id() const
161  {
162  return id;
163  }
164 
169  int32_t get_max_id() const
170  {
171  return get_id();
172  }
173 
178  void set_use_svm(int32_t p_use_svm)
179  {
181  use_svm=p_use_svm;
182  }
183 
188  int32_t get_use_svm() const
189  {
190  return use_svm;
191  }
192 
197  virtual bool uses_svm_values() const
198  {
199  return (get_use_svm()!=0);
200  }
201 
206  void set_use_cache(int32_t p_use_cache)
207  {
209  use_cache=p_use_cache;
210  }
211 
215  {
216  SG_FREE(cache);
217  cache=NULL;
218  }
219 
224  int32_t get_use_cache()
225  {
226  return use_cache;
227  }
228 
235  void set_plif(
236  int32_t p_len, float64_t *p_limits, float64_t* p_penalties)
237  {
238  ASSERT(len==p_len);
239 
240  for (int32_t i=0; i<len; i++)
241  {
242  limits[i]=p_limits[i];
243  penalties[i]=p_penalties[i];
244  }
245 
248  }
249 
255  {
256  ASSERT(len==p_limits.vlen);
257 
258  for (int32_t i=0; i<len; i++)
259  limits[i]=p_limits.vector[i];
260 
263  }
264 
265 
271  {
272  ASSERT(len==p_penalties.vlen);
273 
274  for (int32_t i=0; i<len; i++)
275  penalties[i]=p_penalties.vector[i];
276 
279  }
280 
285  void set_plif_length(int32_t p_len)
286  {
287  if (len!=p_len)
288  {
289  len=p_len;
290  SG_FREE(limits);
293 
294  SG_DEBUG( "set_plif len=%i\n", p_len);
298  }
299 
300  for (int32_t i=0; i<len; i++)
301  {
302  limits[i]=0.0;
303  penalties[i]=0.0;
304  }
305 
308  }
309 
315  {
316  return limits;
317  }
318 
324  {
325  return penalties;
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  inline char* get_plif_name() const
376  {
377  if (name)
378  return name;
379  else
380  {
381  char buf[20];
382  sprintf(buf, "plif%i", id);
383  //name = strdup(buf);
384  return strdup(buf);
385  }
386  }
387 
392  bool get_do_calc();
393 
398  void set_do_calc(bool b);
399 
403  void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
404 
409  inline int32_t get_plif_len()
410  {
411  return len;
412  }
413 
418  virtual void list_plif() const
419  {
420  SG_PRINT("CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n", min_value, max_value, use_svm) ;
421  }
422 
428  static void delete_penalty_struct(CPlif** PEN, int32_t P);
429 
431  inline virtual const char* get_name() const { return "Plif"; }
432 
433  protected:
435  int32_t len;
451  int32_t id;
453  char * name;
455  int32_t use_svm;
457  bool use_cache;
461  bool do_calc;
462 };
463 }
464 #endif

SHOGUN Machine Learning Toolbox - Documentation