Go to the documentation of this file.
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); }
166 for (
i=0;
i<n;
i++) {
167 eigenvalue[
i] += z[
i];
#define ROTATE(a, i, j, k, l)
void ff_pca_free(PCA *pca)
static __device__ float fabs(float a)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define i(width, name, range_min, range_max)
#define av_malloc_array(a, b)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue)
void ff_pca_add(PCA *pca, const double *v)