mapfunc.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from numpy import matrix, r_, c_
  2. from .dop import *
  3. def jacobian(self):
  4. vars=self.keys()
  5. o= [ dop(i)(self) for i in vars ]
  6. o= [ [ c[j] for j in vars ] for c in o ]
  7. return matrix(o)
  8. def frommatrix(self,vars):
  9. pvars=[pol(i) for i in vars]
  10. m=polmap()
  11. for ni,i in enumerate(vars):
  12. m[i]=0
  13. for nj,j in enumerate(vars):
  14. m[i]+=self[ni,nj]*pvars[nj]
  15. return m
  16. def tomatrix(self,vars=None):
  17. if not vars:
  18. vars=self[self.keys()[0]].vars
  19. out=[]
  20. for vi in vars:
  21. p=self[vi]
  22. oi=[]
  23. for vj in vars:
  24. oi.append(p.getlcoef(vj))
  25. out.append(oi)
  26. return matrix(out)
  27. def linearpart(self):
  28. vars=self[self.keys()[0]].vars
  29. m=tomatrix(self)
  30. return frommatrix(m,vars)
  31. def linv(self):
  32. vars=self[self.keys()[0]].vars
  33. m=tomatrix(self,vars)
  34. return frommatrix(m**-1,vars)
  35. def lin(self):
  36. vars=self[self.keys()[0]].vars
  37. m=tomatrix(self,vars)
  38. return frommatrix(m,vars)
  39. j2=matrix([[0.,1],[-1,0]])
  40. n2=matrix([[0.,0],[0,0]])
  41. i2=matrix([[1,0],[0,1]])
  42. j4=r_[c_[j2,n2],c_[n2,j2]]
  43. j6=r_[c_[j2,n2,n2],c_[n2,j2,n2],c_[n2,n2,j2]]
  44. def normalfactor(eig,i,j):
  45. # Prod_k lambda[k]**j[k] - lambda[i]
  46. res=1
  47. for k,jk in enumerate(j):
  48. res*=eig[k]**jk
  49. res-=eig[i]
  50. return res