3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-05-26 11:56:21 +00:00
z3/src/util/ema.h
Copilot 17c8958d70 Remove redundant default constructors when they're the only constructor (#8461)
* Initial plan

* Modernize C++ constructors to use C++11 default member initialization - Phase 1

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Fix theory_pb.h struct definition - move reset() back inside struct

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Modernize C++ constructors to use C++11 default member initialization - Phase 2

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Fix opt_solver.h - revert rational initialization (complex type)

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Modernize C++ constructors to use C++11 default member initialization - Phase 3

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Fix sparse_matrix.h - explicitly initialize union member in default constructor

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Remove unnecessary default constructors when they're the only constructor

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
2026-02-18 20:58:01 -08:00

58 lines
1.2 KiB
C++

/*++
Copyright (c) 2018 Microsoft Corporation
Module Name:
ema.h
Abstract:
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:
Nikolaj Bjorner (nbjorner) 2018-05-03
Revision History:
--*/
#pragma once
class ema {
double m_alpha = 0, m_beta = 1, m_value = 0;
unsigned m_period = 0, m_wait = 0;
bool invariant() const { return 0 <= m_alpha && m_alpha <= m_beta && m_beta <= 1 && m_wait <= m_period; }
public:
ema() {
SASSERT(invariant());
}
ema(double alpha):
m_alpha(alpha), m_beta(1), m_value(0),
m_period(0), m_wait(0) {
SASSERT(invariant());
}
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;
m_beta *= 0.5;
if (m_beta < m_alpha) m_beta = m_alpha;
}
void set(double x) {
m_value = x;
}
};