SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RejectionStrategy.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) 2012 Sergey Lisitsyn
8  * Copyright (C) 2012 Sergey Lisitsyn
9  */
10 
11 #ifndef _REJECTIONSTRATEGY_H___
12 #define _REJECTIONSTRATEGY_H___
13 
14 namespace shogun
15 {
16 
19 {
20  public:
23 
25  virtual ~CRejectionStrategy() { };
26 
28  virtual const char* get_name() const
29  {
30  return "RejectionStrategy";
31  };
32 
34  virtual bool reject(SGVector<float64_t> outputs) const = 0;
35 
36 };
37 
40 {
41  public:
42 
45  CRejectionStrategy(), m_threshold(0.0) { };
46 
49  CRejectionStrategy(), m_threshold(threshold) { };
50 
52 
54  virtual const char* get_name() const
55  {
56  return "ThresholdRejectionStrategy";
57  }
58 
60  virtual bool reject(SGVector<float64_t> outputs) const
61  {
62  for (int32_t i=0; i<outputs.vlen; i++)
63  {
64  if (outputs[i]>m_threshold)
65  return false;
66  }
67  return true;
68  }
69 
70 protected:
71 
74 
75 
76 };
77 
78 static const float64_t Q_test_statistic_values[10][8] =
79 {
80  /* 10,20,30,40,50,60,70,80,90,100 */
81  {0.713,0.683,0.637,0.597,0.551,0.477,0.409,0.325},
82  {0.627,0.604,0.568,0.538,0.503,0.450,0.401,0.339},
83  {0.539,0.517,0.484,0.456,0.425,0.376,0.332,0.278},
84  {0.490,0.469,0.438,0.412,0.382,0.337,0.295,0.246},
85  {0.460,0.439,0.410,0.384,0.355,0.312,0.272,0.226},
86  {0.437,0.417,0.388,0.363,0.336,0.294,0.256,0.211},
87  {0.422,0.403,0.374,0.349,0.321,0.280,0.244,0.201},
88  {0.408,0.389,0.360,0.337,0.310,0.270,0.234,0.192},
89  {0.397,0.377,0.350,0.326,0.300,0.261,0.226,0.185},
90  {0.387,0.368,0.341,0.317,0.292,0.253,0.219,0.179}
91 };
92 
98 {
99  public:
100 
104  {
105  s_index = 3;
106  }
107 
114  {
115  if (significance_level==0.001)
116  s_index = 0;
117  else if (significance_level==0.002)
118  s_index = 1;
119  else if (significance_level==0.005)
120  s_index = 2;
121  else if (significance_level==0.01)
122  s_index = 3;
123  else if (significance_level==0.02)
124  s_index = 4;
125  else if (significance_level==0.05)
126  s_index = 5;
127  else if (significance_level==0.1)
128  s_index = 6;
129  else if (significance_level==0.2)
130  s_index = 7;
131  else SG_ERROR("Given significance level is not supported")
132  }
133 
135  {
136  }
137 
139  virtual const char* get_name() const
140  {
141  return "DixonQTestRejectionStrategy";
142  }
143 
145  virtual bool reject(SGVector<float64_t> outputs) const
146  {
147  int32_t N = outputs.vlen;
148  if (N<10 || N>100)
149  SG_ERROR("Given number of classes is not supported.")
150 
151  int32_t Ni = N/10 - 1;
152 
153  SGVector<float64_t> outputs_local = outputs.clone();
154  outputs_local.qsort();
155 
156  float64_t Q = 0.0;
157  if (N==10)
158  Q = (outputs[N-1]-outputs[N-2])/(outputs[N-1]-outputs[0]);
159 
160  if (N>=20)
161  Q = (outputs[N-1]-outputs[N-4])/(outputs[N-1]-outputs[2]);
162 
163  if (Q>Q_test_statistic_values[Ni][s_index])
164  return false;
165 
166  return true;
167  }
168 
169 private:
170 
171  int32_t s_index;
172 
173 };
174 
175 }
176 #endif

SHOGUN Machine Learning Toolbox - Documentation