| 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 |
+ |
protected: |
| 63 |
+ |
size_t Count_; |
| 64 |
+ |
|
| 65 |
+ |
}; |
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+ |
|
| 69 |
|
/** |
| 70 |
|
* Basic Accumulator class for numbers. |
| 71 |
< |
*/ |
| 72 |
< |
|
| 56 |
< |
class Accumulator { |
| 71 |
> |
*/ |
| 72 |
> |
class Accumulator : public BaseAccumulator { |
| 73 |
|
|
| 74 |
|
typedef RealType ElementType; |
| 75 |
|
typedef RealType ResultType; |
| 76 |
|
|
| 77 |
|
public: |
| 78 |
|
|
| 79 |
< |
Accumulator() { |
| 79 |
> |
Accumulator() : BaseAccumulator() { |
| 80 |
|
this->clear(); |
| 81 |
|
} |
| 82 |
|
|
| 107 |
|
Val_ = 0; |
| 108 |
|
} |
| 109 |
|
|
| 94 |
– |
/** |
| 95 |
– |
* get the number of accumulated values |
| 96 |
– |
*/ |
| 97 |
– |
size_t count() { |
| 98 |
– |
return Count_; |
| 99 |
– |
} |
| 110 |
|
|
| 111 |
|
/** |
| 112 |
|
* return the most recently added value |
| 163 |
|
return; |
| 164 |
|
} |
| 165 |
|
|
| 166 |
< |
protected: |
| 167 |
< |
size_t Count_; |
| 166 |
> |
/** |
| 167 |
> |
* return the 95% confidence interval: |
| 168 |
> |
* |
| 169 |
> |
* That is returns c, such that we have 95% confidence that the |
| 170 |
> |
* true mean is within 2c of the Average (x): |
| 171 |
> |
* |
| 172 |
> |
* x - c <= true mean <= x + c |
| 173 |
> |
* |
| 174 |
> |
*/ |
| 175 |
> |
void get95percentConfidenceInterval(ResultType &ret) { |
| 176 |
> |
assert(Count_ != 0); |
| 177 |
> |
RealType sd; |
| 178 |
> |
this->getStdDev(sd); |
| 179 |
> |
ret = 1.960 * sd / sqrt(RealType(Count_)); |
| 180 |
> |
return; |
| 181 |
> |
} |
| 182 |
> |
|
| 183 |
|
private: |
| 184 |
|
ElementType Val_; |
| 185 |
|
ResultType Avg_; |
| 188 |
|
ElementType Max_; |
| 189 |
|
}; |
| 190 |
|
|
| 191 |
< |
class VectorAccumulator : public Accumulator { |
| 191 |
> |
class VectorAccumulator : public BaseAccumulator { |
| 192 |
|
|
| 193 |
|
typedef Vector3d ElementType; |
| 194 |
|
typedef Vector3d ResultType; |
| 195 |
|
|
| 196 |
|
public: |
| 197 |
< |
VectorAccumulator() : Accumulator() { |
| 197 |
> |
VectorAccumulator() : BaseAccumulator() { |
| 198 |
|
this->clear(); |
| 199 |
|
} |
| 200 |
|
|
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
/** |
| 280 |
+ |
* return the 95% confidence interval: |
| 281 |
+ |
* |
| 282 |
+ |
* That is returns c, such that we have 95% confidence that the |
| 283 |
+ |
* true mean is within 2c of the Average (x): |
| 284 |
+ |
* |
| 285 |
+ |
* x - c <= true mean <= x + c |
| 286 |
+ |
* |
| 287 |
+ |
*/ |
| 288 |
+ |
void get95percentConfidenceInterval(ResultType &ret) { |
| 289 |
+ |
assert(Count_ != 0); |
| 290 |
+ |
ResultType sd; |
| 291 |
+ |
this->getStdDev(sd); |
| 292 |
+ |
ret[0] = 1.960 * sd[0] / sqrt(RealType(Count_)); |
| 293 |
+ |
ret[1] = 1.960 * sd[1] / sqrt(RealType(Count_)); |
| 294 |
+ |
ret[2] = 1.960 * sd[2] / sqrt(RealType(Count_)); |
| 295 |
+ |
return; |
| 296 |
+ |
} |
| 297 |
+ |
|
| 298 |
+ |
/** |
| 299 |
|
* return the largest length |
| 300 |
|
*/ |
| 301 |
|
void getMaxLength(RealType &ret) { |
| 341 |
|
ret = sqrt(var); |
| 342 |
|
return; |
| 343 |
|
} |
| 344 |
< |
|
| 345 |
< |
protected: |
| 346 |
< |
size_t Count_; |
| 344 |
> |
|
| 345 |
> |
/** |
| 346 |
> |
* return the 95% confidence interval: |
| 347 |
> |
* |
| 348 |
> |
* That is returns c, such that we have 95% confidence that the |
| 349 |
> |
* true mean is within 2c of the Average (x): |
| 350 |
> |
* |
| 351 |
> |
* x - c <= true mean <= x + c |
| 352 |
> |
* |
| 353 |
> |
*/ |
| 354 |
> |
void getLength95percentConfidenceInterval(ResultType &ret) { |
| 355 |
> |
assert(Count_ != 0); |
| 356 |
> |
RealType sd; |
| 357 |
> |
this->getLengthStdDev(sd); |
| 358 |
> |
ret = 1.960 * sd / sqrt(RealType(Count_)); |
| 359 |
> |
return; |
| 360 |
> |
} |
| 361 |
> |
|
| 362 |
> |
|
| 363 |
|
private: |
| 364 |
|
ResultType Val_; |
| 365 |
|
ResultType Avg_; |
| 371 |
|
|
| 372 |
|
}; |
| 373 |
|
|
| 374 |
< |
class MatrixAccumulator : public Accumulator { |
| 374 |
> |
class MatrixAccumulator : public BaseAccumulator { |
| 375 |
|
|
| 376 |
|
typedef Mat3x3d ElementType; |
| 377 |
|
typedef Mat3x3d ResultType; |
| 378 |
|
|
| 379 |
|
public: |
| 380 |
< |
MatrixAccumulator() : Accumulator() { |
| 380 |
> |
MatrixAccumulator() : BaseAccumulator() { |
| 381 |
|
this->clear(); |
| 382 |
|
} |
| 383 |
|
|
| 449 |
|
} |
| 450 |
|
return; |
| 451 |
|
} |
| 452 |
< |
|
| 453 |
< |
protected: |
| 454 |
< |
size_t Count_; |
| 452 |
> |
|
| 453 |
> |
/** |
| 454 |
> |
* return the 95% confidence interval: |
| 455 |
> |
* |
| 456 |
> |
* That is returns c, such that we have 95% confidence that the |
| 457 |
> |
* true mean is within 2c of the Average (x): |
| 458 |
> |
* |
| 459 |
> |
* x - c <= true mean <= x + c |
| 460 |
> |
* |
| 461 |
> |
*/ |
| 462 |
> |
void get95percentConfidenceInterval(ResultType &ret) { |
| 463 |
> |
assert(Count_ != 0); |
| 464 |
> |
Mat3x3d sd; |
| 465 |
> |
this->getStdDev(sd); |
| 466 |
> |
for (unsigned int i = 0; i < 3; i++) { |
| 467 |
> |
for (unsigned int j = 0; j < 3; j++) { |
| 468 |
> |
ret(i,j) = 1.960 * sd(i,j) / sqrt(RealType(Count_)); |
| 469 |
> |
} |
| 470 |
> |
} |
| 471 |
> |
return; |
| 472 |
> |
} |
| 473 |
> |
|
| 474 |
|
private: |
| 475 |
|
ElementType Val_; |
| 476 |
|
ResultType Avg_; |