-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using the optimizer #2
Comments
Hi,
First of all, sorry for the late reply. I am travelling right and only have
sporadic internet access.
I didnt try running constrnmpy with python3 so far, and thus never
encountered the problem. Could you try running the same example using py2.7
and see if this is actually a py version problem. Otherwise, we would need
to add an extra test case just testing if UB is None.
Cheers,
Alex
…On Thu, Mar 29, 2018, 10:35 AM pranshrana ***@***.***> wrote:
Hi, I just installed the constrNMPy library and was trying out the
examples. But I get the following error:
C:\Users\User\Desktop\constrNMPy-master\constrNMPy\examples\beales.py
Traceback (most recent call last):
File
"C:\Users\User\Desktop\constrNMPy-master\constrNMPy\examples\beales.py",
line 18, in
res=cNM.constrNM(cNM.test_funcs.beales,x0,LB,UB,full_output=True)
File
"C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\constrnmpy-0.1-py3.6.egg\constrNMPy\constrNMPy.py",
line 60, in constrNM
if not ((x>LB[i] or LB[i]==None) and (x<UB[i] or UB[i]==None)):
TypeError: '<' not supported between instances of 'int' and 'NoneType'
What should I do?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQI2T6Fd2jXqASTO9jTWvLkagrzuxkbsks5tjQ1ggaJpZM4TAoe7>
.
|
if not ((x>LB[i] or LB[i]==None) and (x<UB[i] or UB[i]==None)): you cannot compare an int with a None, so if UB[i] is None, the comparison x < UB[i] will fail if x is an int. In [1]: a = 10 In [3]: a < bTypeError Traceback (most recent call last) TypeError: '<' not supported between instances of 'int' and 'NoneType' In [4]: b is None or a < b In [5]: a < b or b is NoneTypeError Traceback (most recent call last) TypeError: '<' not supported between instances of 'int' and 'NoneType' |
There was a problem comparing Nones with numbers when checking if the initial guess is within boundaries in constrNM. Added an additional check for None. This should fix issue #2.
I fixed the issue by introducing a primary check for None and then checking for boundaries. I hope this fixes the problem. Can you please report back if you still encounter the bug or not so I can close the issue? |
A.
On 5 Jun 2018, at 10:05, Alexander Blaessle ***@***.***> wrote:
I fixed the issue by introducing a primary check for None and then checking for boundaries. I hope this fixes the problem. Can you please report back if you still encounter the bug or not so I can close the issue?
Could you explain as what the intent of these lines (162-165)of code is?
# Add offset if necessary to avoid singularities
for l in LB:
if l == 0:
l = l + offset
as it is now, it is a NOP, e.g. it will not have effect on the data.
How about making the code a bit more pythonic?
e.g. instead of manipulating indexes of arrays, just go over the array data themselves.
# Check if x0 is within bounds
for x, lb, ub in zip(x0, LB, UB):
if not ((lb == None or x > lb) and (ub == None or x < ub)):
errStr = "Initial guess x0 = {} out of bounds {}..{}".format(x, lb, ub)
raise ValueError(errStr)
I could be wrong, but isn’t the transformX function the same as:
def transformX(x, LB, UB):
x = np.asarray(x, dtype=np.float64)
xtrans = []
for xx, lb, ub in zip(x, LB, UB):
if ub != None:
if lb == None:
# Upper bound only
xtrans.append(ub - xx ** 2)
else:
# Both bounds
xtrans.append(max(lb, min(ub, (np.sin(xx) + 1.) / 2. * (ub - lb) + lb)))
elif ub == None
if lb != None:
# Lower bound only
xtrans.append(lb + xx ** 2)
else:
# No bounds
xtrans.append(xx)
return xtrans
Also, as the data is presented in numpy arrays, you might benefit if you could reformulate the calculations in
broadcast / mask operations.
Best regards
.F
|
Hi, I just installed the constrNMPy library and was trying out the examples. But I get the following error:
C:\Users\User\Desktop\constrNMPy-master\constrNMPy\examples\beales.py
Traceback (most recent call last):
File "C:\Users\User\Desktop\constrNMPy-master\constrNMPy\examples\beales.py", line 18, in
res=cNM.constrNM(cNM.test_funcs.beales,x0,LB,UB,full_output=True)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\constrnmpy-0.1-py3.6.egg\constrNMPy\constrNMPy.py", line 60, in constrNM
if not ((x>LB[i] or LB[i]==None) and (x<UB[i] or UB[i]==None)):
TypeError: '<' not supported between instances of 'int' and 'NoneType'
What should I do?
The text was updated successfully, but these errors were encountered: