RejectionStrategy.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2012 Sergey Lisitsyn
00008  * Copyright (C) 2012 Sergey Lisitsyn
00009  */
00010 
00011 #ifndef _REJECTIONSTRATEGY_H___
00012 #define _REJECTIONSTRATEGY_H___
00013 
00014 namespace shogun
00015 {
00016 
00018 class CRejectionStrategy : public CSGObject
00019 {
00020     public:
00022         CRejectionStrategy() { };
00023 
00025         virtual ~CRejectionStrategy() { };
00026 
00028         virtual const char* get_name() const
00029         {
00030                 return "RejectionStrategy";
00031         };
00032 
00034         virtual bool reject(SGVector<float64_t> outputs) const = 0;
00035 
00036 };
00037 
00039 class CThresholdRejectionStrategy : public CRejectionStrategy
00040 {
00041     public:
00042 
00044         CThresholdRejectionStrategy() :
00045             CRejectionStrategy(), m_threshold(0.0) { };
00046 
00048         CThresholdRejectionStrategy(float64_t threshold) :
00049             CRejectionStrategy(), m_threshold(threshold) { };
00050 
00051         virtual ~CThresholdRejectionStrategy() {};
00052 
00054         virtual const char* get_name() const
00055         {
00056             return "ThresholdRejectionStrategy";
00057         }
00058 
00060         virtual bool reject(SGVector<float64_t> outputs) const
00061         {
00062             for (int32_t i=0; i<outputs.vlen; i++)
00063             {
00064                 if (outputs[i]>m_threshold)
00065                     return false;
00066             }
00067             return true;
00068         }
00069 
00070 protected:
00071 
00073         float64_t m_threshold;
00074 
00075 
00076 };
00077 
00078 static const float64_t Q_test_statistic_values[10][8] = 
00079 {
00080     /* 10,20,30,40,50,60,70,80,90,100 */
00081     {0.713,0.683,0.637,0.597,0.551,0.477,0.409,0.325},
00082     {0.627,0.604,0.568,0.538,0.503,0.450,0.401,0.339},
00083     {0.539,0.517,0.484,0.456,0.425,0.376,0.332,0.278},
00084     {0.490,0.469,0.438,0.412,0.382,0.337,0.295,0.246},
00085     {0.460,0.439,0.410,0.384,0.355,0.312,0.272,0.226},
00086     {0.437,0.417,0.388,0.363,0.336,0.294,0.256,0.211},
00087     {0.422,0.403,0.374,0.349,0.321,0.280,0.244,0.201},
00088     {0.408,0.389,0.360,0.337,0.310,0.270,0.234,0.192},
00089     {0.397,0.377,0.350,0.326,0.300,0.261,0.226,0.185},
00090     {0.387,0.368,0.341,0.317,0.292,0.253,0.219,0.179}
00091 };
00092 
00097 class CDixonQTestRejectionStrategy : public CRejectionStrategy
00098 {
00099     public:
00100 
00102         CDixonQTestRejectionStrategy() :
00103             CRejectionStrategy()
00104         {
00105             s_index = 3;
00106         }
00107         
00112         CDixonQTestRejectionStrategy(float64_t significance_level) :
00113             CRejectionStrategy()
00114         {   
00115             if (significance_level==0.001)
00116                 s_index = 0;
00117             else if (significance_level==0.002)
00118                 s_index = 1;
00119             else if (significance_level==0.005)
00120                 s_index = 2;
00121             else if (significance_level==0.01)
00122                 s_index = 3;
00123             else if (significance_level==0.02)
00124                 s_index = 4;
00125             else if (significance_level==0.05)
00126                 s_index = 5;
00127             else if (significance_level==0.1)
00128                 s_index = 6;
00129             else if (significance_level==0.2)
00130                 s_index = 7;
00131             else SG_ERROR("Given significance level is not supported");
00132         }
00133 
00134         virtual ~CDixonQTestRejectionStrategy() 
00135         {
00136         }
00137 
00139         virtual const char* get_name() const
00140         {
00141             return "DixonQTestRejectionStrategy";
00142         }
00143 
00145         virtual bool reject(SGVector<float64_t> outputs) const
00146         {
00147             int32_t N = outputs.vlen;
00148             if (N<10 || N>100) 
00149                 SG_ERROR("Given number of classes is not supported.");
00150 
00151             int32_t Ni = N/10 - 1;
00152 
00153             SGVector<float64_t> outputs_local = outputs.clone();
00154             CMath::qsort(outputs_local.vector,N);
00155 
00156             float64_t Q = 0.0;
00157             if (N==10)
00158                 Q = (outputs[N-1]-outputs[N-2])/(outputs[N-1]-outputs[0]);
00159 
00160             if (N>=20)
00161                 Q = (outputs[N-1]-outputs[N-4])/(outputs[N-1]-outputs[2]);
00162 
00163             if (Q>Q_test_statistic_values[Ni][s_index])
00164                 return false;
00165 
00166             return true;
00167         }
00168 
00169 private:
00170 
00171         int32_t s_index;
00172 
00173 };
00174 
00175 }
00176 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation