11 #include "exp_smooth.h"
13 struct exp_smooth_state
15 fbuff series; /* the series so far */
16 fbuff time_stamps; /* the time stamps */
22 * init local state. can save a copy of the pointer to the
23 * series and time stamps, if desired
26 InitExpSmooth(fbuff series, fbuff time_stamps, char *params)
28 struct exp_smooth_state *state;
32 state = (struct exp_smooth_state *)
33 malloc(sizeof(struct exp_smooth_state));
47 gain = strtod(p_str,&p_str);
50 * all functions take a series and time_stamps
52 state->series = series;
53 state->time_stamps = time_stamps;
54 state->last_pred = 0.0;
57 return((char *)state);
61 FreeExpSmooth(char *state)
68 UpdateExpSmooth(char *state,
73 struct exp_smooth_state *s = (struct exp_smooth_state *)state;
75 pred = s->last_pred + s->gain * (value - s->last_pred);
78 * if there is only one value, last pred is the first valeu in the
81 if(F_COUNT(s->series) <= 1)
83 s->last_pred = F_VAL(s->series,F_FIRST(s->series));
94 ForcExpSmooth(char *state, double *v)
96 struct exp_smooth_state *s = (struct exp_smooth_state *)state;