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)