00001 /* 00002 * See COPYING file distributed along with the psignifit package for 00003 * the copyright and license terms 00004 */ 00005 #ifndef SIGMOID_H 00006 #define SIGMOID_H 00007 00008 #include "errors.h" 00009 #include "special.h" 00010 #include <cmath> 00011 #include <string> 00012 00014 class PsiSigmoid 00015 { 00016 public: 00017 virtual double f ( double x ) const { throw NotImplementedError(); } 00018 virtual double df ( double x ) const { throw NotImplementedError(); } 00019 virtual double ddf ( double x ) const { throw NotImplementedError(); } 00020 virtual double inv ( double p ) const { throw NotImplementedError(); } 00021 virtual int getcode ( void ) const { throw NotImplementedError(); } 00022 virtual PsiSigmoid * clone ( void ) const { throw NotImplementedError(); } 00023 static std::string getDescriptor ( void ) { throw NotImplementedError(); } 00024 }; 00025 00033 class PsiId : public PsiSigmoid 00034 { 00035 public: 00036 double f ( double x ) const { return x; } 00037 double df ( double x ) const { return 1; } 00038 double ddf ( double x ) const { return 0; } 00039 double inv ( double x ) const { return x; } 00040 int getcode ( void ) const { return 6; } 00041 PsiSigmoid * clone ( void ) const { return new PsiId(*this); } 00042 static std::string getDescriptor ( void ) { return "id"; } 00043 }; 00044 00049 class PsiLogistic : public PsiSigmoid 00050 { 00051 public: 00052 PsiLogistic ( void ) {} 00053 PsiLogistic ( const PsiLogistic& original) {} 00054 double f ( double x ) const; 00055 double df ( double x ) const; 00056 double ddf ( double x ) const; 00057 double inv ( double p ) const { return log(p/(1-p)); } 00058 int getcode ( void ) const { return 1; } 00059 PsiSigmoid * clone ( void ) const { 00060 return new PsiLogistic(*this); 00061 } 00062 static std::string getDescriptor ( void ) { 00063 return "logistic"; 00064 } 00065 }; 00066 00071 class PsiGauss : public PsiSigmoid 00072 { 00073 public: 00074 PsiGauss ( void ) {} 00075 PsiGauss ( const PsiGauss& original) {} 00076 double f ( double x ) const; 00077 double df ( double x ) const; 00078 double ddf ( double x ) const; 00079 double inv ( double p ) const; 00080 int getcode ( void ) const { return 2; } 00081 PsiSigmoid * clone (void ) const { 00082 return new PsiGauss(*this); 00083 } 00084 static std::string getDescriptor ( void ) { 00085 return "gauss"; 00086 } 00087 }; 00088 00093 class PsiGumbelL : public PsiSigmoid 00094 { 00095 public: 00096 PsiGumbelL ( void ) {} 00097 PsiGumbelL ( const PsiGumbelL& original ) {} 00098 double f ( double x ) const; 00099 double df ( double x ) const; 00100 double ddf ( double x ) const; 00101 double inv ( double p ) const; 00102 int getcode ( void ) const { return 3; } 00103 PsiSigmoid * clone ( void ) const { 00104 return new PsiGumbelL(*this); 00105 } 00106 static std::string getDescriptor ( void ) { 00107 return "gumbel_l"; 00108 } 00109 }; 00110 00115 class PsiGumbelR : public PsiSigmoid 00116 { 00117 public: 00118 PsiGumbelR ( void ) {} 00119 PsiGumbelR ( const PsiGumbelR& original ) {} 00120 double f ( double x ) const; 00121 double df ( double x ) const; 00122 double ddf ( double x ) const; 00123 double inv ( double p ) const; 00124 int getcode ( void ) const { return 6; } 00125 PsiSigmoid * clone ( void ) const { 00126 return new PsiGumbelR(*this); 00127 } 00128 static std::string getDescriptor ( void ) { 00129 return "gumbel_r"; 00130 } 00131 }; 00132 00137 class PsiCauchy : public PsiSigmoid 00138 { 00139 public: 00140 PsiCauchy( void ) {} 00141 PsiCauchy( const PsiCauchy& oiginal) {} 00142 double f ( double x ) const; 00143 double df ( double x ) const; 00144 double ddf ( double x ) const; 00145 double inv ( double p ) const; 00146 int getcode ( void ) const { return 4; } 00147 PsiSigmoid * clone ( void ) const { 00148 return new PsiCauchy(*this); 00149 } 00150 static std::string getDescriptor ( void ) { 00151 return "cauchy"; 00152 } 00153 }; 00154 00160 class PsiExponential : public PsiSigmoid 00161 { 00162 public: 00163 PsiExponential( void ) {} 00164 PsiExponential( const PsiExponential& oiginal) {} 00165 double f (double x ) const; 00166 double df (double x ) const; 00167 double ddf (double x ) const; 00168 double inv (double p ) const throw(BadArgumentError); 00169 int getcode ( void ) const { return 5; } 00170 PsiSigmoid * clone ( void ) const { 00171 return new PsiExponential(*this); 00172 } 00173 static std::string getDescriptor ( void ) { 00174 return "exponential"; 00175 } 00176 }; 00177 00178 #endif