X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Fsrc%2Ffunctions.c;h=6444b8649875ef2022fb5151aa77207743c48740;hp=68f1b79d60369d596a21c658e2c8e1f5a3aa2213;hb=9fdd3e5f57aa1fd0f839214d9cbfac022a8739a8;hpb=4bf8494d8484be5eab39dd2a83e649678a2de713 diff --git a/pkg/src/functions.c b/pkg/src/functions.c index 68f1b79..6444b86 100644 --- a/pkg/src/functions.c +++ b/pkg/src/functions.c @@ -1,77 +1,61 @@ #include +#include // Index matrix (by columns) -int mi(int i, int j, int d1, int d2) -{ - return j*d1 + i; -} +#define mi(i, j, d1, d2) (j*d1 + i) // Index 3-tensor (by columns, matrices ordered by last dim) -int ti(int i, int j, int k, int d1, int d2, int d3) -{ - return k*d1*d2 + j*d1 + i; -} +#define ti(i, j, k, d1, d2, d3) (k*d1*d2 + j*d1 + i) // Empirical cross-moment of order 2 between X size nxd and Y size n void Moments_M2(double* X, double* Y, int* pn, int* pd, double* M2) { - int n=*pn, d=*pd; - //double* M2 = (double*)calloc(d*d,sizeof(double)); + int n=*pn, d=*pd; + //double* M2 = (double*)calloc(d*d,sizeof(double)); - // M2 = E[Y*X^*2] - E[Y*e^*2] = E[Y (X^*2 - I)] - for (int j=0; j - // W = 1/N sum( t(g(Zi,theta)) g(Zi,theta) ) // with g(Zi, theta) = i-th contribution to all moments (size dim) - real moments -void Compute_Omega(double* X, double* Y, double* M, int* pn, int* pd, double* W) +void Compute_Omega(double* X, int* Y, double* M, int* pnc, int* pn, int* pd, double* W) { - int n=*pn, d=*pd; + int nc=*pnc, n=*pn, d=*pd; int dim = d + d*d + d*d*d; - -//printf("X: \n"); -//for (int kk=0; kk= 1 ? nc : omp_get_num_procs()); + #pragma omp parallel for for (int i=0; i=0; k--) + W[baseIdx+k] += gj * g[k]; } } + // Normalize W: x 1/n + for (int j=0; j j + for (int j=0; j