本文整理汇总了Python中utilities.quadratic_dot函数的典型用法代码示例。如果您正苦于以下问题:Python quadratic_dot函数的具体用法?Python quadratic_dot怎么用?Python quadratic_dot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quadratic_dot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: d2y_SZ
def d2y_SZ(z_i):
DFi,df,Hf = DF(z_i)[n:],self.df(z_i),self.Hf(z_i)
d,d2y_ZZ = self.get_d(z_i),self.d2y[Z,Z](z_i)
temp = np.linalg.inv(DFi[:,y] + DFi[:,e].dot(df) + self.dZ_Z[0]*DFi[:,v].dot(Ivy))
return -np.tensordot(temp, self.HFhat[S,Z](z_i)
+ np.tensordot(DFi[:,e],quadratic_dot(Hf,d[y,S],d[y,Z]),1)
+ np.tensordot(DFi[:,v].dot(Ivy), quadratic_dot(d2y_ZZ,IZY.dot(d[Y,S]),self.dZ_Z),1),1)
示例2: compute_ye
def compute_ye(x):
z_i,zbar = x
extreme = Para.check_extreme(z_i)
zhat = z_i-zbar
r = np.random.randn(neps)
for i in range(neps):
r[i] = min(3.,max(-3.,r[i]))
e = r*sigma
Shat = np.hstack([zhat,Y1hat])
if not extreme:
return np.hstack(( self.ss.get_y(zbar).flatten() + self.dy[eps](zbar).dot(e).flatten() + (self.dy[Eps](zbar).flatten())*0.
+ self.dy[p](zbar).dot(phat).flatten()
+ self.dy[z](zbar).dot(zhat).flatten()
+ self.dy[Y](zbar).dot(Y1hat).flatten()
+ self.dy[Z](zbar).dot(Zhat).flatten()
+ 0.5*quadratic*(quadratic_dot(self.d2y[eps,eps](zbar),e,e).flatten() + self.d2y[sigma](zbar).dot(sigma**2).flatten()
+quadratic_dot(self.d2y[S,S](zbar),Shat,Shat) + 2*quadratic_dot(self.d2y[S,eps](zbar),Shat,e)
+self.dy[Y](zbar).dot(Y2hat)
+2*quadratic_dot(self.d2y[Z,S](zbar),Zhat,Shat)
+2*quadratic_dot(self.d2y[Z,eps](zbar),Zhat,e)
+quadratic_dot(self.d2y[Z,Z](zbar),Zhat,Zhat)
+2*np.einsum('ijk,jk,k',self.dy[Y,S,Z](zbar),Y2hat_GZ,Zhat)
+2*np.einsum('ijk,jk,k',self.d2y[Y,S,Z](zbar),Y2hat_GZ,IZYhat.dot(Y1hat))
+self.d2y[Eps,Eps](zbar).flatten()*sigma_E**2
+self.d2y[sigma_E](zbar).flatten()*sigma_E**2
).flatten()
,e))
示例3: d2y_SS
def d2y_SS(z_i):
DF,df,Hf = self.DF(z_i),self.df(z_i),self.Hf(z_i)
d = self.get_d(z_i)
DFi = DF[n:]
return np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,e].dot(df) + DFi[:,v].dot(Ivy)),
-self.HFhat[S,S](z_i) - np.tensordot(DFi[:,e],quadratic_dot(Hf,d[y,S],d[y,S]),1)
-np.tensordot(DFi[:,v].dot(Ivy),quadratic_dot(self.d2y[Z,Z](z_i),IZY.dot(d[Y,S]),IZY.dot(d[Y,S])),1)
, axes=1)
示例4: d2y_SS
def d2y_SS(z_i):
DF,df,Hf = self.DF(z_i),self.df(z_i),self.Hf(z_i)
d = self.get_d(z_i)
DFi = DF[n:]
return np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,e].dot(df) + DFi[:,v].dot(Ivy)),
-self.HFhat[S,S](z_i) - np.tensordot(DFi[:,e],quadratic_dot(Hf,d[y,S],d[y,S]),1)
-np.tensordot(DFi[:,v].dot(Ivy),quadratic_dot(self.d2y[Z,Z](z_i),IZYhat.dot(d[Y,S]),IZYhat.dot(d[Y,S])),1)
-2*np.einsum('ij...,j...->i...',DFi[:,v].dot(Ivy),quadratic_dot(self.d2y[Z,S](z_i),IZYhat.dot(d[Y,S]),np.eye(nY+nz)))
, axes=1)
示例5: DFhat_EpsEps
def DFhat_EpsEps(z_i):
dSprime_Eps_i,dZprime_Eps = dSprime_Eps(z_i),IZYhat.dot(self.dY_Eps)
DFi = DF(z_i)[:-n]
return self.HFhat[Eps,Eps](z_i) + np.tensordot(DFi[:,v].dot(Ivy),
quadratic_dot(self.d2y[S,S](z_i),dSprime_Eps_i,dSprime_Eps_i)
+2*quadratic_dot(self.d2y[S,Z](z_i),dSprime_Eps_i,dZprime_Eps)
+quadratic_dot(self.d2y[Z,Z](z_i),dZprime_Eps,dZprime_Eps)
+np.tensordot(self.dy[Y](z_i),d2Yprime_EpsEps,1)
+2*np.einsum('ijk,jlkm',self.dy[Y,S,Z](z_i),d2YprimeGZ_EpsEps1) #from dy_GammaZ
+2*np.einsum('ijk,jlkm',self.d2y[Y,S,Z](z_i),d2YprimeGZ_EpsEps2) #from dy_GammaGamma
,axes=1)
示例6: d2y_SZ
def d2y_SZ(z_i):
DFi,df,Hf = DF(z_i)[n:],self.df(z_i),self.Hf(z_i)
d,d2y_ZZ = self.get_d(z_i),self.d2y[Z,Z](z_i)
temp = -(self.HFhat[S,Z](z_i) + np.tensordot(DFi[:,e],quadratic_dot(Hf,d[y,S],d[y,Z]),1)
+ np.tensordot(DFi[:,v].dot(Ivy), quadratic_dot(d2y_ZZ,IZYhat.dot(d[Y,S]),self.dZ_Z),1) )
d2y_SZ = np.empty((ny,nY+nz,nZ))
for i,rho in enumerate(D):
temp2 = np.linalg.inv(DFi[:,y] + DFi[:,e].dot(df) + rho*DFi[:,v].dot(Ivy))
d2y_SZ[:,:,i] = temp2.dot(temp[:,:,i])
return d2y_SZ
示例7: HFhat_temp
def HFhat_temp(z_i,x1=x1,x2=x2):
HF = self.HF(z_i)
d = self.get_d(z_i)
HFhat = 0.
for y1 in [y,e,Y,z,v,eps]:
HFy1 = HF[:,y1,:]
for y2 in [y,e,Y,z,v,eps]:
if x1 == S and x2 == S:
HFhat += quadratic_dot(HFy1[n:,:,y2],d[y1,x1],d[y2,x2])
else:
HFhat += quadratic_dot(HFy1[:-n,:,y2],d[y1,x1],d[y2,x2])
return HFhat
示例8: HFhat_temp
def HFhat_temp(z_i,x1=x1,x2=x2):
HF = self.HF(z_i)
d = self.get_d(z_i)
HFhat = 0.
for y1 in [y,e,Y,Z,z,v,eps,Eps]:
HFy1 = HF[:,y1,:]
for y2 in [y,e,Y,Z,z,v,eps,Eps]:
if x1.__hash__() in shock_hashes or x2.__hash__() in shock_hashes:
HFhat += quadratic_dot(HFy1[:-n,:,y2],d[y1,x1],d[y2,x2])
else:
HFhat += quadratic_dot(HFy1[n:,:,y2],d[y1,x1],d[y2,x2])
return HFhat
示例9: compute_dsigma
def compute_dsigma(self):
'''
Computes how dY and dy_i depend on sigma
'''
DG = self.DG
#Now how do things depend with sigma
integral_term =self.integrate(lambda z_i:
quadratic_dot(self.d2Y[z,z](z_i),Izy.dot(self.dy[eps](z_i)),Izy.dot(self.dy[eps](z_i))).flatten()
+ self.dY(z_i).dot(Izy).dot(self.d2y[eps,eps](z_i).flatten()))
ABCi = self.interpolate(parallel_map(lambda z_i:self.compute_d2y_sigma(z_i,integral_term),self.zgrid) )
Ai,Bi,Ci = dict_fun(ABCi[:,0]),dict_fun(ABCi[:,1:nY+1]),dict_fun(ABCi[:,nY+1:])
Atild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Ai(z_i)))
Btild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Bi(z_i)))
Ctild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Ci(z_i)))
tempC = np.linalg.inv(np.eye(nY)-Ctild)
DGhat = self.integrate(self.interpolate(parallel_map(self.compute_DGhat_sigma,self.zgrid)))
temp1 = self.integrate(lambda z_i:DG(z_i)[:,Y] + DG(z_i)[:,y].dot(Bi(z_i)+Ci(z_i).dot(tempC).dot(Btild)) )
temp2 = self.integrate(lambda z_i:DG(z_i)[:,y].dot(Ai(z_i)+Ci(z_i).dot(tempC).dot(Atild)) )
self.d2Y[sigma] = np.linalg.solve(temp1,-DGhat-temp2)
self.d2y[sigma] = dict_fun(self.interpolate(
parallel_map(lambda z_i: Ai(z_i) + Ci(z_i).dot(tempC).dot(Atild) +
( Bi(z_i)+Ci(z_i).dot(tempC).dot(Btild) ).dot(self.d2Y[sigma]),self.zgrid)))
示例10: compute_dsigma
def compute_dsigma(self):
'''
Computes how dY and dy_i depend on sigma
'''
DG = lambda z_i : self.DG(z_i)[nG:,:]
#Now how do things depend with sigma
self.integral_term =self.integrate(lambda z_i:
quadratic_dot(self.d2Y[z,z](z_i),Izy.dot(self.dy[eps](z_i)),Izy.dot(self.dy[eps](z_i))).diagonal(0,1,2)
+ self.dY(z_i).dot(Izy).dot(self.d2y[eps,eps](z_i).diagonal(0,1,2)))
ABCi = dict_fun(self.compute_d2y_sigma )
Ai,Bi,Ci = lambda z_i : ABCi(z_i)[:,:neps], lambda z_i : ABCi(z_i)[:,neps:nY+neps], lambda z_i : ABCi(z_i)[:,nY+neps:]
Atild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Ai(z_i)))
Btild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Bi(z_i)))
Ctild = self.integrate(lambda z_i: self.dY(z_i).dot(Izy).dot(Ci(z_i)))
tempC = np.linalg.inv(np.eye(nY)-Ctild)
DGhat = self.integrate(self.compute_DGhat_sigma)
temp1 = self.integrate(lambda z_i:DG(z_i)[:,Y] + DG(z_i)[:,y].dot(Bi(z_i)+Ci(z_i).dot(tempC).dot(Btild)) )
temp2 = self.integrate(lambda z_i:DG(z_i)[:,y].dot(Ai(z_i)+Ci(z_i).dot(tempC).dot(Atild)) )
self.d2Y[sigma] = np.linalg.solve(temp1,-DGhat-temp2)
self.d2y[sigma] = dict_fun(lambda z_i: Ai(z_i) + Ci(z_i).dot(tempC).dot(Atild) +
( Bi(z_i)+Ci(z_i).dot(tempC).dot(Btild) ).dot(self.d2Y[sigma]))
示例11: d2y_epseps
def d2y_epseps(z_i):
DF = self.DF(z_i)
d = self.get_d(z_i)
DFi = DF[:-n]
return np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,v].dot(Ivy).dot(d[y,z]).dot(Izy)),
-self.HFhat[eps,eps](z_i) - np.tensordot(DFi[:,v].dot(Ivy),
quadratic_dot(self.d2y[S,S](z_i)[:,:nz,:nz],d[z,eps],d[z,eps]),1)
,axes=1)
示例12: HGhat
def HGhat(z_i,y1,y2):
HG = self.HG(z_i)[:-nG,:]
d = self.get_d(z_i)
HGhat = np.zeros((nY,len(y1),len(y2)))
for x1 in [y,z,Y,Z,Eps]:
HGx1 = HG[:,x1,:]
for x2 in [y,z,Y,Z,Eps]:
HGhat += quadratic_dot(HGx1[:,:,x2],d[x1,y1],d[x2,y2])
return HGhat
示例13: d2y_Seps
def d2y_Seps(z_i):
DF = self.DF(z_i)
d = self.get_d(z_i)
DFi = DF[:-n]
dz_eps= Izy.dot(d[y,eps])
return np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,v].dot(Ivy).dot(d[y,z]).dot(Izy)),
-self.HFhat[S,eps](z_i) - np.tensordot(DFi[:,v].dot(Ivy), self.d2y[S,S](z_i)[:,:,:nz].dot(dz_eps),1)
-np.tensordot(DFi[:,v].dot(Ivy), quadratic_dot(self.d2y[Z,S](z_i)[:,:,:nz],IZYhat.dot(d[Y,S]),dz_eps),1)
, axes=1)
示例14: compute_ye
def compute_ye(z_i):
r = np.random.randn(neps)
for i in range(neps):
if z_i[0] > logm_min and z_i[1] > muhat_min:
r[i] = min(3.,max(-3.,r[i]))
else:
r[i] = min(1.,max(logm_min-z_i[0]+0.1,(muhat_min-z_i[1])/10. +0.1))
e = r*sigma
return np.hstack(( self.ss.get_y(z_i).flatten() + self.dy[eps](z_i).dot(e).flatten() + self.dy[Eps](z_i).flatten()*E
+ self.dy[p](z_i).dot(phat).flatten()
+ 0.5*quadratic*(quadratic_dot(self.d2y[eps,eps](z_i),e,e).flatten() + self.d2y[sigma](z_i).dot(sigma**2).flatten()).flatten()
,e))
示例15: compute_DGhat
def compute_DGhat(self,z_i):
'''
Computes the second order approximation for agent of type z_i
'''
DG,HG = self.DG(z_i)[nG:,:],self.HG(z_i)[nG:,:,:]
d = self.get_d(z_i)
d2y = self.d2y
DGhat = np.zeros((nY,nz+nY,nz+nY))
DGhat += np.tensordot(DG[:,y],d2y[S,S](z_i),1)
for x1 in [y,Y,z]:
HGx1 = HG[:,x1,:]
for x2 in [y,Y,z]:
DGhat += quadratic_dot(HGx1[:,:,x2],d[x1,S],d[x2,S])
return DGhat