lls.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <limits.h>
  19. #include <stdio.h>
  20. #include "libavutil/internal.h"
  21. #include "libavutil/lfg.h"
  22. #include "libavutil/lls.h"
  23. int main(void)
  24. {
  25. LLSModel m;
  26. int i, order;
  27. AVLFG lfg;
  28. av_lfg_init(&lfg, 1);
  29. avpriv_init_lls(&m, 3);
  30. for (i = 0; i < 100; i++) {
  31. LOCAL_ALIGNED(32, double, var, [4]);
  32. double eval;
  33. var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
  34. var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
  35. var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
  36. var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
  37. m.update_lls(&m, var);
  38. avpriv_solve_lls(&m, 0.001, 0);
  39. for (order = 0; order < 3; order++) {
  40. eval = m.evaluate_lls(&m, var + 1, order);
  41. printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
  42. var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
  43. m.coeff[order][0], m.coeff[order][1],
  44. m.coeff[order][2]);
  45. }
  46. }
  47. return 0;
  48. }