SHOGUN  v3.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>
15 #include <shogun/lib/SGVector.h>
18 
19 namespace shogun
20 {
21 
24 {
35 };
36 
38 class CPlif: public CPlifBase
39 {
40  public:
45  CPlif(int32_t len=0);
46  virtual ~CPlif();
47 
50 
58  float64_t p_value, float64_t *d_values) const;
59 
67  float64_t p_value, float64_t* svm_values) const;
68 
75  float64_t lookup_penalty(int32_t p_value, float64_t* svm_values) const;
76 
82  inline float64_t lookup(float64_t p_value)
83  {
84  ASSERT(use_svm == 0)
85  return lookup_penalty(p_value, NULL);
86  }
87 
90 
98  float64_t p_value, float64_t* svm_values, float64_t factor) ;
99 
106  void penalty_add_derivative(float64_t p_value, float64_t* svm_values, float64_t factor);
107 
113  const float64_t * get_cum_derivative(int32_t & p_len) const
114  {
115  p_len = len;
116  return cum_derivatives.vector;
117  }
118 
124  bool set_transform_type(const char *type_str);
125 
130  const char* get_transform_type()
131  {
132  if (transform== T_LINEAR)
133  return "linear";
134  else if (transform== T_LOG)
135  return "log";
136  else if (transform== T_LOG_PLUS1)
137  return "log(+1)";
138  else if (transform== T_LOG_PLUS3)
139  return "log(+3)";
140  else if (transform== T_LINEAR_PLUS3)
141  return "(+3)";
142  else
143  SG_ERROR("wrong type")
144  return "";
145  }
146 
147 
152  void set_id(int32_t p_id)
153  {
154  id=p_id;
155  }
156 
161  int32_t get_id() const
162  {
163  return id;
164  }
165 
170  int32_t get_max_id() const
171  {
172  return get_id();
173  }
174 
179  void set_use_svm(int32_t p_use_svm)
180  {
182  use_svm=p_use_svm;
183  }
184 
189  int32_t get_use_svm() const
190  {
191  return use_svm;
192  }
193 
198  virtual bool uses_svm_values() const
199  {
200  return (get_use_svm()!=0);
201  }
202 
207  void set_use_cache(int32_t p_use_cache)
208  {
210  use_cache=p_use_cache;
211  }
212 
216  {
217  SG_FREE(cache);
218  cache=NULL;
219  }
220 
225  int32_t get_use_cache()
226  {
227  return use_cache;
228  }
229 
236  void set_plif(
237  int32_t p_len, float64_t *p_limits, float64_t* p_penalties)
238  {
239  ASSERT(len==p_len)
240 
241  for (int32_t i=0; i<len; i++)
242  {
243  limits[i]=p_limits[i];
244  penalties[i]=p_penalties[i];
245  }
246 
249  }
250 
256  {
257  ASSERT(len==p_limits.vlen)
258 
259  limits = p_limits;
260 
263  }
264 
265 
271  {
272  ASSERT(len==p_penalties.vlen)
273 
274  penalties = p_penalties;
275 
278  }
279 
284  void set_plif_length(int32_t p_len)
285  {
286  if (len!=p_len)
287  {
288  len=p_len;
289 
290  SG_DEBUG("set_plif len=%i\n", p_len)
294  }
295 
296  for (int32_t i=0; i<len; i++)
297  {
298  limits[i]=0.0;
299  penalties[i]=0.0;
300  cum_derivatives[i]=0.0;
301  }
302 
305  }
306 
312  {
313  return limits;
314  }
315 
321  {
322  return penalties;
323  }
324 
329  inline void set_max_value(float64_t p_max_value)
330  {
331  max_value=p_max_value;
333  }
334 
339  virtual float64_t get_max_value() const
340  {
341  return max_value;
342  }
343 
348  inline void set_min_value(float64_t p_min_value)
349  {
350  min_value=p_min_value;
352  }
353 
358  virtual float64_t get_min_value() const
359  {
360  return min_value;
361  }
362 
367  void set_plif_name(char *p_name);
368 
373  char* get_plif_name() const;
374 
379  bool get_do_calc();
380 
385  void set_do_calc(bool b);
386 
390  void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
391 
396  inline int32_t get_plif_len()
397  {
398  return len;
399  }
400 
405  virtual void list_plif() const
406  {
407  SG_PRINT("CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n", min_value, max_value, use_svm)
408  }
409 
415  static void delete_penalty_struct(CPlif** PEN, int32_t P);
416 
418  virtual const char* get_name() const { return "Plif"; }
419 
420  protected:
422  int32_t len;
438  int32_t id;
440  char * name;
442  int32_t use_svm;
444  bool use_cache;
448  bool do_calc;
449 };
450 }
451 #endif

SHOGUN Machine Learning Toolbox - Documentation