Commit 93bf41d6 authored by Marco Selig's avatar Marco Selig

fixes and features.

parent fb3d0c82
......@@ -13,6 +13,7 @@
build
demos/*
!demos/__init__.py
!demos/demo_faraday.py
!demos/demo_faraday_map.npy
!demos/demo_excaliwir.py
......
## NIFTY (Numerical Information Field Theory) has been developed at the
## Max-Planck-Institute for Astrophysics.
##
## Copyright (C) 2014 Max-Planck-Society
##
## Author: Marco Selig
## Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
pass
......@@ -514,7 +514,7 @@ class _about(object): ## nifty support class for global settings
"""
## version
self._version = "0.8.9"
self._version = "0.9.0"
## switches and notifications
self._errors = notification(default=True,ccode=notification._code)
......@@ -8290,26 +8290,52 @@ class operator(object):
def det(self):
"""
Computes the determinant of the operator
Computes the determinant of the operator.
Returns
-------
det : float
The determinant
"""
raise NotImplementedError(about._errors.cstring("ERROR: no generic instance method 'det'."))
def inverse_det(self):
"""
Computes the determinant of the inverse operator
Computes the determinant of the inverse operator.
Returns
-------
det : float
The determinant
"""
raise NotImplementedError(about._errors.cstring("ERROR: no generic instance method 'inverse_det'."))
def log_det(self):
"""
Computes the logarithm of the determinant of the operator (if applicable).
Returns
-------
logdet : float
The logarithm of the determinant
"""
raise NotImplementedError(about._errors.cstring("ERROR: no generic instance method 'log_det'."))
def tr_log(self):
"""
Computes the trace of the logarithm of the operator (if applicable).
Returns
-------
logdet : float
The trace of the logarithm
"""
return self.log_det()
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def hat(self,bare=False,domain=None,target=None,**kwargs):
......@@ -9129,6 +9155,23 @@ class diagonal_operator(operator):
else:
raise ValueError(about._errors.cstring("ERROR: singular operator."))
def log_det(self):
"""
Computes the logarithm of the determinant of the operator.
Returns
-------
logdet : float
The logarithm of the determinant
"""
if(self.uni): ## identity
return 0
elif(self.domain.dim(split=False)<self.domain.dof()): ## hidden degrees of freedom
return self.domain.calc_dot(np.ones(self.domain.dim(split=True),dtype=self.domain.datatype,order='C'),np.log(self.val))
else:
return np.sum(np.log(self.val),axis=None,dtype=None,out=None)
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def get_random_field(self,domain=None,target=None,**kwargs):
......@@ -10211,7 +10254,8 @@ class vecvec_operator(operator):
def inverse_diag(self):
"""
Inverse is ill-defined for this operator.
Inverse is ill-defined for this operator.
"""
raise AttributeError(about._errors.cstring("ERROR: singular operator."))
......@@ -10219,18 +10263,27 @@ class vecvec_operator(operator):
def det(self):
"""
Computes the determinant of the operator
Computes the determinant of the operator.
Returns
-------
det : 0
The determinant
"""
return 0
def inverse_det(self):
"""
Inverse is ill-defined for this operator.
Inverse is ill-defined for this operator.
"""
raise AttributeError(about._errors.cstring("ERROR: singular operator."))
def log_det(self):
"""
Logarithm of the determinant is ill-defined for this singular operator.
"""
raise AttributeError(about._errors.cstring("ERROR: singular operator."))
......
......@@ -1077,7 +1077,11 @@ class explicit_operator(operator):
if(np.any(self._hidden)):
about.warnings.cprint("WARNING: inappropriate determinant calculation.")
return np.linalg.det(self.weight(rowpower=0.5,colpower=0.5,overwrite=False))
det = np.linalg.det(self.weight(rowpower=0.5,colpower=0.5,overwrite=False))
if(np.isreal(det)):
return np.asscalar(np.real(det))
else:
return det
def inverse_det(self):
"""
......@@ -1104,6 +1108,44 @@ class explicit_operator(operator):
else:
raise ValueError(about._errors.cstring("ERROR: singular matrix."))
def log_det(self):
"""
Computes the logarithm of the determinant of the operator
(if applicable).
Returns
-------
logdet : float
The logarithm of the determinant
See Also
--------
numpy.linalg.slogdet
Raises
------
ValueError
If `domain` and `target` are unequal or it is non-positive
definite matrix.
"""
if(self.domain!=self.target):
raise ValueError(about._errors.cstring("ERROR: determinant ill-defined."))
if(np.any(self._hidden)):
about.warnings.cprint("WARNING: inappropriate determinant calculation.")
sign,logdet = np.linalg.slogdet(self.weight(rowpower=0.5,colpower=0.5,overwrite=False))
if(abs(sign)<0.1): ## abs(sign) << 1
raise ValueError(about._errors.cstring("ERROR: singular matrix."))
if(sign==-1):
raise ValueError(about._errors.cstring("ERROR: non-positive definite matrix."))
else:
logdet += np.log(sign)
if(np.isreal(logdet)):
return np.asscalar(np.real(logdet))
else:
return logdet
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def __len__(self):
......@@ -2324,7 +2366,11 @@ def explicify(op,newdomain=None,newtarget=None,ncpu=2,nper=1,loop=False,**quargs
raise TypeError(about._errors.cstring("ERROR: invalid input."))
elif(newdomain is not None)and(newtarget is None)and(op.domain==op.target):
newtarget = newdomain
return explicit_probing(op=op,function=op.times,domain=newdomain,codomain=newtarget,target=op.domain,ncpu=ncpu,nper=nper,**quargs)(loop=loop)
if(newdomain is None)or(newdomain==op.domain):
target_ = None
else:
target_ = op.domain
return explicit_probing(op=op,function=op.times,domain=newdomain,codomain=newtarget,target=target_,ncpu=ncpu,nper=nper,**quargs)(loop=loop)
##-----------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment