From 519bb7272661ae4fb81a9c4851133cd8e7da1805 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Tue, 25 Apr 2023 16:38:25 -0400 Subject: running average in statistics file --- src/statistics.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/statistics.c (limited to 'src/statistics.c') diff --git a/src/statistics.c b/src/statistics.c new file mode 100644 index 0000000..a35d1e2 --- /dev/null +++ b/src/statistics.c @@ -0,0 +1,28 @@ +#include "statistics.h" + +// run this at each step to compute the running average +double average_step( + // the value at the step + double val, + // the average computed so far + double avg, + uint64_t t, + uint64_t starting_time, + uint64_t print_freq, + uint64_t first_box +){ + + // running average + // reset averages + if(t % print_freq == 1){ + return(0); + } + + // compute average + // different computationin first box if starting_time is not a multiple of print_freq + if(t < starting_time + first_box){ + return(avg+val/first_box); + } else { + return(avg+val/print_freq); + } +} -- cgit v1.2.3-54-g00ecf