X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2Fsrc%2Ffunctions.c;h=f311a34d52d7c468f3697ed9669eb2d229423302;hb=bbdcfe44da4011574dabb19b4f83e2ab199c667a;hp=42bb1343c8fdb7b47c663fd4869ff65a4fa2149f;hpb=4263503b0fbe45a6fa5b353c8405e30557b3dd70;p=morpheus.git diff --git a/pkg/src/functions.c b/pkg/src/functions.c index 42bb134..f311a34 100644 --- a/pkg/src/functions.c +++ b/pkg/src/functions.c @@ -1,18 +1,18 @@ #include -//index matrix (by columns) +// Index matrix (by columns) int mi(int i, int j, int d1, int d2) { - return j*d1+i; + return j*d1 + i; } -//index 3-tensor (by columns, matrices ordered by last dim) +// 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; } -// Emprical cross-moment of order 2 between X size nxd and Y size n +// 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; @@ -30,7 +30,7 @@ void Moments_M2(double* X, double* Y, int* pn, int* pd, double* M2) } } -// Emprical cross-moment of order 3 between X size nxd and Y size n +// Empirical cross-moment of order 3 between X size nxd and Y size n void Moments_M3(double* X, double* Y, int* pn, int* pd, double* M3) { int n=*pn, d=*pd; @@ -54,9 +54,55 @@ void Moments_M3(double* X, double* Y, int* pn, int* pd, double* M3) } } -void Compute_Omega(double* X, double* Y, int* pn, int* pd, double* W) +// 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) { - // TODO: formula 1/N sum( t(g(Zi,theta)) g(Zi,theta) ) - // = 1/N sum( t( (XiYi-...) - theta[i] ) ( ... ) ) - // --> similar to Moments_M2 and M3 above + int n=*pn, d=*pd; + int dim = d + d*d + d*d*d; + //double* W = (double*)malloc(dim*dim*sizeof(double)); + + // (Re)Initialize W: + for (int j=0; j