2 * principal component analysis (PCA)
3 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/pca.c"
23 #include "libavutil/lfg.h"
33 double eigenvector[LEN*LEN];
34 double eigenvalue[LEN];
37 av_lfg_init(&prng, 1);
39 pca= ff_pca_init(LEN);
41 for(i=0; i<9000000; i++){
44 int pos = av_lfg_get(&prng) % LEN;
45 int v2 = av_lfg_get(&prng) % 101 - 50;
46 v[0] = av_lfg_get(&prng) % 101 - 50;
48 if(j<=pos) v[j]= v[0];
52 /* for(j=0; j<LEN; j++){
55 // sum += av_lfg_get(&prng) % 10;
56 /* for(j=0; j<LEN; j++){
59 // lbt1(v+100,v+100,LEN);
64 ff_pca(pca, eigenvector, eigenvalue);
69 // (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
72 // pca.covariance[i + i*LEN]= pow(0.5, fabs
74 printf("%f ", pca->covariance[i + j*LEN]);
82 memset(v, 0, sizeof(v));
85 v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
87 v[j] /= eigenvalue[i];
88 error += fabs(v[j] - eigenvector[i + j*LEN]);
96 printf("%9.6f ", eigenvector[i + j*LEN]);
98 printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);