From e202f0cba948321acd7fef8554e3751511e37370 Mon Sep 17 00:00:00 2001 From: theresa Date: Wed, 10 Apr 2024 15:34:56 +0200 Subject: [PATCH 1/4] added kernel der_laplacian_rbf --- applications/fastsum/fastsum.m | 1 + applications/fastsum/fastsum_matlab.c | 2 ++ applications/fastsum/fastsum_test.c | 2 ++ applications/fastsum/kernels.c | 17 +++++++++++++++++ applications/fastsum/kernels.h | 1 + 5 files changed, 23 insertions(+) diff --git a/applications/fastsum/fastsum.m b/applications/fastsum/fastsum.m index 2358b985..3aefc435 100644 --- a/applications/fastsum/fastsum.m +++ b/applications/fastsum/fastsum.m @@ -48,6 +48,7 @@ % 'cot' K(x) = cot(cx) % 'one_over_cube' K(x) = 1/x^3 % 'laplacian_rbf' K(x) = EXP(-|x|/c) +% 'der_laplacian_rbf' K(x) = |x|/c EXP(-|x|/c) % 'xx_gaussian' K(x) = x^2/c^2 EXP(-x^2/c^2) % 'absx' K(x) = |x| % diff --git a/applications/fastsum/fastsum_matlab.c b/applications/fastsum/fastsum_matlab.c index 365eab23..952cb91f 100644 --- a/applications/fastsum/fastsum_matlab.c +++ b/applications/fastsum/fastsum_matlab.c @@ -122,6 +122,8 @@ int main(int argc, char **argv) kernel = log_sin; else if (strcmp(s, "laplacian_rbf") == 0) kernel = laplacian_rbf; + else if (strcmp(s, "der_laplacian_rbf") == 0) + kernel = der_laplacian_rbf; else if (strcmp(s, "xx_gaussian") == 0) kernel = xx_gaussian; else if (strcmp(s, "absx") == 0) diff --git a/applications/fastsum/fastsum_test.c b/applications/fastsum/fastsum_test.c index 016e6eb4..a9a0ea99 100644 --- a/applications/fastsum/fastsum_test.c +++ b/applications/fastsum/fastsum_test.c @@ -124,6 +124,8 @@ int main(int argc, char **argv) kernel = log_sin; else if (strcmp(s, "laplacian_rbf") == 0) kernel = laplacian_rbf; + else if (strcmp(s, "der_laplacian_rbf") == 0) + kernel = der_laplacian_rbf; else if (strcmp(s, "xx_gaussian") == 0) kernel = xx_gaussian; else if (strcmp(s, "absx") == 0) diff --git a/applications/fastsum/kernels.c b/applications/fastsum/kernels.c index f17f66b3..4b79f864 100644 --- a/applications/fastsum/kernels.c +++ b/applications/fastsum/kernels.c @@ -431,6 +431,23 @@ C laplacian_rbf(R x, int der, const R *param) /* K(x)=EXP(-|x|/c) */ return value; } +C der_laplacian_rbf(R x, int der, const R *param) /* K(x)=|x|/c EXP(-|x|/c) */ +{ + R c = param[0]; + R value = K(0.0); + + switch (der) + { + case 0 : value = (FABS(x)/c)*EXP(-FABS(x)/c); break; + default: + value = (POW(K(-1.0),(R)der))*((FABS(x)-(R)der*c)/POW(c,(R)der+1))*EXP(-FABS(x)/c); + if (x < K(0.0)) + value *= POW(K(-1.0),(R)der); + } + + return value; +} + C xx_gaussian(R x, int der, const R *param) /* K(x)=x^2/c^2 EXP(-x^2/c^2) */ { R c = param[0]; diff --git a/applications/fastsum/kernels.h b/applications/fastsum/kernels.h index f5766ff7..0742c1b8 100644 --- a/applications/fastsum/kernels.h +++ b/applications/fastsum/kernels.h @@ -56,6 +56,7 @@ C kcot(R x, int der, const R *param); /**< K(x) = cot(cx) */ C one_over_cube(R x, int der, const R *param); /**< K(x) = 1/x^3 */ C log_sin(R x, int der, const R *param); /**< K(x) = log(|sin(cx)|) */ C laplacian_rbf(R x, int der, const R *param); /**< K(x) = exp(-|x|/c) */ +C der_laplacian_rbf(R x, int der, const R *param); /**< K(x) = |x|/c exp(-|x|/c) */ C xx_gaussian(R x, int der, const R *param); /**< K(x) = x^2/c^2 exp(-x^2/c^2) */ C absx(R x, int der, const R *param); /**< K(x) = |x| */ /* \} */ From 583def2e4d10cfc27238c7d4a472c51f3dda2f25 Mon Sep 17 00:00:00 2001 From: theresa Date: Wed, 10 Apr 2024 15:54:43 +0200 Subject: [PATCH 2/4] adapted julia and matlab files for der_laplacian_kernel --- julia/fastsum/libfastsumjulia.c | 2 ++ matlab/fastsum/fastsummex.c | 2 ++ matlab/fastsum/simple_test.m | 1 + matlab/fastsum/test_fastsum.m | 1 + 4 files changed, 6 insertions(+) diff --git a/julia/fastsum/libfastsumjulia.c b/julia/fastsum/libfastsumjulia.c index 8b42fd75..c74021b2 100644 --- a/julia/fastsum/libfastsumjulia.c +++ b/julia/fastsum/libfastsumjulia.c @@ -55,6 +55,8 @@ int jfastsum_init( fastsum_plan* p, int d, char* s, double* c, unsigned int f, i kernel = log_sin; else if ( strcmp(s, "laplacian_rbf") == 0 ) kernel = laplacian_rbf; + else if ( strcmp(s, "der_laplacian_rbf") == 0 ) + kernel = der_laplacian_rbf; else if ( strcmp(s, "xx_gaussian") == 0 ) kernel = xx_gaussian; else if ( strcmp(s, "absx") == 0 ) diff --git a/matlab/fastsum/fastsummex.c b/matlab/fastsum/fastsummex.c index 47fece56..ea50560a 100644 --- a/matlab/fastsum/fastsummex.c +++ b/matlab/fastsum/fastsummex.c @@ -134,6 +134,8 @@ static kernel get_kernel(const mxArray *p) ker = log_sin; else if (strcmp(s, "laplacian_rbf") == 0) ker = laplacian_rbf; + else if (strcmp(s, "der_laplacian_rbf") == 0) + ker = der_laplacian_rbf; else if (strcmp(s, "xx_gaussian") == 0) ker = xx_gaussian; else if (strcmp(s, "absx") == 0) diff --git a/matlab/fastsum/simple_test.m b/matlab/fastsum/simple_test.m index d5534f26..6ed15571 100644 --- a/matlab/fastsum/simple_test.m +++ b/matlab/fastsum/simple_test.m @@ -39,6 +39,7 @@ % 'one_over_cube' K(x) = 1/x^3 % 'log_sin' K(x) = LOG(|SIN(cx)|) % 'laplacian_rbf' K(x) = EXP(-|x|/c) +% 'der_laplacian_rbf' K(x) = |x|/c EXP(-|x|/c) % 'xx_gaussian' K(x) = x^2/c^2 EXP(-x^2/c^2) % 'absx' K(x) = |x| diff --git a/matlab/fastsum/test_fastsum.m b/matlab/fastsum/test_fastsum.m index d316a0c2..ab1aff68 100644 --- a/matlab/fastsum/test_fastsum.m +++ b/matlab/fastsum/test_fastsum.m @@ -39,6 +39,7 @@ % 'one_over_cube' K(x) = 1/x^3 % 'log_sin' K(x) = LOG(|SIN(cx)|) % 'laplacian_rbf' K(x) = EXP(-|x|/c) +% 'der_laplacian_rbf' K(x) = |x|/c EXP(-|x|/c) % 'xx_gaussian' K(x) = x^2/c^2 EXP(-x^2/c^2) % 'absx' K(x) = |x| From e1ef14cccd39ef916eec88526c0c6d8b5a6a956b Mon Sep 17 00:00:00 2001 From: theresa Date: Tue, 16 Apr 2024 13:15:00 +0200 Subject: [PATCH 3/4] increased efficiency of computations --- applications/fastsum/kernels.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/applications/fastsum/kernels.c b/applications/fastsum/kernels.c index 4b79f864..ee9d0575 100644 --- a/applications/fastsum/kernels.c +++ b/applications/fastsum/kernels.c @@ -441,8 +441,7 @@ C der_laplacian_rbf(R x, int der, const R *param) /* K(x)=|x|/c EXP(-|x|/c) * case 0 : value = (FABS(x)/c)*EXP(-FABS(x)/c); break; default: value = (POW(K(-1.0),(R)der))*((FABS(x)-(R)der*c)/POW(c,(R)der+1))*EXP(-FABS(x)/c); - if (x < K(0.0)) - value *= POW(K(-1.0),(R)der); + value *= 1 - 2 * ((x < K(0.0)) && (der % 2.0)); } return value; From 5098ca9593f4440b7c06708e6f3283e65363fe09 Mon Sep 17 00:00:00 2001 From: theresa Date: Tue, 16 Apr 2024 13:35:12 +0200 Subject: [PATCH 4/4] fixed bug --- applications/fastsum/kernels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/fastsum/kernels.c b/applications/fastsum/kernels.c index ee9d0575..de27b90a 100644 --- a/applications/fastsum/kernels.c +++ b/applications/fastsum/kernels.c @@ -441,7 +441,7 @@ C der_laplacian_rbf(R x, int der, const R *param) /* K(x)=|x|/c EXP(-|x|/c) * case 0 : value = (FABS(x)/c)*EXP(-FABS(x)/c); break; default: value = (POW(K(-1.0),(R)der))*((FABS(x)-(R)der*c)/POW(c,(R)der+1))*EXP(-FABS(x)/c); - value *= 1 - 2 * ((x < K(0.0)) && (der % 2.0)); + value *= 1 - 2 * ((x < K(0.0)) && (der % 2)); } return value;