From ecbc4221533e1b39f05b5c07c66fce3dcfcfba0b Mon Sep 17 00:00:00 2001 From: Marco Selig <mselig@ncg-02.MPA-Garching.MPG.DE> Date: Wed, 13 Mar 2013 13:44:35 +0100 Subject: [PATCH] field's L2-norm generalized to Lq-norm. --- nifty_core.py | 18 ++++++++++++++---- nifty_power.py | 7 ++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/nifty_core.py b/nifty_core.py index cc27ec386..88bc08827 100644 --- a/nifty_core.py +++ b/nifty_core.py @@ -5897,17 +5897,27 @@ class field(object): x = self.domain.calc_weight(x,power=1) return self.domain.calc_dot(self.val,x) - def norm(self): ## TODO: extend to L^q norm + def norm(self,q=None): """ - Computes the L2-norm of the field values. + Computes the Lq-norm of the field values. + + Parameters + ---------- + q : scalar + Parameter q of the Lq-norm (default: 2). Returns ------- norm : scalar - The L2-norm of the field values. + The Lq-norm of the field values. """ - return np.sqrt(self.dot(x=self.val)) + if(q is None): + return np.sqrt(self.dot(x=self.val)) + else: + return self.dot(x=self.val**(q-1))**(1/q) + + ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ def pseudo_dot(self,x=1,**kwargs): """ diff --git a/nifty_power.py b/nifty_power.py index 58b3c3bff..6ef88ae49 100644 --- a/nifty_power.py +++ b/nifty_power.py @@ -36,11 +36,8 @@ homogeneity and isotropy. Fields which are only statistically homogeneous can also be created using the diagonal operator routine. - At the moment, NIFTy offers one additional routine for power spectrum - manipulation, the smooth_power function to smooth a power spectrum with a - Gaussian convolution kernel. This can be necessary in cases where power - spectra are reconstructed and reused in an iterative algorithm, where - too much statistical variation might severely effect the results. + At the moment, NIFTY offers several additional routines for power spectrum + manipulation. """ -- GitLab