| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * principal component analysis (PCA) | ||
| 3 | * Copyright (c) 2004 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 | #include "libavutil/pca.c" | ||
| 23 | #include "libavutil/lfg.h" | ||
| 24 | |||
| 25 | #include <stdio.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | |||
| 28 | 1 | int main(void){ | |
| 29 | PCA *pca; | ||
| 30 | int i, j, k; | ||
| 31 | #define LEN 8 | ||
| 32 | double eigenvector[LEN*LEN]; | ||
| 33 | double eigenvalue[LEN]; | ||
| 34 | AVLFG prng; | ||
| 35 | |||
| 36 | 1 | av_lfg_init(&prng, 1); | |
| 37 | |||
| 38 | 1 | pca= ff_pca_init(LEN); | |
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 9000000 times.
✓ Branch 1 taken 1 times.
|
9000001 | for(i=0; i<9000000; i++){ |
| 41 | double v[2*LEN+100]; | ||
| 42 | // double sum=0; | ||
| 43 | 9000000 | int pos = av_lfg_get(&prng) % LEN; | |
| 44 | 9000000 | int v2 = (int)(av_lfg_get(&prng) % 101) - 50; | |
| 45 | 9000000 | v[0] = (int)(av_lfg_get(&prng) % 101) - 50; | |
| 46 |
2/2✓ Branch 0 taken 63000000 times.
✓ Branch 1 taken 9000000 times.
|
72000000 | for(j=1; j<8; j++){ |
| 47 |
2/2✓ Branch 0 taken 31497425 times.
✓ Branch 1 taken 31502575 times.
|
63000000 | if(j<=pos) v[j]= v[0]; |
| 48 | 31502575 | else v[j]= v2; | |
| 49 | // sum += v[j]; | ||
| 50 | } | ||
| 51 | /* for(j=0; j<LEN; j++){ | ||
| 52 | v[j] -= v[pos]; | ||
| 53 | }*/ | ||
| 54 | // sum += av_lfg_get(&prng) % 10; | ||
| 55 | /* for(j=0; j<LEN; j++){ | ||
| 56 | v[j] -= sum/LEN; | ||
| 57 | }*/ | ||
| 58 | // lbt1(v+100,v+100,LEN); | ||
| 59 | 9000000 | ff_pca_add(pca, v); | |
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | 1 | ff_pca(pca, eigenvector, eigenvalue); | |
| 64 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(i=0; i<LEN; i++){ |
| 65 | 8 | pca->count= 1; | |
| 66 | 8 | pca->mean[i]= 0; | |
| 67 | |||
| 68 | // (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x| | ||
| 69 | |||
| 70 | |||
| 71 | // pca.covariance[i + i*LEN]= pow(0.5, fabs | ||
| 72 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
|
44 | for(j=i; j<LEN; j++){ |
| 73 | 36 | printf("%f ", pca->covariance[i + j*LEN]); | |
| 74 | } | ||
| 75 | 8 | printf("\n"); | |
| 76 | } | ||
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(i=0; i<LEN; i++){ |
| 79 | double v[LEN]; | ||
| 80 | 8 | double error=0; | |
| 81 | 8 | memset(v, 0, sizeof(v)); | |
| 82 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for(j=0; j<LEN; j++){ |
| 83 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 64 times.
|
576 | for(k=0; k<LEN; k++){ |
| 84 | 512 | v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN]; | |
| 85 | } | ||
| 86 | 64 | v[j] /= eigenvalue[i]; | |
| 87 | 64 | error += fabs(v[j] - eigenvector[i + j*LEN]); | |
| 88 | } | ||
| 89 | 8 | printf("%f ", error); | |
| 90 | } | ||
| 91 | 1 | printf("\n"); | |
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for(i=0; i<LEN; i++){ |
| 94 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for(j=0; j<LEN; j++){ |
| 95 | 64 | printf("%9.6f ", eigenvector[i + j*LEN]); | |
| 96 | } | ||
| 97 | 8 | printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]); | |
| 98 | } | ||
| 99 | |||
| 100 | 1 | ff_pca_free(pca); | |
| 101 | 1 | return 0; | |
| 102 | } | ||
| 103 |