Browse code

drop LLS1, rename LLS2 to LLS

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2014/08/10 06:03:26
Showing 10 changed files
... ...
@@ -20,7 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "libavutil/common.h"
23
-#include "libavutil/lls2.h"
23
+#include "libavutil/lls.h"
24 24
 
25 25
 #define LPC_USE_DOUBLE
26 26
 #include "lpc.h"
... ...
@@ -208,7 +208,7 @@ int ff_lpc_calc_coefs(LPCContext *s,
208 208
     }
209 209
 
210 210
     if (lpc_type == FF_LPC_TYPE_CHOLESKY) {
211
-        LLSModel2 m[2];
211
+        LLSModel m[2];
212 212
         LOCAL_ALIGNED(32, double, var, [FFALIGN(MAX_LPC_ORDER+1,4)]);
213 213
         double av_uninit(weight);
214 214
         memset(var, 0, FFALIGN(MAX_LPC_ORDER+1,4)*sizeof(*var));
... ...
@@ -217,7 +217,7 @@ int ff_lpc_calc_coefs(LPCContext *s,
217 217
             m[0].coeff[max_order-1][j] = -lpc[max_order-1][j];
218 218
 
219 219
         for(; pass<lpc_passes; pass++){
220
-            avpriv_init_lls2(&m[pass&1], max_order);
220
+            avpriv_init_lls(&m[pass&1], max_order);
221 221
 
222 222
             weight=0;
223 223
             for(i=max_order; i<blocksize; i++){
... ...
@@ -238,7 +238,7 @@ int ff_lpc_calc_coefs(LPCContext *s,
238 238
 
239 239
                 m[pass&1].update_lls(&m[pass&1], var);
240 240
             }
241
-            avpriv_solve_lls2(&m[pass&1], 0.001, 0);
241
+            avpriv_solve_lls(&m[pass&1], 0.001, 0);
242 242
         }
243 243
 
244 244
         for(i=0; i<max_order; i++){
... ...
@@ -102,8 +102,7 @@ OBJS = adler32.o                                                        \
102 102
        intfloat_readwrite.o                                             \
103 103
        intmath.o                                                        \
104 104
        lfg.o                                                            \
105
-       lls1.o                                                           \
106
-       lls2.o                                                           \
105
+       lls.o                                                            \
107 106
        log.o                                                            \
108 107
        log2_tab.o                                                       \
109 108
        mathematics.o                                                    \
... ...
@@ -163,8 +162,7 @@ TESTPROGS = adler32                                                     \
163 163
             float_dsp                                                   \
164 164
             hmac                                                        \
165 165
             lfg                                                         \
166
-            lls1                                                        \
167
-            lls2                                                        \
166
+            lls                                                         \
168 167
             log                                                         \
169 168
             md5                                                         \
170 169
             murmur3                                                     \
171 170
new file mode 100644
... ...
@@ -0,0 +1,160 @@
0
+/*
1
+ * linear least squares model
2
+ *
3
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file
24
+ * linear least squares model
25
+ */
26
+
27
+#include <math.h>
28
+#include <string.h>
29
+
30
+#include "attributes.h"
31
+#include "version.h"
32
+#include "lls.h"
33
+
34
+static void update_lls(LLSModel *m, double *var)
35
+{
36
+    int i, j;
37
+
38
+    for (i = 0; i <= m->indep_count; i++) {
39
+        for (j = i; j <= m->indep_count; j++) {
40
+            m->covariance[i][j] += var[i] * var[j];
41
+        }
42
+    }
43
+}
44
+
45
+void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
46
+{
47
+    int i, j, k;
48
+    double (*factor)[MAX_VARS_ALIGN] = (void *) &m->covariance[1][0];
49
+    double (*covar) [MAX_VARS_ALIGN] = (void *) &m->covariance[1][1];
50
+    double *covar_y                = m->covariance[0];
51
+    int count                      = m->indep_count;
52
+
53
+    for (i = 0; i < count; i++) {
54
+        for (j = i; j < count; j++) {
55
+            double sum = covar[i][j];
56
+
57
+            for (k = i - 1; k >= 0; k--)
58
+                sum -= factor[i][k] * factor[j][k];
59
+
60
+            if (i == j) {
61
+                if (sum < threshold)
62
+                    sum = 1.0;
63
+                factor[i][i] = sqrt(sum);
64
+            } else {
65
+                factor[j][i] = sum / factor[i][i];
66
+            }
67
+        }
68
+    }
69
+
70
+    for (i = 0; i < count; i++) {
71
+        double sum = covar_y[i + 1];
72
+
73
+        for (k = i - 1; k >= 0; k--)
74
+            sum -= factor[i][k] * m->coeff[0][k];
75
+
76
+        m->coeff[0][i] = sum / factor[i][i];
77
+    }
78
+
79
+    for (j = count - 1; j >= min_order; j--) {
80
+        for (i = j; i >= 0; i--) {
81
+            double sum = m->coeff[0][i];
82
+
83
+            for (k = i + 1; k <= j; k++)
84
+                sum -= factor[k][i] * m->coeff[j][k];
85
+
86
+            m->coeff[j][i] = sum / factor[i][i];
87
+        }
88
+
89
+        m->variance[j] = covar_y[0];
90
+
91
+        for (i = 0; i <= j; i++) {
92
+            double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1];
93
+
94
+            for (k = 0; k < i; k++)
95
+                sum += 2 * m->coeff[j][k] * covar[k][i];
96
+
97
+            m->variance[j] += m->coeff[j][i] * sum;
98
+        }
99
+    }
100
+}
101
+
102
+static double evaluate_lls(LLSModel *m, double *param, int order)
103
+{
104
+    int i;
105
+    double out = 0;
106
+
107
+    for (i = 0; i <= order; i++)
108
+        out += param[i] * m->coeff[order][i];
109
+
110
+    return out;
111
+}
112
+
113
+av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
114
+{
115
+    memset(m, 0, sizeof(LLSModel));
116
+    m->indep_count = indep_count;
117
+    m->update_lls = update_lls;
118
+    m->evaluate_lls = evaluate_lls;
119
+    if (ARCH_X86)
120
+        ff_init_lls_x86(m);
121
+}
122
+
123
+#ifdef TEST
124
+
125
+#include <stdio.h>
126
+#include <limits.h>
127
+#include "lfg.h"
128
+
129
+int main(void)
130
+{
131
+    LLSModel m;
132
+    int i, order;
133
+    AVLFG lfg;
134
+
135
+    av_lfg_init(&lfg, 1);
136
+    avpriv_init_lls(&m, 3);
137
+
138
+    for (i = 0; i < 100; i++) {
139
+        LOCAL_ALIGNED(32, double, var, [4]);
140
+        double eval;
141
+
142
+        var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
143
+        var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
144
+        var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
145
+        var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
146
+        m.update_lls(&m, var);
147
+        avpriv_solve_lls(&m, 0.001, 0);
148
+        for (order = 0; order < 3; order++) {
149
+            eval = m.evaluate_lls(&m, var + 1, order);
150
+            printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
151
+                   var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
152
+                   m.coeff[order][0], m.coeff[order][1],
153
+                   m.coeff[order][2]);
154
+        }
155
+    }
156
+    return 0;
157
+}
158
+
159
+#endif
0 160
new file mode 100644
... ...
@@ -0,0 +1,64 @@
0
+/*
1
+ * linear least squares model
2
+ *
3
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#ifndef AVUTIL_LLS_H
23
+#define AVUTIL_LLS_H
24
+
25
+#include "common.h"
26
+#include "mem.h"
27
+#include "version.h"
28
+
29
+#define MAX_VARS 32
30
+#define MAX_VARS_ALIGN FFALIGN(MAX_VARS+1,4)
31
+
32
+//FIXME avoid direct access to LLSModel from outside
33
+
34
+/**
35
+ * Linear least squares model.
36
+ */
37
+typedef struct LLSModel {
38
+    DECLARE_ALIGNED(32, double, covariance[MAX_VARS_ALIGN][MAX_VARS_ALIGN]);
39
+    DECLARE_ALIGNED(32, double, coeff[MAX_VARS][MAX_VARS]);
40
+    double variance[MAX_VARS];
41
+    int indep_count;
42
+    /**
43
+     * Take the outer-product of var[] with itself, and add to the covariance matrix.
44
+     * @param m this context
45
+     * @param var training samples, starting with the value to be predicted
46
+     *            32-byte aligned, and any padding elements must be initialized
47
+     *            (i.e not denormal/nan).
48
+     */
49
+    void (*update_lls)(struct LLSModel *m, double *var);
50
+    /**
51
+     * Inner product of var[] and the LPC coefs.
52
+     * @param m this context
53
+     * @param var training samples, excluding the value to be predicted. unaligned.
54
+     * @param order lpc order
55
+     */
56
+    double (*evaluate_lls)(struct LLSModel *m, double *var, int order);
57
+} LLSModel;
58
+
59
+void avpriv_init_lls(LLSModel *m, int indep_count);
60
+void ff_init_lls_x86(LLSModel *m);
61
+void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order);
62
+
63
+#endif /* AVUTIL_LLS_H */
0 64
deleted file mode 100644
... ...
@@ -1,180 +0,0 @@
1
-/*
2
- * linear least squares model
3
- *
4
- * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-/**
24
- * @file
25
- * linear least squares model
26
- */
27
-
28
-#include <math.h>
29
-#include <string.h>
30
-
31
-#include "attributes.h"
32
-#include "version.h"
33
-#include "lls1.h"
34
-
35
-#if FF_API_LLS1
36
-
37
-av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
38
-{
39
-    memset(m, 0, sizeof(LLSModel));
40
-    m->indep_count = indep_count;
41
-}
42
-
43
-void avpriv_update_lls(LLSModel *m, double *var, double decay)
44
-{
45
-    int i, j;
46
-
47
-    for (i = 0; i <= m->indep_count; i++) {
48
-        for (j = i; j <= m->indep_count; j++) {
49
-            m->covariance[i][j] *= decay;
50
-            m->covariance[i][j] += var[i] * var[j];
51
-        }
52
-    }
53
-}
54
-
55
-void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
56
-{
57
-    int i, j, k;
58
-    double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0];
59
-    double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1];
60
-    double *covar_y                = m->covariance[0];
61
-    int count                      = m->indep_count;
62
-
63
-    for (i = 0; i < count; i++) {
64
-        for (j = i; j < count; j++) {
65
-            double sum = covar[i][j];
66
-
67
-            for (k = i - 1; k >= 0; k--)
68
-                sum -= factor[i][k] * factor[j][k];
69
-
70
-            if (i == j) {
71
-                if (sum < threshold)
72
-                    sum = 1.0;
73
-                factor[i][i] = sqrt(sum);
74
-            } else {
75
-                factor[j][i] = sum / factor[i][i];
76
-            }
77
-        }
78
-    }
79
-
80
-    for (i = 0; i < count; i++) {
81
-        double sum = covar_y[i + 1];
82
-
83
-        for (k = i - 1; k >= 0; k--)
84
-            sum -= factor[i][k] * m->coeff[0][k];
85
-
86
-        m->coeff[0][i] = sum / factor[i][i];
87
-    }
88
-
89
-    for (j = count - 1; j >= min_order; j--) {
90
-        for (i = j; i >= 0; i--) {
91
-            double sum = m->coeff[0][i];
92
-
93
-            for (k = i + 1; k <= j; k++)
94
-                sum -= factor[k][i] * m->coeff[j][k];
95
-
96
-            m->coeff[j][i] = sum / factor[i][i];
97
-        }
98
-
99
-        m->variance[j] = covar_y[0];
100
-
101
-        for (i = 0; i <= j; i++) {
102
-            double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1];
103
-
104
-            for (k = 0; k < i; k++)
105
-                sum += 2 * m->coeff[j][k] * covar[k][i];
106
-
107
-            m->variance[j] += m->coeff[j][i] * sum;
108
-        }
109
-    }
110
-}
111
-
112
-double avpriv_evaluate_lls(LLSModel *m, double *param, int order)
113
-{
114
-    int i;
115
-    double out = 0;
116
-
117
-    for (i = 0; i <= order; i++)
118
-        out += param[i] * m->coeff[order][i];
119
-
120
-    return out;
121
-}
122
-
123
-#if FF_API_LLS_PRIVATE
124
-av_cold void av_init_lls(LLSModel *m, int indep_count)
125
-{
126
-    avpriv_init_lls(m, indep_count);
127
-}
128
-void av_update_lls(LLSModel *m, double *param, double decay)
129
-{
130
-    avpriv_update_lls(m, param, decay);
131
-}
132
-void av_solve_lls(LLSModel *m, double threshold, int min_order)
133
-{
134
-    avpriv_solve_lls(m, threshold, min_order);
135
-}
136
-double av_evaluate_lls(LLSModel *m, double *param, int order)
137
-{
138
-    return avpriv_evaluate_lls(m, param, order);
139
-}
140
-#endif /* FF_API_LLS_PRIVATE */
141
-
142
-#endif /* FF_API_LLS1 */
143
-
144
-#ifdef TEST
145
-
146
-#include <stdio.h>
147
-#include <limits.h>
148
-#include "lfg.h"
149
-
150
-int main(void)
151
-{
152
-    LLSModel m;
153
-    int i, order;
154
-    AVLFG lfg;
155
-
156
-    av_lfg_init(&lfg, 1);
157
-    avpriv_init_lls(&m, 3);
158
-
159
-    for (i = 0; i < 100; i++) {
160
-        double var[4];
161
-        double eval;
162
-
163
-        var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
164
-        var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
165
-        var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
166
-        var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
167
-        avpriv_update_lls(&m, var, 0.99);
168
-        avpriv_solve_lls(&m, 0.001, 0);
169
-        for (order = 0; order < 3; order++) {
170
-            eval = avpriv_evaluate_lls(&m, var + 1, order);
171
-            printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
172
-                   var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
173
-                   m.coeff[order][0], m.coeff[order][1],
174
-                   m.coeff[order][2]);
175
-        }
176
-    }
177
-    return 0;
178
-}
179
-
180
-#endif
181 1
deleted file mode 100644
... ...
@@ -1,54 +0,0 @@
1
-/*
2
- * linear least squares model
3
- *
4
- * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#ifndef AVUTIL_LLS_H
24
-#define AVUTIL_LLS_H
25
-
26
-#include "version.h"
27
-
28
-#define MAX_VARS 32
29
-
30
-//FIXME avoid direct access to LLSModel from outside
31
-
32
-/**
33
- * Linear least squares model.
34
- */
35
-typedef struct LLSModel {
36
-    double covariance[MAX_VARS + 1][MAX_VARS + 1];
37
-    double coeff[MAX_VARS][MAX_VARS];
38
-    double variance[MAX_VARS];
39
-    int indep_count;
40
-} LLSModel;
41
-
42
-void avpriv_init_lls(LLSModel *m, int indep_count);
43
-void avpriv_update_lls(LLSModel *m, double *param, double decay);
44
-void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order);
45
-double avpriv_evaluate_lls(LLSModel *m, double *param, int order);
46
-
47
-#if FF_API_LLS_PRIVATE
48
-void av_init_lls(LLSModel *m, int indep_count);
49
-void av_update_lls(LLSModel *m, double *param, double decay);
50
-void av_solve_lls(LLSModel *m, double threshold, int min_order);
51
-double av_evaluate_lls(LLSModel *m, double *param, int order);
52
-#endif /* FF_API_LLS_PRIVATE */
53
-
54
-#endif /* AVUTIL_LLS_H */
55 1
deleted file mode 100644
... ...
@@ -1,160 +0,0 @@
1
-/*
2
- * linear least squares model
3
- *
4
- * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-/**
24
- * @file
25
- * linear least squares model
26
- */
27
-
28
-#include <math.h>
29
-#include <string.h>
30
-
31
-#include "attributes.h"
32
-#include "version.h"
33
-#include "lls2.h"
34
-
35
-static void update_lls(LLSModel2 *m, double *var)
36
-{
37
-    int i, j;
38
-
39
-    for (i = 0; i <= m->indep_count; i++) {
40
-        for (j = i; j <= m->indep_count; j++) {
41
-            m->covariance[i][j] += var[i] * var[j];
42
-        }
43
-    }
44
-}
45
-
46
-void avpriv_solve_lls2(LLSModel2 *m, double threshold, unsigned short min_order)
47
-{
48
-    int i, j, k;
49
-    double (*factor)[MAX_VARS_ALIGN] = (void *) &m->covariance[1][0];
50
-    double (*covar) [MAX_VARS_ALIGN] = (void *) &m->covariance[1][1];
51
-    double *covar_y                = m->covariance[0];
52
-    int count                      = m->indep_count;
53
-
54
-    for (i = 0; i < count; i++) {
55
-        for (j = i; j < count; j++) {
56
-            double sum = covar[i][j];
57
-
58
-            for (k = i - 1; k >= 0; k--)
59
-                sum -= factor[i][k] * factor[j][k];
60
-
61
-            if (i == j) {
62
-                if (sum < threshold)
63
-                    sum = 1.0;
64
-                factor[i][i] = sqrt(sum);
65
-            } else {
66
-                factor[j][i] = sum / factor[i][i];
67
-            }
68
-        }
69
-    }
70
-
71
-    for (i = 0; i < count; i++) {
72
-        double sum = covar_y[i + 1];
73
-
74
-        for (k = i - 1; k >= 0; k--)
75
-            sum -= factor[i][k] * m->coeff[0][k];
76
-
77
-        m->coeff[0][i] = sum / factor[i][i];
78
-    }
79
-
80
-    for (j = count - 1; j >= min_order; j--) {
81
-        for (i = j; i >= 0; i--) {
82
-            double sum = m->coeff[0][i];
83
-
84
-            for (k = i + 1; k <= j; k++)
85
-                sum -= factor[k][i] * m->coeff[j][k];
86
-
87
-            m->coeff[j][i] = sum / factor[i][i];
88
-        }
89
-
90
-        m->variance[j] = covar_y[0];
91
-
92
-        for (i = 0; i <= j; i++) {
93
-            double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1];
94
-
95
-            for (k = 0; k < i; k++)
96
-                sum += 2 * m->coeff[j][k] * covar[k][i];
97
-
98
-            m->variance[j] += m->coeff[j][i] * sum;
99
-        }
100
-    }
101
-}
102
-
103
-static double evaluate_lls(LLSModel2 *m, double *param, int order)
104
-{
105
-    int i;
106
-    double out = 0;
107
-
108
-    for (i = 0; i <= order; i++)
109
-        out += param[i] * m->coeff[order][i];
110
-
111
-    return out;
112
-}
113
-
114
-av_cold void avpriv_init_lls2(LLSModel2 *m, int indep_count)
115
-{
116
-    memset(m, 0, sizeof(LLSModel2));
117
-    m->indep_count = indep_count;
118
-    m->update_lls = update_lls;
119
-    m->evaluate_lls = evaluate_lls;
120
-    if (ARCH_X86)
121
-        ff_init_lls_x86(m);
122
-}
123
-
124
-#ifdef TEST
125
-
126
-#include <stdio.h>
127
-#include <limits.h>
128
-#include "lfg.h"
129
-
130
-int main(void)
131
-{
132
-    LLSModel2 m;
133
-    int i, order;
134
-    AVLFG lfg;
135
-
136
-    av_lfg_init(&lfg, 1);
137
-    avpriv_init_lls2(&m, 3);
138
-
139
-    for (i = 0; i < 100; i++) {
140
-        LOCAL_ALIGNED(32, double, var, [4]);
141
-        double eval;
142
-
143
-        var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
144
-        var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
145
-        var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
146
-        var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
147
-        m.update_lls(&m, var);
148
-        avpriv_solve_lls2(&m, 0.001, 0);
149
-        for (order = 0; order < 3; order++) {
150
-            eval = m.evaluate_lls(&m, var + 1, order);
151
-            printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
152
-                   var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
153
-                   m.coeff[order][0], m.coeff[order][1],
154
-                   m.coeff[order][2]);
155
-        }
156
-    }
157
-    return 0;
158
-}
159
-
160
-#endif
161 1
deleted file mode 100644
... ...
@@ -1,64 +0,0 @@
1
-/*
2
- * linear least squares model
3
- *
4
- * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#ifndef AVUTIL_LLS_H
24
-#define AVUTIL_LLS_H
25
-
26
-#include "common.h"
27
-#include "mem.h"
28
-#include "version.h"
29
-
30
-#define MAX_VARS 32
31
-#define MAX_VARS_ALIGN FFALIGN(MAX_VARS+1,4)
32
-
33
-//FIXME avoid direct access to LLSModel2 from outside
34
-
35
-/**
36
- * Linear least squares model.
37
- */
38
-typedef struct LLSModel2 {
39
-    DECLARE_ALIGNED(32, double, covariance[MAX_VARS_ALIGN][MAX_VARS_ALIGN]);
40
-    DECLARE_ALIGNED(32, double, coeff[MAX_VARS][MAX_VARS]);
41
-    double variance[MAX_VARS];
42
-    int indep_count;
43
-    /**
44
-     * Take the outer-product of var[] with itself, and add to the covariance matrix.
45
-     * @param m this context
46
-     * @param var training samples, starting with the value to be predicted
47
-     *            32-byte aligned, and any padding elements must be initialized
48
-     *            (i.e not denormal/nan).
49
-     */
50
-    void (*update_lls)(struct LLSModel2 *m, double *var);
51
-    /**
52
-     * Inner product of var[] and the LPC coefs.
53
-     * @param m this context
54
-     * @param var training samples, excluding the value to be predicted. unaligned.
55
-     * @param order lpc order
56
-     */
57
-    double (*evaluate_lls)(struct LLSModel2 *m, double *var, int order);
58
-} LLSModel2;
59
-
60
-void avpriv_init_lls2(LLSModel2 *m, int indep_count);
61
-void ff_init_lls_x86(LLSModel2 *m);
62
-void avpriv_solve_lls2(LLSModel2 *m, double threshold, unsigned short min_order);
63
-
64
-#endif /* AVUTIL_LLS_H */
... ...
@@ -29,7 +29,7 @@ SECTION .text
29 29
 %define COVAR_STRIDE MAX_VARS_ALIGN*8
30 30
 %define COVAR(x,y) [covarq + (x)*8 + (y)*COVAR_STRIDE]
31 31
 
32
-struc LLSModel2
32
+struc LLSModel
33 33
     .covariance:  resq MAX_VARS_ALIGN*MAX_VARS_ALIGN
34 34
     .coeff:       resq MAX_VARS*MAX_VARS
35 35
     .variance:    resq MAX_VARS
... ...
@@ -49,7 +49,7 @@ INIT_XMM sse2
49 49
 %define movdqa movaps
50 50
 cglobal update_lls, 2,5,8, ctx, var, i, j, covar2
51 51
     %define covarq ctxq
52
-    mov     id, [ctxq + LLSModel2.indep_count]
52
+    mov     id, [ctxq + LLSModel.indep_count]
53 53
     lea   varq, [varq + iq*8]
54 54
     neg     iq
55 55
     mov covar2q, covarq
... ...
@@ -129,7 +129,7 @@ cglobal update_lls, 2,5,8, ctx, var, i, j, covar2
129 129
 INIT_YMM avx
130 130
 cglobal update_lls, 3,6,8, ctx, var, count, i, j, count2
131 131
     %define covarq ctxq
132
-    mov  countd, [ctxq + LLSModel2.indep_count]
132
+    mov  countd, [ctxq + LLSModel.indep_count]
133 133
     lea count2d, [countq-2]
134 134
     xor     id, id
135 135
 .loopi:
... ...
@@ -206,7 +206,7 @@ cglobal evaluate_lls, 3,4,2, ctx, var, order, i
206 206
     %define coefsq ctxq
207 207
     mov     id, orderd
208 208
     imul    orderd, MAX_VARS
209
-    lea     coefsq, [ctxq + LLSModel2.coeff + orderq*8]
209
+    lea     coefsq, [ctxq + LLSModel.coeff + orderq*8]
210 210
     movsd   m0, [varq]
211 211
     movhpd  m0, [varq + 8]
212 212
     mulpd   m0, [coefsq]
... ...
@@ -20,14 +20,14 @@
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 21
  */
22 22
 
23
-#include "libavutil/lls2.h"
23
+#include "libavutil/lls.h"
24 24
 #include "libavutil/x86/cpu.h"
25 25
 
26
-void ff_update_lls_sse2(LLSModel2 *m, double *var);
27
-void ff_update_lls_avx(LLSModel2 *m, double *var);
28
-double ff_evaluate_lls_sse2(LLSModel2 *m, double *var, int order);
26
+void ff_update_lls_sse2(LLSModel *m, double *var);
27
+void ff_update_lls_avx(LLSModel *m, double *var);
28
+double ff_evaluate_lls_sse2(LLSModel *m, double *var, int order);
29 29
 
30
-av_cold void ff_init_lls_x86(LLSModel2 *m)
30
+av_cold void ff_init_lls_x86(LLSModel *m)
31 31
 {
32 32
     int cpu_flags = av_get_cpu_flags();
33 33
     if (EXTERNAL_SSE2(cpu_flags)) {