1212#include < algorithm>
1313#include < limits>
1414
15- #include < Eigen/Eigen>
16-
1715#include < atfa_api.h>
1816
1917using sample_t = float ;
@@ -24,34 +22,38 @@ constexpr sample_t delta = std::sqrt(std::numeric_limits<sample_t>::epsilon());
2422
2523struct AdapfData {
2624
27- sample_t x_array[N];
28- Eigen::Map<Eigen::Matrix<sample_t , N, 1 >> x;
29-
30- sample_t w_array[N];
31- Eigen::Map<Eigen::Matrix<sample_t , N, 1 >> w;
25+ sample_t x[N];
26+ sample_t w[N];
3227
3328 AdapfData ()
34- : x(x_array), w(w_array)
3529 {
3630 reset ();
3731 }
3832
3933 void reset () {
40- std::fill (x_array, x_array +N, 0 );
41- std::fill (w_array, w_array +N, 0 );
34+ std::fill (x, x +N, 0 );
35+ std::fill (w, w +N, 0 );
4236 }
4337
4438 void push (sample_t sample) {
45- std::copy_backward (x_array, x_array +(N-1 ), x_array +N); // shift down
46- x_array [0 ] = sample; // push at top
39+ std::copy_backward (x, x +(N-1 ), x +N); // shift down
40+ x [0 ] = sample; // push at top
4741 }
4842
4943 sample_t dot_product () const {
50- return x.dot (w);
44+ sample_t result = 0 ;
45+ for (int i=0 ; i<N; ++i)
46+ result += x[i]*w[i];
47+ return result;
5148 }
5249
5350 void update (sample_t err) {
54- w += mu * err * x / (delta + x.squaredNorm ());
51+ sample_t x_normsquared = delta;
52+ for (int i=0 ; i<N; ++i)
53+ x_normsquared += x[i]*x[i];
54+ sample_t factor = mu*err/x_normsquared;
55+ for (int i=0 ; i<N; ++i)
56+ w[i] += factor * x[i];
5557 }
5658
5759};
@@ -91,7 +93,7 @@ float adapf_run(AdapfData *data, float sample, float y, int update,
9193
9294void adapf_getw (const AdapfData *data, const float **begin, unsigned *n)
9395{
94- *begin = data->w_array ;
96+ *begin = data->w ;
9597 *n = N;
9698}
9799}
0 commit comments