80 int ff_pca(
PCA *pca,
double *eigenvector,
double *eigenvalue){
86 memset(eigenvector, 0,
sizeof(
double)*n*n);
90 eigenvector[j + j*
n] = 1.0;
100 for(pass=0; pass < 50; pass++){
111 if(eigenvalue[j] > maxvalue){
112 maxvalue= eigenvalue[j];
116 eigenvalue[k]= eigenvalue[i];
117 eigenvalue[i]= maxvalue;
119 double tmp= eigenvector[k + j*
n];
120 eigenvector[k + j*
n]= eigenvector[i + j*
n];
121 eigenvector[i + j*
n]=
tmp;
128 for(j=i+1; j<
n; j++){
130 double t,
c,
s,tau,theta,
h;
132 if(pass < 3 && fabs(covar) < sum / (5*n*n))
134 if(fabs(covar) == 0.0)
136 if(pass >=3 && fabs((eigenvalue[j]+z[j])/covar) > (1LL<<32) && fabs((eigenvalue[i]+z[i])/covar) > (1LL<<32)){
141 h= (eigenvalue[j]+z[j]) - (eigenvalue[i]+z[i]);
143 t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
144 if(theta < 0.0) t = -t;
152 #define ROTATE(a,i,j,k,l) {\
153 double g=a[j + i*n];\
154 double h=a[l + k*n];\
155 a[j + i*n]=g-s*(h+g*tau);\
156 a[l + k*n]=h+s*(g-h*tau); }
161 ROTATE(eigenvector,k,i,k,j)
166 for (i=0; i<
n; i++) {
167 eigenvalue[i] += z[i];
#define ROTATE(a, i, j, k, l)
int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue)
void ff_pca_free(PCA *pca)
void ff_pca_add(PCA *pca, const double *v)
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
principal component analysis (PCA)
common internal and external API header
#define av_malloc_array(a, b)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...