Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
93bf41d6
Commit
93bf41d6
authored
Dec 04, 2014
by
Marco Selig
Browse files
fixes and features.
parent
fb3d0c82
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
93bf41d6
...
...
@@ -13,6 +13,7 @@
build
demos/*
!demos/__init__.py
!demos/demo_faraday.py
!demos/demo_faraday_map.npy
!demos/demo_excaliwir.py
...
...
demos/__init__.py
0 → 100644
View file @
93bf41d6
## 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
nifty_core.py
View file @
93bf41d6
...
...
@@ -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."
))
...
...
nifty_explicit.py
View file @
93bf41d6
...
...
@@ -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
)
##-----------------------------------------------------------------------------
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment