| 35 |  | * | 
| 36 |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | < | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | 
| 38 | > | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 |  | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 |  | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 |  | */ | 
| 49 |  |  | 
| 50 |  | namespace OpenMD { | 
| 51 |  |  | 
| 52 | + |  | 
| 53 | + | class BaseAccumulator { | 
| 54 | + | public: | 
| 55 | + | virtual void clear() = 0; | 
| 56 | + | /** | 
| 57 | + | * get the number of accumulated values | 
| 58 | + | */ | 
| 59 | + | virtual size_t count()  { | 
| 60 | + | return Count_; | 
| 61 | + | } | 
| 62 | + | virtual ~BaseAccumulator() {}; | 
| 63 | + | protected: | 
| 64 | + | size_t Count_; | 
| 65 | + |  | 
| 66 | + | }; | 
| 67 | + |  | 
| 68 | + |  | 
| 69 | + |  | 
| 70 |  | /** | 
| 71 |  | * Basic Accumulator class for numbers. | 
| 72 | < | */ | 
| 73 | < |  | 
| 56 | < | class Accumulator { | 
| 72 | > | */ | 
| 73 | > | class Accumulator : public BaseAccumulator { | 
| 74 |  |  | 
| 75 |  | typedef RealType ElementType; | 
| 76 |  | typedef RealType ResultType; | 
| 77 |  |  | 
| 78 |  | public: | 
| 79 |  |  | 
| 80 | < | Accumulator() { | 
| 80 | > | Accumulator() : BaseAccumulator() { | 
| 81 |  | this->clear(); | 
| 82 |  | } | 
| 83 | + |  | 
| 84 | + | ~Accumulator() {}; | 
| 85 |  |  | 
| 86 |  | /** | 
| 87 |  | * Accumulate another value | 
| 110 |  | Val_   = 0; | 
| 111 |  | } | 
| 112 |  |  | 
| 94 | – | /** | 
| 95 | – | * get the number of accumulated values | 
| 96 | – | */ | 
| 97 | – | size_t count()  { | 
| 98 | – | return Count_; | 
| 99 | – | } | 
| 113 |  |  | 
| 114 |  | /** | 
| 115 |  | * return the most recently added value | 
| 166 |  | return; | 
| 167 |  | } | 
| 168 |  |  | 
| 169 | < | protected: | 
| 170 | < | size_t Count_; | 
| 169 | > | /** | 
| 170 | > | * return the 95% confidence interval: | 
| 171 | > | * | 
| 172 | > | * That is returns c, such that we have 95% confidence that the | 
| 173 | > | * true mean is within 2c of the Average (x): | 
| 174 | > | * | 
| 175 | > | *   x - c <= true mean <= x + c | 
| 176 | > | * | 
| 177 | > | */ | 
| 178 | > | void get95percentConfidenceInterval(ResultType &ret) { | 
| 179 | > | assert(Count_ != 0); | 
| 180 | > | RealType sd; | 
| 181 | > | this->getStdDev(sd); | 
| 182 | > | ret = 1.960 * sd / sqrt(RealType(Count_)); | 
| 183 | > | return; | 
| 184 | > | } | 
| 185 | > |  | 
| 186 |  | private: | 
| 187 |  | ElementType Val_; | 
| 188 |  | ResultType Avg_; | 
| 191 |  | ElementType Max_; | 
| 192 |  | }; | 
| 193 |  |  | 
| 194 | < | class VectorAccumulator : public Accumulator { | 
| 194 | > | class VectorAccumulator : public BaseAccumulator { | 
| 195 |  |  | 
| 196 |  | typedef Vector3d ElementType; | 
| 197 |  | typedef Vector3d ResultType; | 
| 198 |  |  | 
| 199 |  | public: | 
| 200 | < | VectorAccumulator() : Accumulator() { | 
| 200 | > | VectorAccumulator() : BaseAccumulator() { | 
| 201 |  | this->clear(); | 
| 202 |  | } | 
| 203 |  |  | 
| 276 |  | ret[0] = sqrt(var[0]); | 
| 277 |  | ret[1] = sqrt(var[1]); | 
| 278 |  | ret[2] = sqrt(var[2]); | 
| 279 | + | return; | 
| 280 | + | } | 
| 281 | + |  | 
| 282 | + | /** | 
| 283 | + | * return the 95% confidence interval: | 
| 284 | + | * | 
| 285 | + | * That is returns c, such that we have 95% confidence that the | 
| 286 | + | * true mean is within 2c of the Average (x): | 
| 287 | + | * | 
| 288 | + | *   x - c <= true mean <= x + c | 
| 289 | + | * | 
| 290 | + | */ | 
| 291 | + | void get95percentConfidenceInterval(ResultType &ret) { | 
| 292 | + | assert(Count_ != 0); | 
| 293 | + | ResultType sd; | 
| 294 | + | this->getStdDev(sd); | 
| 295 | + | ret[0] = 1.960 * sd[0] / sqrt(RealType(Count_)); | 
| 296 | + | ret[1] = 1.960 * sd[1] / sqrt(RealType(Count_)); | 
| 297 | + | ret[2] = 1.960 * sd[2] / sqrt(RealType(Count_)); | 
| 298 |  | return; | 
| 299 |  | } | 
| 300 |  |  | 
| 344 |  | ret = sqrt(var); | 
| 345 |  | return; | 
| 346 |  | } | 
| 347 | < |  | 
| 348 | < | protected: | 
| 349 | < | size_t Count_; | 
| 347 | > |  | 
| 348 | > | /** | 
| 349 | > | * return the 95% confidence interval: | 
| 350 | > | * | 
| 351 | > | * That is returns c, such that we have 95% confidence that the | 
| 352 | > | * true mean is within 2c of the Average (x): | 
| 353 | > | * | 
| 354 | > | *   x - c <= true mean <= x + c | 
| 355 | > | * | 
| 356 | > | */ | 
| 357 | > | void getLength95percentConfidenceInterval(ResultType &ret) { | 
| 358 | > | assert(Count_ != 0); | 
| 359 | > | RealType sd; | 
| 360 | > | this->getLengthStdDev(sd); | 
| 361 | > | ret = 1.960 * sd / sqrt(RealType(Count_)); | 
| 362 | > | return; | 
| 363 | > | } | 
| 364 | > |  | 
| 365 | > |  | 
| 366 |  | private: | 
| 367 |  | ResultType Val_; | 
| 368 |  | ResultType Avg_; | 
| 374 |  |  | 
| 375 |  | }; | 
| 376 |  |  | 
| 377 | < | class MatrixAccumulator : public Accumulator { | 
| 377 | > | class MatrixAccumulator : public BaseAccumulator { | 
| 378 |  |  | 
| 379 |  | typedef Mat3x3d ElementType; | 
| 380 |  | typedef Mat3x3d ResultType; | 
| 381 |  |  | 
| 382 |  | public: | 
| 383 | < | MatrixAccumulator() : Accumulator() { | 
| 383 | > | MatrixAccumulator() : BaseAccumulator() { | 
| 384 |  | this->clear(); | 
| 385 |  | } | 
| 386 |  |  | 
| 452 |  | } | 
| 453 |  | return; | 
| 454 |  | } | 
| 455 | < |  | 
| 456 | < | protected: | 
| 457 | < | size_t Count_; | 
| 455 | > |  | 
| 456 | > | /** | 
| 457 | > | * return the 95% confidence interval: | 
| 458 | > | * | 
| 459 | > | * That is returns c, such that we have 95% confidence that the | 
| 460 | > | * true mean is within 2c of the Average (x): | 
| 461 | > | * | 
| 462 | > | *   x - c <= true mean <= x + c | 
| 463 | > | * | 
| 464 | > | */ | 
| 465 | > | void get95percentConfidenceInterval(ResultType &ret) { | 
| 466 | > | assert(Count_ != 0); | 
| 467 | > | Mat3x3d sd; | 
| 468 | > | this->getStdDev(sd); | 
| 469 | > | for (unsigned int i = 0; i < 3; i++) { | 
| 470 | > | for (unsigned int j = 0; j < 3; j++) { | 
| 471 | > | ret(i,j) = 1.960 * sd(i,j) / sqrt(RealType(Count_)); | 
| 472 | > | } | 
| 473 | > | } | 
| 474 | > | return; | 
| 475 | > | } | 
| 476 | > |  | 
| 477 |  | private: | 
| 478 |  | ElementType Val_; | 
| 479 |  | ResultType Avg_; |