FFmpeg
lls.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <limits.h>
20 #include <stdio.h>
21 
22 #include "libavutil/internal.h"
23 #include "libavutil/lfg.h"
24 #include "libavutil/lls.h"
25 #include "libavutil/mem_internal.h"
26 
27 int main(void)
28 {
29  LLSModel m;
30  int i, order;
31  AVLFG lfg;
32 
33  av_lfg_init(&lfg, 1);
34  avpriv_init_lls(&m, 3);
35 
36  for (i = 0; i < 100; i++) {
37  LOCAL_ALIGNED(32, double, var, [4]);
38  double eval;
39 
40  var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
41  var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
42  var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
43  var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
44  m.update_lls(&m, var);
45  avpriv_solve_lls(&m, 0.001, 0);
46  for (order = 0; order < 3; order++) {
47  eval = m.evaluate_lls(&m, var + 1, order);
48  printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
49  var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
50  m.coeff[order][0], m.coeff[order][1],
51  m.coeff[order][2]);
52  }
53  }
54  return 0;
55 }
LLSModel
Linear least squares model.
Definition: lls.h:37
mem_internal.h
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
LLSModel::variance
double variance[MAX_VARS]
Definition: lls.h:40
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:112
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
lfg.h
limits.h
lls.h
double
double
Definition: af_crystalizer.c:132
avpriv_init_lls
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
Definition: lls.c:114
main
int main(void)
Definition: lls.c:27
LLSModel::update_lls
void(* update_lls)(struct LLSModel *m, const double *var)
Take the outer-product of var[] with itself, and add to the covariance matrix.
Definition: lls.h:49
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
printf
printf("static const uint8_t my_array[100] = {\n")
LLSModel::evaluate_lls
double(* evaluate_lls)(struct LLSModel *m, const double *var, int order)
Inner product of var[] and the LPC coefs.
Definition: lls.h:56
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
internal.h
LLSModel::coeff
double coeff[32][MAX_VARS]
Definition: lls.h:39
avpriv_solve_lls
void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
Definition: lls.c:46