schwehr/density

Subversion checkout URL

You can clone with HTTPS or Subversion.

Older
100644 357 lines (284 sloc) 11.881 kb
 72ac9cd cleanup and LGPL license schwehr authored Sep 25, 2004 1 // $Revision$ $Author$ $Date$ 2 /* 3 Copyright (C) 2004 Kurt Schwehr 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 */ b155d68 Initial revision schwehr authored Sep 9, 2004 20 21 /* 22 23 Random: double gsl_ran_gaussian (const gsl_rng * r, double sigma) 24 25 This function returns a Gaussian random variate, with mean zero and 26 standard deviation sigma. The probability distribution for Gaussian 27 random variates is, 28 29 p(x) dx = {1 \over \sqrt{2 \pi \sigma^2}} \exp (-x^2 / 2\sigma^2) dx 30 31 for x in the range -\infty to +\infty. Use the transformation z = \mu 32 + x on the numbers returned by gsl_ran_gaussian to obtain a Gaussian 33 distribution with mean \mu. This function uses the Box-Mueller 34 algorithm which requires two calls to the random number generator r. 35 36 */ 37 38 #include 39 #include 40 41 #include 20d9616 major cleanup. Moved code to BootStrap schwehr authored Sep 13, 2004 42 #include d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 43 #include 20d9616 major cleanup. Moved code to BootStrap schwehr authored Sep 13, 2004 44 #include d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 45 46 #include "kdsPmagL.H" // L is for local 47 #include "SiteSigma.H" e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 48 #include "Bootstrap.H" b155d68 Initial revision schwehr authored Sep 9, 2004 49 50 using namespace std; 51 815f89e Version 0.4. Now has verbosity and debug.H schwehr authored Oct 8, 2004 52 53 /*************************************************************************** 54 * LOCAL MACROS and DEFINES 55 ***************************************************************************/ 56 57 #include "debug.H" // provides FAILED_HERE, UNUSED, DebugPrintf 58 #ifndef NDEBUG 59 int debug_level; 60 #endif 61 62 /*************************************************************************** 63 * GLOBALS 64 ***************************************************************************/ 65 66 /// Let the debugger find out which version is being used. 67 static const UNUSED char* RCSid ="@(#) $Id$"; 68 69 /*************************************************************************** 70 * LOCAL FUNCTIONS 71 ***************************************************************************/ 72 73 d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 74 // return true if all went well. 75 // false if trouble of any kind 76 77 // Unlike Lisa's code, this one does NOT alter the sigmas on loading 78 // which is what her adread subroutine did. e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 79 // Have to call SiteSigma if doing a Site based Parametric Bootstrap d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 80 bool 81 LoadS(const string filename,vector &s,vector &sigmas) { 82 ifstream in(filename.c_str(),ios::in); 83 if (!bool(in)) {cerr << "failed to open file: " << filename << endl; return false; } 84 85 // FIX: detect formats - {s[6]}, {s[6],sigma}, {name, sigma, s[6]} 86 // FIX: only do {s[6],sigma} for now e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 87 SVec tmp(6,0.); float tmpSigma; d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 88 while (in >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3] >> tmp[4] >> tmp[5] >> tmpSigma) { e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 89 s.push_back(tmp); sigmas.push_back(tmpSigma); d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 90 } e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 91 // FIX: do we need to normalize so that the trace is 1? 92 // Not all data will have a trace==1?? d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 93 return (true); 94 } 95 e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 96 ////////////////////////////////////////////////////////////////////// 97 // MAIN 98 ////////////////////////////////////////////////////////////////////// 99 #ifndef REGRESSION_TEST // NOT testing d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 100 c62545f Works with the new UI. schwehr authored Oct 6, 2004 101 enum BootTypeEnum { BAD_PARAMETRIC, SITE_PARAMETRIC, SAMPLE_PARAMETRIC }; 102 enum FormatEnum {BAD_FORMAT, XYZ_FORMAT,TPR_FORMAT,S_FORMAT}; 103 #include "s_bootstrap_cmd.h" // Command line args 104 #include "Eigs.H" // Let's us convert to other coords 105 106 bool GetFiles(char **in_arg,vector &inFiles) { 107 assert(in_arg); 108 assert(*in_arg); // Must be at least 1 file in! 109 // can not have more than 64000 input files 110 for (size_t i=0;i<64000 && in_arg[i];i++) { 111 inFiles.push_back(string(in_arg[i])); 112 } 113 return (true); 114 } 115 116 BootTypeEnum GetParametricType(const int site_given, const int sample_given) { 117 if (site_given && sample_given) { 118 cerr << "ERROR: can not specify both site and sample paramteric bootstrap" < &inFiles, 139 ofstream &out1, ofstream &out2, ofstream &out3, 140 const int numout_arg, const FormatEnum format, const BootTypeEnum type, 141 const int draw) 142 { 143 bool ok=true; 144 assert(1==numout_arg || 3==numout_arg); 145 assert(0 s; 158 vector sigmas; 159 160 vector Vmin(3,0), Vint(3,0), Vmax(3,0); // for xyz or tpr 161 162 for(size_t i=0;i inFiles; 247 if (!GetFiles(a.in_arg,inFiles)) {cerr << "Doh! What happened?" << endl; return(EXIT_FAILURE);} 248 249 if (1!=a.numout_arg && 3!=a.numout_arg) { 250 cerr << "ERROR: numout must be either 1 or 3" << endl 251 << " found: " << a.numout_arg << endl; 252 return(EXIT_FAILURE); 253 } 254 255 const FormatEnum format = GetFormat(a.format_arg); 815f89e Version 0.4. Now has verbosity and debug.H schwehr authored Oct 8, 2004 256 DebugPrintf(VERBOSE,("format: %s (%d)",a.format_arg,int(format))); c62545f Works with the new UI. schwehr authored Oct 6, 2004 257 258 // Can't have S_FORMAT and 3 outfiles. Does not make sense!!! 259 if (3==a.numout_arg && S_FORMAT==format) { 260 cerr << "ERROR: you can't have 3 output files with the S_FORMAT." << endl 261 << " That would be ludicrous" << endl; 262 return (EXIT_FAILURE); 263 } 264 265 266 const BootTypeEnum type = GetParametricType(a.site_given,a.sample_given); 267 #ifndef NDEBUG 268 cerr << "Bootstrap type: " << (SITE_PARAMETRIC==type?"site":"sample") << "parametric"< b-del) ? true : false ); 308 } 309 310 bool Test1 (void) { 311 vector s; 312 vector sigmas; 313 if (!LoadS(string("as1-crypt.s"),s,sigmas)) {FAILED_HERE; return false;}; e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 314 d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 315 const float siteSigma = SiteSigma(s); 316 const float expectedSiteSigma = 0.00133387523; 317 if (!isEqual(siteSigma, expectedSiteSigma, 0.000001)) {FAILED_HERE; return false;} e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 318 319 gsl_rng *r; 320 const gsl_rng_type *T; 321 gsl_rng_env_setup(); 322 T = gsl_rng_default; 323 r = gsl_rng_alloc (T); 324 // Let it always start with the same value 325 gsl_rng_set(r,0); 326 //{ unsigned long int seed; getDevRandom(seed); gsl_rng_set(r,s); } 327 328 SVec newSample; 329 const size_t siteNum = BootstrapParametricSite (s,siteSigma,newSample, r); 330 cout << "Site boot picked sample " << siteNum << endl; 331 const size_t sampleNum = BootstrapParametricSample(s,sigmas ,newSample, r); 332 cout << "Sample boot picked sample " << sampleNum << endl; 333 d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 334 return (true); 335 } 336 e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 337 bool Test2 () { 338 { char a; cout << " devRandom char : " << short(getDevRandom (a)) << endl; } 339 { short a; cout << " devRandom short : " << getDevRandom (a) << endl; } 340 { int a; cout << " devRandom int : " << getDevRandom (a) << endl; } 341 { long a; cout << " devRandom long : " << getDevRandom (a) << endl; } 342 { float a; cout << " devRandom float : " << getDevRandom (a) << endl; } 343 { double a; cout << " devRandom double: " << getDevRandom (a) << endl; } 344 return (true); 345 } d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 346 347 int main(UNUSED int argc, char *argv[]) { 348 bool ok=true; 349 350 if (!Test1()) {FAILED_HERE;ok=false;}; e6fae9e Pulled a lot of code out to Bootstrap.[CH] schwehr authored Sep 10, 2004 351 if (!Test2()) {FAILED_HERE;ok=false;}; d290f0c Starting to get Test1() going. Only does sitesigma so far. schwehr authored Sep 9, 2004 352 353 cout << argv[0] << " :" << (ok?"ok":"FAILED") << endl; 354 return (ok?EXIT_SUCCESS:EXIT_FAILURE); 355 } 356 #endif // REGRESSION_TEST
Something went wrong with that request. Please try again.