00001
00002
00003
00004
00005 #ifndef CORE_H
00006 #define CORE_H
00007
00008 #include <vector>
00009 #include "errors.h"
00010 #include "special.h"
00011 #include "data.h"
00012
00022 class PsiCore
00023 {
00024 public:
00025 virtual double g (
00026 double x,
00027 const std::vector<double>& prm
00028 ) const { throw NotImplementedError(); }
00029 virtual double dg (
00030 double x,
00031 const std::vector<double>& prm,
00032 int i
00033 ) const { throw NotImplementedError(); }
00034 virtual double dgx (
00035 double x,
00036 const std::vector<double>& prm
00037 ) const { throw NotImplementedError(); }
00038 virtual double ddg (
00039 double x,
00040 const std::vector<double>& prm,
00041 int i,
00042 int j
00043 ) const { throw NotImplementedError(); }
00044 virtual double inv (
00045 double y,
00046 const std::vector<double>& prm
00047 ) const { throw NotImplementedError(); }
00048 virtual double dinv (
00049 double p,
00050 const std::vector<double>& prm,
00051 int i
00052 ) const { throw NotImplementedError(); }
00053 virtual std::vector<double> transform (
00054 int nprm,
00055 double a,
00056 double b
00057 ) const {throw NotImplementedError();}
00058 virtual PsiCore * clone ( void ) const { throw NotImplementedError(); }
00059 static std::string getDescriptor ( void ) { throw NotImplementedError(); }
00060 };
00061
00070 class abCore : public PsiCore
00071 {
00072 private:
00073 public:
00074 abCore( const PsiData* data=NULL,
00075 const int sigmoid=1,
00076 const double alpha=0.1
00077 ) {}
00078 abCore( const abCore& original) {}
00079 double g (
00080 double x,
00081 const std::vector<double>& prm
00082 ) const { return (x-prm[0])/prm[1]; }
00083 double dg (
00084 double x,
00085 const std::vector<double>& prm,
00086 int i
00087 ) const ;
00088 double dgx (
00089 double x,
00090 const std::vector<double>& prm
00091 ) const;
00092 double ddg (
00093 double x,
00094 const std::vector<double>& prm,
00095 int i,
00096 int j
00097 ) const;
00098 double inv (
00099 double y,
00100 const std::vector<double>& prm
00101 ) const;
00102 double dinv (
00103 double p,
00104 const std::vector<double>& prm,
00105 int i
00106 ) const;
00107 std::vector<double> transform (
00108 int nprm,
00109 double a,
00110 double b
00111 ) const;
00112 PsiCore * clone ( void ) const {
00113 return new abCore(*this);
00114 }
00115 static std::string getDescriptor ( void ) {
00116 return "ab";
00117 }
00118 };
00119
00127 class mwCore : public PsiCore
00128 {
00129 private:
00130 int sigmtype;
00131 double alpha;
00132 double zalpha;
00133 double zshift;
00134 public:
00135 mwCore( const PsiData* data=NULL,
00136 const int sigmoid=1,
00137 const double alpha=0.1
00138 );
00139 mwCore( const mwCore& original ) : sigmtype(original.sigmtype),
00140 alpha(original.alpha),
00141 zalpha(original.zalpha),
00142 zshift(original.zshift) {}
00143 double g (
00144 double x,
00145 const std::vector<double>& prm
00146 ) const;
00147 double dg (
00148 double x,
00149 const std::vector<double>& prm,
00150 int i
00151 ) const;
00152 double dgx (
00153 double x,
00154 const std::vector<double>& prm
00155 ) const;
00156 double ddg (
00157 double x,
00158 const std::vector<double>& prm,
00159 int i,
00160 int j
00161 ) const;
00162 double inv (
00163 double y,
00164 const std::vector<double>& prm
00165 ) const;
00166 double dinv (
00167 double p,
00168 const std::vector<double>& prm,
00169 int i
00170 ) const;
00171 std::vector<double> transform (
00172 int nprm,
00173 double a,
00174 double b
00175 ) const;
00176 PsiCore * clone ( void ) const {
00177 return new mwCore(*this);
00178 }
00179 static std::string getDescriptor ( void ) {
00180 return "mw";
00181 }
00182 double getAlpha( void ) const {
00183 return alpha;
00184 }
00185 };
00186
00194 class linearCore : public PsiCore
00195 {
00196 public:
00197 linearCore( const PsiData* data=NULL,
00198 const int sigmoid=1,
00199 const double alpha=0.1
00200 ) {}
00201 linearCore( const linearCore& original ) {}
00202 double g (
00203 double x,
00204 const std::vector<double>& prm
00205 ) const { return prm[0] * x + prm[1]; }
00206 double dg (
00207 double x,
00208 const std::vector<double>& prm,
00209 int i
00210 ) const { switch (i) { case 0: return x; break; case 1: return 1; break; default: return 0; break; } }
00211 double dgx (
00212 double x,
00213 const std::vector<double>& prm
00214 ) const { return prm[0]; }
00215 double ddg (
00216 double x,
00217 const std::vector<double>& prm,
00218 int i,
00219 int j
00220 ) const { return 0; }
00221 double inv (
00222 double y,
00223 const std::vector<double>& prm
00224 ) const { return (y-prm[1])/prm[0]; }
00225 double dinv (
00226 double y,
00227 const std::vector<double>& prm,
00228 int i
00229 ) const { switch (i) { case 0: return (prm[1]-y)/(prm[0]*prm[0]); break; case 1: return -1./prm[0]; break; default: return 0; break; } }
00230 std::vector<double> transform (
00231 int nprm,
00232 double a,
00233 double b
00234 ) const { std::vector<double> out (nprm,0); out[0] = b; out[1] = a; return out; }
00235 PsiCore * clone ( void ) const {
00236 return new linearCore(*this);
00237 }
00238 static std::string getDescriptor ( void ) {
00239 return "linear";
00240 }
00241 };
00242
00249 class logCore : public PsiCore
00250 {
00251 private:
00252 double scale;
00253 public:
00254 logCore( const PsiData* data=NULL,
00255 const int sigmoid=1,
00256 const double alpha=0.1
00257 );
00258 logCore ( const logCore& original) : scale(original.scale) {}
00259 double g (
00260 double x,
00261 const std::vector<double>& prm
00262 ) const throw(BadArgumentError);
00263 double dg (
00264 double x,
00265 const std::vector<double>& prm,
00266 int i
00267 ) const;
00268 double dgx (
00269 double x,
00270 const std::vector<double>& prm
00271 ) const;
00272 double ddg (
00273 double x,
00274 const std::vector<double>& prm,
00275 int i,
00276 int j
00277 ) const { return 0; }
00278 double inv (
00279 double y,
00280 const std::vector<double>& prm
00281 ) const { return exp((y-prm[1])/prm[0]); }
00282 double dinv (
00283 double y,
00284 const std::vector<double>& prm,
00285 int i
00286 ) const;
00287 std::vector<double> transform (
00288 int nprm,
00289 double a,
00290 double b
00291 ) const;
00292 PsiCore * clone ( void ) const {
00293 return new logCore(*this);
00294 }
00295 static std::string getDescriptor ( void ) {
00296 return "log";
00297 }
00298 };
00299
00307 class weibullCore : public PsiCore
00308 {
00309 private:
00310 double twooverlog2;
00311 double loglog2;
00312 double loglina;
00313 double loglinb;
00314 public:
00315 weibullCore( const PsiData* data=NULL,
00316 const int sigmoid=1,
00317 const double alpha=0.1
00318 );
00319 weibullCore ( const weibullCore& original ) : twooverlog2(original.twooverlog2),
00320 loglog2(original.loglog2),
00321 loglina(original.loglina),
00322 loglinb(original.loglinb) {}
00323 double g (
00324 double x,
00325 const std::vector<double>& prm
00326 ) const { return twooverlog2*prm[0]*prm[1] * (log(x)-log(prm[0])) + loglog2; }
00327 double dg (
00328 double x,
00329 const std::vector<double>& prm,
00330 int i
00331 ) const throw(BadArgumentError) ;
00332 double dgx (
00333 double x,
00334 const std::vector<double>& prm
00335 ) const;
00336 double ddg (
00337 double x,
00338 const std::vector<double>& prm,
00339 int i,
00340 int j
00341 ) const throw(BadArgumentError) ;
00342 double inv (
00343 double y,
00344 const std::vector<double>& prm
00345 ) const;
00346 double dinv (
00347 double y,
00348 const std::vector<double>& prm,
00349 int i
00350 ) const;
00351 std::vector<double> transform (
00352 int nprm,
00353 double a,
00354 double b
00355 ) const;
00356 PsiCore * clone ( void ) const {
00357 return new weibullCore(*this);
00358 }
00359 static std::string getDescriptor ( void ) {
00360 return "weibull";
00361 }
00362 };
00363
00369 class polyCore : public PsiCore
00370 {
00371 private:
00372 double x1;
00373 double x2;
00374 public:
00375 polyCore( const PsiData* data=NULL,
00376 const int sigmoid=1,
00377 const double alpha=0.1
00378 );
00379 polyCore ( const polyCore& original ) : x1(original.x1),
00380 x2(original.x2) {}
00381 double g (
00382 double x,
00383 const std::vector<double>& prm
00384 ) const { return pow( x/prm[0], prm[1] ); }
00385 double dg (
00386 double x,
00387 const std::vector<double>& prm,
00388 int i
00389 ) const;
00390 double dgx (
00391 double x,
00392 const std::vector<double>& prm
00393 ) const;
00394 double ddg (
00395 double x,
00396 const std::vector<double>& prm,
00397 int i,
00398 int j
00399 ) const;
00400 double inv (
00401 double y,
00402 const std::vector<double>& prm
00403 ) const;
00404 double dinv (
00405 double y,
00406 const std::vector<double>& prm,
00407 int i
00408 ) const;
00409 std::vector<double> transform (
00410 int nprm,
00411 double a,
00412 double b
00413 ) const;
00414 PsiCore * clone ( void ) const {
00415 return new polyCore(*this);
00416 }
00417 static std::string getDescriptor ( void ) {
00418 return "poly";
00419 }
00420 };
00421
00428 class NakaRushton : public PsiCore
00429 {
00430 private:
00431 std::vector<double> x;
00432 public:
00433 NakaRushton (
00434 const PsiData* data=NULL,
00435 const int sigmoid=6,
00436 const double alpha=0.1
00437 );
00438 NakaRushton ( const NakaRushton& original ) : x ( original.x ) {}
00439
00440 double g (
00441 double x,
00442 const std::vector<double>& prm
00443 ) const { return (x<0 ? 0 : pow ( x, prm[1] ) / (pow(prm[0],prm[1])+pow(x,prm[1]))); }
00444 double dg (
00445 double x,
00446 const std::vector<double>& prm,
00447 int i
00448 ) const;
00449 double ddg (
00450 double x,
00451 const std::vector<double>& prm,
00452 int i,
00453 int j
00454 ) const;
00455 double dgx (
00456 double x,
00457 const std::vector<double>& prm
00458 ) const;
00459 double inv (
00460 double y,
00461 const std::vector<double>& prm
00462 ) const;
00463 double dinv (
00464 double y,
00465 const std::vector<double>& prm,
00466 int i
00467 ) const;
00468 std::vector<double> transform (
00469 int nprm,
00470 double a,
00471 double b
00472 ) const;
00473 PsiCore * clone ( void ) const {
00474 return new NakaRushton ( *this );
00475 }
00476 static std::string getDescriptor ( void ) {
00477 return "NakaRushton";
00478 }
00479 };
00480
00481 #endif