Issue computing Hessian with Foward mode

26 views
Skip to first unread message

Gustavo Chaparro

unread,
Jan 25, 2018, 7:41:25 AM1/25/18
to algopy
Hey! I am beginner using python from scientific computation and I am just discovering the capabilities of Algopy (such a great work btw).
So far I am having some issues when computing the Hessian of a scalar function with the forward mode, thi is my code so far:

import numpy as np
import algopy
from algopy import UTPM

g12, g21, g13, g31, g23,g32
g=np.array([1337.69,-235.61,1456.94,998.39,-935.27,680.02])
g12,g21,g13,g31,g23,g32=g
A=np.array([[0,g12,g13],[g21,0,g23],[g31,g32,0]])
#α12,13,32
α=0.2
T=313.15
def NRTL(X0,T):
    x1,x2=X0
    X=np.array([x1,x2,1-x1-x2])
    τ=A/T
    G=np.exp(-α*τ)
    P1=np.sum(X*τ.T*G.T,1)/np.sum(X*G.T,1)
    P2=X*G/np.sum(X*G.T,1)
    P3=τ-P1
    lnγ=np.sum(P3*P2,1)+P1
    Gex=np.sum(X*lnγ)
    return Gex

X=np.array([0.3,0.4])
#algopy
x = UTPM.init_hessian(X)
y = NRTL(x,T)
algopy_jacobian = UTPM.extract_hessian(2,y)

I keep getting the following error: 
TypeError: 'float' object cannot be interpreted as an integer

I also tried with some of the examples on the documentation (https://pythonhosted.org/algopy/examples/ampl_minimization_problem.html,
 https://pythonhosted.org/algopy/examples/hessian_of_potential_function.html) and I got the same error. 
When I use the reverse mode everything is working properly.

do you any suggestions?
Thanks in advance!
Gustavo.

Sebastian Walter

unread,
Jan 25, 2018, 8:30:34 AM1/25/18
to alg...@googlegroups.com
I can't reproduce the issue. After replacing the greek unicode symbosl to ASCII tau, gamma and alpha, the code seems to work fine.
What version of Algopy and Python do you use?


--
You received this message because you are subscribed to the Google Groups "algopy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to algopy+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gustavo Chaparro

unread,
Jan 25, 2018, 1:06:43 PM1/25/18
to algopy
Thanks for replying!

Python: 3.6.3
Numpy version:  1.13.3
Scipy: 0.19.1
Algopy: 0.5.3

I tried changing greek letters and still the same :/
To unsubscribe from this group and stop receiving emails from it, send an email to algopy+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages