summaryrefslogtreecommitdiff
path: root/lib/wolff_tools.c
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2017-10-12 16:18:11 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2017-10-12 16:18:11 -0400
commit77584d5ab2182f5e9d9b8614b600b2e1ef08bb7f (patch)
treedf42f62f6b920164d60c180dfb6753b4a1556d00 /lib/wolff_tools.c
parent969e9dd60bf2966ec696120df61317ecb5961f35 (diff)
downloadc++-77584d5ab2182f5e9d9b8614b600b2e1ef08bb7f.tar.gz
c++-77584d5ab2182f5e9d9b8614b600b2e1ef08bb7f.tar.bz2
c++-77584d5ab2182f5e9d9b8614b600b2e1ef08bb7f.zip
made collection of data more standard and efficient
Diffstat (limited to 'lib/wolff_tools.c')
-rw-r--r--lib/wolff_tools.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/wolff_tools.c b/lib/wolff_tools.c
index 7886bab..59d04fc 100644
--- a/lib/wolff_tools.c
+++ b/lib/wolff_tools.c
@@ -152,3 +152,26 @@ uint32_t wolff_step(double T, double H, ising_state_t *s, gsl_rng *r,
return n_flips;
}
+
+double add_to_avg(double mx, double x, uint64_t n) {
+ return mx * (n / (n + 1.)) + x * 1. / (n + 1.);
+}
+
+void update_meas(meas_t *m, double x) {
+ uint64_t n = m->n;
+
+ m->x = add_to_avg(m->x, x, n);
+ m->x2 = add_to_avg(m->x2, pow(x, 2), n);
+
+ m->m2 = add_to_avg(m->m2, pow(x - m->x, 2), n);
+ m->m4 = add_to_avg(m->m4, pow(x - m->x, 4), n);
+
+ if (n > 1) {
+ double s2 = n / (n - 1.) * (m->x2 - pow(m->x, 2));
+ m->dx = sqrt(s2 / n);
+ m->c = s2;
+ m->dc = sqrt((m->m4 - (n - 3.)/(n - 1.) * pow(m->m2, 2)) / n);
+ }
+
+ (m->n)++;
+}