ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ema.hpp
Go to the documentation of this file.
1#ifndef _ema_hpp_INCLUDED
2#define _ema_hpp_INCLUDED
3
4#include "global.h"
5
6#include <cstdint>
7
9
10namespace CaDiCaL {
11
12struct Internal;
13
14// This is a more complex generic exponential moving average class to
15// support more robust initialization (see comments in the 'update'
16// implementation).
17
18struct EMA {
19
20#ifdef LOGGING
21 uint64_t updated;
22#endif
23 double value; // unbiased (corrected) moving average
24 double biased; // biased initialized moving average
25 double alpha; // input scaling with 'alpha = 1 - beta'
26 double beta; // decay of 'biased' with 'beta = 1 - alpha'
27 double exp; // 'exp = pow (beta, updated)'
28
29 EMA ()
30 :
31#ifdef LOGGING
32 updated (0),
33#endif
34 value (0), biased (0), alpha (0), beta (0), exp (0) {
35 }
36
37 EMA (double a)
38 :
39#ifdef LOGGING
40 updated (0),
41#endif
42 value (0), biased (0), alpha (a), beta (1 - a), exp (!!beta) {
43 CADICAL_assert (beta >= 0);
44 }
45
46 operator double () const { return value; }
47 void update (Internal *, double y, const char *name);
48};
49
50} // namespace CaDiCaL
51
52/*------------------------------------------------------------------------*/
53
54// Compact average update and initialization macros for better logging.
55
56#define UPDATE_AVERAGE(A, Y) \
57 do { \
58 A.update (internal, (Y), #A); \
59 } while (0)
60
61#define INIT_EMA(E, WINDOW) \
62 do { \
63 CADICAL_assert ((WINDOW) >= 1); \
64 double ALPHA = 1.0 / (double) (WINDOW); \
65 E = EMA (ALPHA); \
66 LOG ("init " #E " EMA target alpha %g window %d", ALPHA, \
67 (int) WINDOW); \
68 } while (0)
69
70/*------------------------------------------------------------------------*/
71
73
74#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
#define CADICAL_assert(ignore)
Definition global.h:14
char * name
Definition main.h:24
double value
Definition ema.hpp:23
double alpha
Definition ema.hpp:25
double biased
Definition ema.hpp:24
double beta
Definition ema.hpp:26
EMA(double a)
Definition ema.hpp:37
void update(Internal *, double y, const char *name)
double exp
Definition ema.hpp:27