Skip to content

Commit

Permalink
optimize: Fix bound transform
Browse files Browse the repository at this point in the history
Closes #575
  • Loading branch information
jschueller committed Nov 25, 2024
1 parent 75dd16e commit 1a5c0c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/api/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
static void x_bound_inv(int n, double *x, const double *lb, const double *ub)
{
int i;
double mid, width, th;
double mid, width, v;
if (!lb || !ub)
return;
for (i = 0; i < n; ++ i)
Expand All @@ -71,8 +71,12 @@ static void x_bound_inv(int n, double *x, const double *lb, const double *ub)
{
mid = (lb[i] + ub[i]) * 0.5;
width = (ub[i] - lb[i]) * 0.5;
th = tanh(x[i]);
x[i] = mid + th * width;
v = (x[i] - mid) / width;
if (v <= -1.0)
v = -1.0 + 1e-12;
if (v >= 1.0)
v = 1.0 - 1e-12;
x[i] = atanh(v);
}
else if (!nlopt_isinf(lb[i]))
x[i] = (x[i] > lb[i]) ? sqrt(x[i] - lb[i]) : 0.0;
Expand Down

0 comments on commit 1a5c0c8

Please sign in to comment.