mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
fix ema
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
43403fafcd
commit
13b54f379c
8 changed files with 103 additions and 47 deletions
|
@ -7,7 +7,9 @@ Module Name:
|
|||
|
||||
Abstract:
|
||||
|
||||
Exponential moving average in the style of CaDiCal.
|
||||
Exponential moving average based on CaDiCal.
|
||||
The exponential scheme used to adjust beta to alpha is
|
||||
described in Biere & Froelich, POS (Pragmatics of SAT) 2016.
|
||||
|
||||
Author:
|
||||
|
||||
|
@ -22,17 +24,27 @@ Revision History:
|
|||
class ema {
|
||||
double m_alpha, m_beta, m_value;
|
||||
unsigned m_period, m_wait;
|
||||
|
||||
bool invariant() const { return 0 <= m_alpha && m_alpha <= m_beta && m_beta <= 1; }
|
||||
public:
|
||||
ema() { memset(this, 0, sizeof(*this)); }
|
||||
ema(): m_alpha(0), m_beta(1), m_value(0), m_period(0), m_wait(0) {
|
||||
SASSERT(invariant());
|
||||
}
|
||||
|
||||
ema(double alpha):
|
||||
m_alpha(alpha), m_beta(1), m_value(0),
|
||||
m_period(0), m_wait(0) {}
|
||||
m_period(0), m_wait(0) {
|
||||
SASSERT(invariant());
|
||||
}
|
||||
|
||||
double operator() const { return m_value; }
|
||||
void set_alpha(double alpha) {
|
||||
m_alpha = alpha;
|
||||
SASSERT(invariant());
|
||||
}
|
||||
|
||||
operator double () const { return m_value; }
|
||||
|
||||
void update(double x) {
|
||||
SASSERT(invariant());
|
||||
m_value += m_beta * (x - m_value);
|
||||
if (m_beta <= m_alpha || m_wait--) return;
|
||||
m_wait = m_period = 2*(m_period + 1) - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue