yat
0.8.3pre
|
00001 #ifndef _theplu_yat_statistics_sam_score_ 00002 #define _theplu_yat_statistics_sam_score_ 00003 00004 // $Id: SAMScore.h 2119 2009-12-12 23:11:43Z peter $ 00005 00006 /* 00007 Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson 00008 00009 This file is part of the yat library, http://dev.thep.lu.se/yat 00010 00011 The yat library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 3 of the 00014 License, or (at your option) any later version. 00015 00016 The yat library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with yat. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #include "Score.h" 00026 00027 #include <cmath> 00028 00029 namespace theplu { 00030 namespace yat { 00031 namespace utility { 00032 class VectorBase; 00033 } 00034 namespace classifier { 00035 class DataLookWeighted1D; 00036 } 00037 namespace statistics { 00038 00050 class SAMScore : public Score 00051 { 00052 00053 public: 00058 SAMScore(const double s0, bool absolute=true); 00059 00069 double score(const classifier::Target& target, 00070 const utility::VectorBase& value) const; 00071 00083 double score(const classifier::Target& target, 00084 const classifier::DataLookupWeighted1D& value) const; 00085 00097 double score(const classifier::Target& target, 00098 const utility::VectorBase& value, 00099 const utility::VectorBase& weight) const; 00100 private: 00101 double s0_; 00102 00103 template<class T> 00104 double score(const T& positive, const T& negative) const 00105 { 00106 if(positive.n()+negative.n()<=2) 00107 return 0; 00108 double diff = positive.mean() - negative.mean(); 00109 double s2 = ( (1.0/positive.n()+1.0/negative.n()) * 00110 (positive.sum_xx_centered()+negative.sum_xx_centered()) / 00111 (positive.n()+negative.n()-2) ); 00112 if (diff<0 && absolute_) 00113 return -diff/(sqrt(s2)+s0_); 00114 return diff/(sqrt(s2)+s0_); 00115 } 00116 }; 00117 00118 }}} // of namespace statistics, yat, and theplu 00119 00120 #endif