ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
smooth.c File Reference
#include "allocate.h"
#include "internal.h"
#include "logging.h"
Include dependency graph for smooth.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void kissat_init_smooth (kissat *solver, smooth *smooth, int window, const char *name)
 
void kissat_update_smooth (kissat *solver, smooth *smooth, double y)
 

Function Documentation

◆ kissat_init_smooth()

ABC_NAMESPACE_IMPL_START void kissat_init_smooth ( kissat * solver,
smooth * smooth,
int window,
const char * name )

Definition at line 7 of file smooth.c.

8 {
9 KISSAT_assert (window > 0);
10 const double alpha = 1.0 / window;
11 LOG ("initialized %s EMA alpha %g window %d", name, alpha, window);
12 smooth->value = 0;
13 smooth->biased = 0;
14 smooth->alpha = alpha;
15 smooth->beta = 1.0 - alpha;
17 smooth->exp = 1.0;
18#ifdef LOGGING
19 smooth->name = name;
20 smooth->updated = 0;
21#else
22 (void) solver;
23 (void) name;
24#endif
25}
#define LOG(...)
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
char * name
Definition main.h:24
double value
Definition smooth.h:12
double biased
Definition smooth.h:12
double exp
Definition smooth.h:12
double beta
Definition smooth.h:12
double alpha
Definition smooth.h:12

◆ kissat_update_smooth()

void kissat_update_smooth ( kissat * solver,
smooth * smooth,
double y )

Definition at line 27 of file smooth.c.

27 {
28#ifdef LOGGING
29 smooth->updated++;
30 const double old_value = smooth->value;
31#endif
32 const double old_biased = smooth->biased;
33 const double alpha = smooth->alpha;
34 const double beta = smooth->beta;
35 const double delta = y - old_biased;
36 const double scaled_delta = alpha * delta;
37 const double new_biased = old_biased + scaled_delta;
38 LOG ("update %" PRIu64 " of biased %s EMA %g with %g (delta %g) "
39 "yields %g (scaled delta %g)",
40 smooth->updated, smooth->name, old_biased, y, delta, new_biased,
41 scaled_delta);
42 smooth->biased = new_biased;
43 double old_exp = smooth->exp;
44 double new_exp, div, new_value;
45 if (old_exp) {
46 new_exp = old_exp * beta;
47 KISSAT_assert (new_exp < 1);
48 if (new_exp == old_exp) {
49 new_exp = 0;
50 new_value = new_biased;
51#ifdef LOGGING
52 div = 1;
53#endif
54 } else {
55 div = 1 - new_exp;
56 KISSAT_assert (div > 0);
57 new_value = new_biased / div;
58 }
59 smooth->exp = new_exp;
60 } else {
61 new_value = new_biased;
62#ifdef LOGGING
63 new_exp = 0;
64 div = 1;
65#endif
66 }
67 smooth->value = new_value;
68 LOG ("update %" PRIu64 " of corrected %s EMA %g "
69 "with %g (delta %g) yields %g (exponent %g, div %g)",
70 smooth->updated, smooth->name, old_value, y, delta, new_value,
71 new_exp, div);
72#ifndef LOGGING
73 (void) solver;
74#endif
75}