From ea1eb1252b425b55613f9ae57ef2c0da158e28e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20Merelo=20Guerv=C3=B3s?= Date: Wed, 13 Nov 2024 17:33:47 +0100 Subject: [PATCH 1/4] This was an error in the implementation Besides being equivalent to 1 that way, you need to go no further than the formula. --- code-experiments/src/f_katsuura.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-experiments/src/f_katsuura.c b/code-experiments/src/f_katsuura.c index 0055a36a4..0d495e440 100644 --- a/code-experiments/src/f_katsuura.c +++ b/code-experiments/src/f_katsuura.c @@ -43,7 +43,7 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) } /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ - result = 10. / ((double) number_of_variables) / ((double) number_of_variables) + result = 10. / ((double) number_of_variables) * ((double) number_of_variables) * (-1. + result); return result; From 2a99d943f4f95276f196693a965be191e4704330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20Merelo=20Guerv=C3=B3s?= Date: Tue, 19 Nov 2024 07:46:57 +0100 Subject: [PATCH 2/4] This simply makes it clearer Although it's actually equivalent to what was there before. --- code-experiments/src/f_katsuura.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code-experiments/src/f_katsuura.c b/code-experiments/src/f_katsuura.c index 0d495e440..4f5fa7cfa 100644 --- a/code-experiments/src/f_katsuura.c +++ b/code-experiments/src/f_katsuura.c @@ -43,7 +43,7 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) } /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ - result = 10. / ((double) number_of_variables) * ((double) number_of_variables) + result = 10. / (((double) number_of_variables) * ((double) number_of_variables)) * (-1. + result); return result; From 6ced3f60b90c4dffadbefcee544ee772db871ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20Merelo=20Guerv=C3=B3s?= Date: Tue, 19 Nov 2024 07:55:29 +0100 Subject: [PATCH 3/4] Put everything on the same line and eliminate unneeded parentheses This should be equivalent to what was there before, but now the translation of the formula seems clearer. Don't understand the point of the ((double) x) except if it was to force some kind of precedence (which is not needed if you wrap everything with parentheses) --- code-experiments/src/f_katsuura.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code-experiments/src/f_katsuura.c b/code-experiments/src/f_katsuura.c index 4f5fa7cfa..295976aba 100644 --- a/code-experiments/src/f_katsuura.c +++ b/code-experiments/src/f_katsuura.c @@ -43,8 +43,7 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) } /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ - result = 10. / (((double) number_of_variables) * ((double) number_of_variables)) - * (-1. + result); + result = 10. / ((double) number_of_variables * (double) number_of_variables) * (-1. + result); return result; } From 4b3289bf30668305411ecbb05e3de6d2360eeedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20Merelo=20Guerv=C3=B3s?= Date: Tue, 19 Nov 2024 07:59:49 +0100 Subject: [PATCH 4/4] :recycle: to make it even closer to the formula And avoid making repeated conversions. --- code-experiments/src/f_katsuura.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code-experiments/src/f_katsuura.c b/code-experiments/src/f_katsuura.c index 295976aba..6c9554714 100644 --- a/code-experiments/src/f_katsuura.c +++ b/code-experiments/src/f_katsuura.c @@ -24,13 +24,13 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) size_t i, j; double tmp, tmp2; - double result; if (coco_vector_contains_nan(x, number_of_variables)) return NAN; /* Computation core */ - result = 1.0; + double result = 1.0; + double D = (double) number_of_variables; for (i = 0; i < number_of_variables; ++i) { tmp = 0; for (j = 1; j < 33; ++j) { @@ -39,11 +39,11 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) } tmp = 1.0 + ((double) (long) i + 1) * tmp; /*result *= tmp;*/ /* Wassim TODO: delete once consistency check passed*/ - result *= pow(tmp, 10. / pow((double) number_of_variables, 1.2)); + result *= pow(tmp, 10. / pow(D, 1.2)); } /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ - result = 10. / ((double) number_of_variables * (double) number_of_variables) * (-1. + result); + result = 10. / (D * D) * (-1. + result); return result; }