SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlifArray.cpp
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 #include <shogun/lib/config.h>
12 
13 #include <stdio.h>
14 #include <string.h>
15 
16 #include <shogun/io/SGIO.h>
17 
19 #include <shogun/structure/Plif.h>
20 
21 //#define PLIFARRAY_DEBUG
22 
23 using namespace shogun;
24 
26 : CPlifBase()
27 {
28  min_value=-1e6;
29  max_value=1e6;
30 }
31 
33 {
34 }
35 
37 {
38  ASSERT(new_plif);
39  m_array.append_element(new_plif) ;
40 
41  min_value = -1e6 ;
42  for (int32_t i=0; i<m_array.get_num_elements(); i++)
43  {
44  ASSERT(m_array[i]);
45  if (!m_array[i]->uses_svm_values())
47  }
48 
49  max_value = 1e6 ;
50  for (int32_t i=0; i<m_array.get_num_elements(); i++)
51  if (!m_array[i]->uses_svm_values())
53 }
54 
56 {
58  min_value = -1e6 ;
59  max_value = 1e6 ;
60 }
61 
63  float64_t p_value, float64_t* svm_values) const
64 {
65  //min_value = -1e6 ;
66  //max_value = 1e6 ;
67  if (p_value<min_value || p_value>max_value)
68  {
69  //SG_WARNING("lookup_penalty: p_value: %i min_value: %f, max_value: %f\n",p_value, min_value, max_value);
70  return -CMath::INFTY ;
71  }
72  float64_t ret = 0.0 ;
73  for (int32_t i=0; i<m_array.get_num_elements(); i++)
74  ret += m_array[i]->lookup_penalty(p_value, svm_values) ;
75  return ret ;
76 }
77 
79  int32_t p_value, float64_t* svm_values) const
80 {
81  //min_value = -1e6 ;
82  //max_value = 1e6 ;
83  if (p_value<min_value || p_value>max_value)
84  {
85  //SG_WARNING("lookup_penalty: p_value: %i min_value: %f, max_value: %f\n",p_value, min_value, max_value);
86  return -CMath::INFTY ;
87  }
88  float64_t ret = 0.0 ;
89  for (int32_t i=0; i<m_array.get_num_elements(); i++)
90  {
91  float64_t val = m_array[i]->lookup_penalty(p_value, svm_values) ;
92  ret += val ;
93 #ifdef PLIFARRAY_DEBUG
94  CPlif * plif = (CPlif*)m_array[i] ;
95  if (plif->get_use_svm())
96  SG_PRINT("penalty[%i]=%1.5f (use_svm=%i -> %1.5f)\n", i, val, plif->get_use_svm(), svm_values[plif->get_use_svm()-1]) ;
97  else
98  SG_PRINT("penalty[%i]=%1.5f\n", i, val) ;
99 #endif
100  }
101  return ret ;
102 }
103 
105 {
106  for (int32_t i=0; i<m_array.get_num_elements(); i++)
108 }
109 
111  float64_t p_value, float64_t* svm_values, float64_t factor)
112 {
113  for (int32_t i=0; i<m_array.get_num_elements(); i++)
114  m_array[i]->penalty_add_derivative(p_value, svm_values, factor) ;
115 }
116 
118 {
119  for (int32_t i=0; i<m_array.get_num_elements(); i++)
120  if (m_array[i]->uses_svm_values())
121  return true ;
122  return false ;
123 }
124 
125 int32_t CPlifArray::get_max_id() const
126 {
127  int32_t max_id = 0 ;
128  for (int32_t i=0; i<m_array.get_num_elements(); i++)
129  max_id = CMath::max(max_id, m_array[i]->get_max_id()) ;
130  return max_id ;
131 }
132 
133 void CPlifArray::get_used_svms(int32_t* num_svms, int32_t* svm_ids)
134 {
135  SG_PRINT("get_used_svms: num: %i \n",m_array.get_num_elements());
136  for (int32_t i=0; i<m_array.get_num_elements(); i++)
137  {
138  m_array[i]->get_used_svms(num_svms, svm_ids);
139  }
140  SG_PRINT("\n");
141 }

SHOGUN Machine Learning Toolbox - Documentation