3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

adding ema

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-05-03 13:23:59 -07:00
parent 96914d8578
commit 43403fafcd
5 changed files with 55 additions and 3 deletions

44
src/util/ema.h Normal file
View file

@ -0,0 +1,44 @@
/*++
Copyright (c) 2018 Microsoft Corporation
Module Name:
ema.h
Abstract:
Exponential moving average in the style of CaDiCal.
Author:
Nikolaj Bjorner (nbjorner) 2018-05-03
Revision History:
--*/
#ifndef EMA_H_
#define EMA_H_
class ema {
double m_alpha, m_beta, m_value;
unsigned m_period, m_wait;
public:
ema() { memset(this, 0, sizeof(*this)); }
ema(double alpha):
m_alpha(alpha), m_beta(1), m_value(0),
m_period(0), m_wait(0) {}
double operator() const { return m_value; }
void update(double x) {
m_value += m_beta * (x - m_value);
if (m_beta <= m_alpha || m_wait--) return;
m_wait = m_period = 2*(m_period + 1) - 1;
m_beta *= 0.5;
if (m_beta < m_alpha) m_beta = m_alpha;
}
};
#endif

View file

@ -371,6 +371,9 @@ Notes:
break;
case ordered_at_most_1:
return mk_ordered_exactly_1(full, n, xs);
default:
UNREACHABLE();
return mk_ordered_exactly_1(full, n, xs);
}
if (full) {