本文整理汇总了Python中utilities.quadratic_dot函数的典型用法代码示例。如果您正苦于以下问题:Python quadratic_dot函数的具体用法?Python quadratic_dot怎么用?Python quadratic_dot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quadratic_dot函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:7,代码来源:approximate_aggstate_noshock.py
示例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))
开发者ID:dgevans,项目名称:IdioInvest,代码行数:27,代码来源:approximate_aggstate_test.py
示例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)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:8,代码来源:approximate_aggstate_noshock.py
示例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)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:9,代码来源:approximate_aggstate_test.py
示例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)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:11,代码来源:approximate_aggstate_test.py
示例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
开发者ID:dgevans,项目名称:IdioInvest,代码行数:11,代码来源:approximate_aggstate_test.py
示例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
开发者ID:dgevans,项目名称:IdioApprox,代码行数:12,代码来源:approximate_nointerp.py
示例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
开发者ID:dgevans,项目名称:IdioInvest,代码行数:12,代码来源:approximate_aggstate_test.py
示例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)))
开发者ID:dgevans,项目名称:IdioApprox,代码行数:26,代码来源:approximate_parallel.py
示例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]))
开发者ID:dgevans,项目名称:IdioInvest,代码行数:25,代码来源:approximate_aggstate_test.py
示例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)
开发者ID:dgevans,项目名称:IdioApprox,代码行数:8,代码来源:approximate_nointerp.py
示例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
开发者ID:dgevans,项目名称:IdioInvest,代码行数:9,代码来源:approximate_aggstate_test.py
示例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)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:9,代码来源:approximate_aggstate_test.py
示例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))
开发者ID:dgevans,项目名称:IdioApprox,代码行数:12,代码来源:approximate_begs.py
示例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
开发者ID:dgevans,项目名称:IdioInvest,代码行数:15,代码来源:approximate_aggstate_test.py
示例16: compute_DGhat_sigma
def compute_DGhat_sigma(self,z_i):
'''
Computes the second order approximation for agent of type z_i
'''
DG,HG = self.DG(z_i),self.HG(z_i)
d = self.get_d(z_i)
d2y = self.d2y
DGhat = np.zeros(nY)
DGhat += DG[:,y].dot(d2y[eps,eps](z_i).flatten())
d[eps,eps] =np.array([[1]])
for x1 in [y,eps]:
HGx1 = HG[:,x1,:]
for x2 in [y,eps]:
DGhat += quadratic_dot(HGx1[:,:,x2],d[x1,eps],d[x2,eps]).flatten()
return DGhat
开发者ID:dgevans,项目名称:IdioApprox,代码行数:16,代码来源:approximate_parallel.py
示例17: compute_DGhat_sigma
def compute_DGhat_sigma(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,neps))
DGhat += DG[:,y].dot(d2y[eps,eps](z_i).diagonal(0,1,2))
d[eps,eps] =np.eye(neps)
for x1 in [y,eps]:
HGx1 = HG[:,x1,:]
for x2 in [y,eps]:
DGhat += quadratic_dot(HGx1[:,:,x2],d[x1,eps],d[x2,eps]).diagonal(0,1,2)
return DGhat
开发者ID:dgevans,项目名称:IdioInvest,代码行数:16,代码来源:approximate_aggstate_test.py
示例18: compute_d2y_sigma
def compute_d2y_sigma(self,z_i):
'''
Computes linear contribution of sigma, dYsigma and dY1sigma
'''
DF = self.DF(z_i)
df,Hf = self.df(z_i),self.Hf(z_i)
#first compute DFhat, need loadings of S and epsilon on variables
d = self.get_d(z_i)
d[y,Y] = d[y,S][:,nz:]
DFi = DF[n:] #conditions like x_i = Ex_i don't effect this
temp = np.linalg.inv(DFi[:,y]+DFi[:,e].dot(df)+DFi[:,v].dot(Ivy+Ivy.dot(d[y,z]).dot(Izy)))
Ahat = (-DFi[:,e].dot(df).dot(self.d2y[eps,eps](z_i).diagonal(0,1,2))
-DFi[:,e].dot(quadratic_dot(Hf,d[y,eps],d[y,eps]).diagonal(0,1,2))
-DFi[:,v].dot(Ivy).dot(d[y,Y]).dot(self.integral_term) )
Bhat = -DFi[:,Y]- DFi[:,v].dot(Ivy).dot(d[y,Z]).dot(IZYhat)
Chat = -DFi[:,v].dot(Ivy).dot(d[y,Y])
return temp.dot(np.hstack((Ahat.reshape(-1,neps),Bhat,Chat)))
开发者ID:dgevans,项目名称:IdioInvest,代码行数:21,代码来源:approximate_aggstate_test.py
示例19: compute_d2y
def compute_d2y(self,z_i):
'''
Computes second derivative of y
'''
DF,HF = self.DF(z_i),self.HF(z_i)
df,Hf = self.df(z_i),self.Hf(z_i)
#first compute DFhat, need loadings of S and epsilon on variables
d = self.get_d(z_i)
#Now compute Fhat
HFhat = {}
HFhat[S,S],HFhat[S,eps],HFhat[eps,S],HFhat[eps,eps] = 0.,0.,0.,0.
for x1 in [y,e,Y,z,v,eps]:
HFx1 = HF[:,x1,:]
for x2 in [y,e,Y,z,v,eps]:
HFhat[S,S] += quadratic_dot(HFx1[n:,:,x2],d[x1,S],d[x2,S])
HFhat[S,eps] += quadratic_dot(HFx1[:-n,:,x2],d[x1,S],d[x2,eps])
HFhat[eps,S] += quadratic_dot(HFx1[:-n,:,x2],d[x1,eps],d[x2,S])
HFhat[eps,eps] += quadratic_dot(HFx1[:-n,:,x2],d[x1,eps],d[x2,eps])
#Now compute d2y
d2y = {}
DFi = DF[n:]
d2y[S,S] = np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,e].dot(df) + DFi[:,v].dot(Ivy)),
-HFhat[S,S] - np.tensordot(DFi[:,e],quadratic_dot(Hf,d[y,S],d[y,S]),1)
, axes=1)
DFi = DF[:-n]
d2y[S,eps] =np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,v].dot(Ivy).dot(d[y,z]).dot(Izy)),
-HFhat[S,eps] - np.tensordot(DFi[:,v].dot(Ivy), d2y[S,S][:,:,:nz].dot(d[z,eps]),1)
, axes=1)
d2y[eps,S] = copy(d2y[S,eps])
d2y[eps,S].transpose(0,2,1)
d2y[eps,eps] = np.tensordot(np.linalg.inv(DFi[:,y] + DFi[:,v].dot(Ivy).dot(d[y,z]).dot(Izy)),
-HFhat[eps,eps] - np.tensordot(DFi[:,v].dot(Ivy),
quadratic_dot(d2y[S,S][:,:nz,:nz],d[z,eps],d[z,eps]),1)
,axes=1)
return d2y
开发者ID:dgevans,项目名称:IdioApprox,代码行数:40,代码来源:approximate_parallel.py
示例20: d2y_Zeps
def d2y_Zeps(z_i):
DFi = DF(z_i)[:-n]
temp = np.linalg.inv(DFi[:,y] + DFi[:,v].dot(Ivy).dot(self.dy[z](z_i)).dot(Izy))
return -np.tensordot(temp, self.HFhat[Z,eps](z_i)
+ np.tensordot(DFi[:,v].dot(Ivy),
quadratic_dot(self.d2y[Z,S](z_i)[:,:,:nz],self.dZ_Z,Izy.dot(self.dy[eps](z_i))) ,1),1)
开发者ID:dgevans,项目名称:IdioInvest,代码行数:6,代码来源:approximate_aggstate_test.py
注:本文中的utilities.quadratic_dot函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论