SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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.vector;
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  limits = p_limits;
259 
262  }
263 
264 
270  {
271  ASSERT(len==p_penalties.vlen);
272 
273  penalties = p_penalties;
274 
277  }
278 
283  void set_plif_length(int32_t p_len)
284  {
285  if (len!=p_len)
286  {
287  len=p_len;
288 
289  SG_DEBUG( "set_plif len=%i\n", p_len);
293  }
294 
295  for (int32_t i=0; i<len; i++)
296  {
297  limits[i]=0.0;
298  penalties[i]=0.0;
299  cum_derivatives[i]=0.0;
300  }
301 
304  }
305 
311  {
312  return limits.vector;
313  }
314 
320  {
321  return penalties.vector;
322  }
323 
328  inline void set_max_value(float64_t p_max_value)
329  {
330  max_value=p_max_value;
332  }
333 
338  virtual float64_t get_max_value() const
339  {
340  return max_value;
341  }
342 
347  inline void set_min_value(float64_t p_min_value)
348  {
349  min_value=p_min_value;
351  }
352 
357  virtual float64_t get_min_value() const
358  {
359  return min_value;
360  }
361 
366  void set_plif_name(char *p_name);
367 
372  inline char* get_plif_name() const
373  {
374  if (name)
375  return name;
376  else
377  {
378  char buf[20];
379  sprintf(buf, "plif%i", id);
380  //name = strdup(buf);
381  return strdup(buf);
382  }
383  }
384 
389  bool get_do_calc();
390 
395  void set_do_calc(bool b);
396 
400  void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
401 
406  inline int32_t get_plif_len()
407  {
408  return len;
409  }
410 
415  virtual void list_plif() const
416  {
417  SG_PRINT("CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n", min_value, max_value, use_svm) ;
418  }
419 
425  static void delete_penalty_struct(CPlif** PEN, int32_t P);
426 
428  inline virtual const char* get_name() const { return "Plif"; }
429 
430  protected:
432  int32_t len;
448  int32_t id;
450  char * name;
452  int32_t use_svm;
454  bool use_cache;
458  bool do_calc;
459 };
460 }
461 #endif

SHOGUN Machine Learning Toolbox - Documentation