From: Michael Orlitzky Date: Sat, 12 Nov 2016 12:34:25 +0000 (-0500) Subject: Add a cached method for games that returns the spectral norm of L. X-Git-Tag: 0.1.0~33 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dunshire.git;a=commitdiff_plain;h=60f232a1669856e3b061632ede2509789be1e1d8 Add a cached method for games that returns the spectral norm of L. --- diff --git a/dunshire/games.py b/dunshire/games.py index bb808cb..a1ac0f5 100644 --- a/dunshire/games.py +++ b/dunshire/games.py @@ -322,6 +322,8 @@ class SymmetricLinearGame: if not self._e2 in K: raise ValueError('the point e2 must lie in the interior of K') + # Initial value of cached method. + self._L_specnorm_value = None def __str__(self): @@ -821,7 +823,7 @@ class SymmetricLinearGame: """ p = self.e2() / (norm(self.e2()) ** 2) dist = self.K().ball_radius(self.e1()) - nu = - specnorm(self.L())/(dist*norm(self.e2())) + nu = - self._L_specnorm()/(dist*norm(self.e2())) x = matrix([nu, p], (self.dimension() + 1, 1)) s = - self._G()*x @@ -834,7 +836,7 @@ class SymmetricLinearGame: """ q = self.e1() / (norm(self.e1()) ** 2) dist = self.K().ball_radius(self.e2()) - omega = specnorm(self.L())/(dist*norm(self.e1())) + omega = self._L_specnorm()/(dist*norm(self.e1())) y = matrix([omega]) z2 = q z1 = y*self.e2() - self.L().trans()*z2 @@ -843,6 +845,14 @@ class SymmetricLinearGame: return {'y': y, 'z': z} + def _L_specnorm(self): + """ + Compute the spectral norm of ``L`` and cache it. + """ + if self._L_specnorm_value is None: + self._L_specnorm_value = specnorm(self.L()) + return self._L_specnorm_value + def solution(self): """ Solve this linear game and return a :class:`Solution`.