2

The use of m.abs3() gives result value as 0 for initial value while using in a time series analysis. This further causes 'division by 0' problem in the subsequent calculations.

In the script, for example, for values of x = [-0.010292872139, -0.013621207394, -0.013666766692, -0.013712305714, -0.013757829097, -0.013803253697, -0.013848595166, -0.013893769488, -0.013943077385, -0.013987013738, -0.014030702679], m.abs3(x) returns [0.0, 0.013621207394, 0.013666766692, 0.013712305714, 0.013757829097, 0.013803253697, 0.013848595166, 0.013893769488, 0.013943077385, 0.013987013738, 0.014030702679] as result.

I have tried m.if3(x,-x,x) as a work around as suggested here - How to solve Absolute Value abs() objective with Python Gekko? but the result is still the same as above for m.abs3(x).

Could you please let me know what causes this to occur and is there a way to solve this. Thank you very much.

sriraj
  • 31
  • 3

2 Answers2

1

Assigning a lower bound to the value of x solved the problem; m.x.LOWER = 10**-10

sriraj
  • 31
  • 3
1

One way to solve this problem is to change the initial guess for y to be something other than the default of 0. Here is an example script that shows how to initialize y to 1 with y.value=1.

from gekko import GEKKO
m = GEKKO()
x = m.Param(-1)
y = m.abs3(x)

# initialize y to value 1
y.value = 1

m.Minimize((x/y)**2)
m.solve()
John Hedengren
  • 12,068
  • 1
  • 21
  • 25