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
ift
NIFTy
Commits
de59bf62
Commit
de59bf62
authored
Oct 24, 2013
by
Marco Selig
Browse files
version update.
parent
33a90fc9
Changes
6
Hide whitespace changes
Inline
Side-by-side
README.rst
View file @
de59bf62
...
@@ -63,6 +63,7 @@ apply to fields.
...
@@ -63,6 +63,7 @@ apply to fields.
vector
vector
*
``
response_operator
``
-
exemplary
responses
that
include
a
convolution
,
*
``
response_operator
``
-
exemplary
responses
that
include
a
convolution
,
masking
and
projection
masking
and
projection
*
``
propagator_operator
``
-
information
propagator
in
Wiener
filter
theory
*
(
and
more
)
*
(
and
more
)
*
(
and
more
)
*
(
and
more
)
...
@@ -96,7 +97,7 @@ Requirements
...
@@ -96,7 +97,7 @@ Requirements
Download
Download
........
........
The latest release is tagged **v0.
4.2
** and is available as a source package
The
latest
release
is
tagged
**
v0
.
6.0
**
and
is
available
as
a
source
package
at
`<
https
://
github
.
com
/
mselig
/
nifty
/
tags
>`
_
.
The
current
version
can
be
at
`<
https
://
github
.
com
/
mselig
/
nifty
/
tags
>`
_
.
The
current
version
can
be
obtained
by
cloning
the
repository
::
obtained
by
cloning
the
repository
::
...
@@ -122,7 +123,7 @@ Please, acknowledge the use of NIFTY in your publication(s) by using a phrase
...
@@ -122,7 +123,7 @@ Please, acknowledge the use of NIFTY in your publication(s) by using a phrase
such
as
the
following
:
such
as
the
following
:
*
"Some of the results in this publication have been derived using the NIFTY
*
"Some of the results in this publication have been derived using the NIFTY
[Selig et al., 2013]
package
."*
package
[Selig et al., 2013]."
*
References
References
..........
..........
...
...
demos/demo_wf1.py
View file @
de59bf62
...
@@ -33,8 +33,6 @@
...
@@ -33,8 +33,6 @@
"""
"""
from
__future__
import
division
from
__future__
import
division
from
nifty
import
*
# version 0.6.0
from
nifty
import
*
# version 0.6.0
from
nifty.nifty_tools
import
*
# some signal space; e.g., a two-dimensional regular grid
# some signal space; e.g., a two-dimensional regular grid
...
@@ -57,15 +55,11 @@ n = N.get_random_field(domain=d_space) # generate
...
@@ -57,15 +55,11 @@ n = N.get_random_field(domain=d_space) # generate
d
=
R
(
s
)
+
n
# compute data
d
=
R
(
s
)
+
n
# compute data
j
=
R
.
adjoint_times
(
N
.
inverse_times
(
d
))
# define information source
j
=
R
.
adjoint_times
(
N
.
inverse_times
(
d
))
# define information source
D
=
propagator_operator
(
S
=
S
,
N
=
N
,
R
=
R
)
# define information propagator
D
=
propagator_operator
(
S
=
S
,
N
=
N
,
R
=
R
)
# define information propagator
m
=
D
(
j
,
tol
=
1E-4
,
note
=
True
)
# reconstruct map
m
=
D
(
j
,
tol
=
1E-4
,
note
=
True
)
# reconstruct map
s
.
plot
(
title
=
"signal"
)
# plot signal
s
.
plot
(
title
=
"signal"
)
# plot signal
d_
=
field
(
x_space
,
val
=
d
.
val
,
target
=
k_space
)
d_
=
field
(
x_space
,
val
=
d
.
val
,
target
=
k_space
)
d_
.
plot
(
title
=
"data"
,
vmin
=
s
.
val
.
min
(),
vmax
=
s
.
val
.
max
())
# plot data
d_
.
plot
(
title
=
"data"
,
vmin
=
s
.
val
.
min
(),
vmax
=
s
.
val
.
max
())
# plot data
...
...
demos/demo_wf2.py
View file @
de59bf62
...
@@ -33,8 +33,6 @@
...
@@ -33,8 +33,6 @@
"""
"""
from
__future__
import
division
from
__future__
import
division
from
nifty
import
*
# version 0.6.0
from
nifty
import
*
# version 0.6.0
from
nifty.nifty_tools
import
*
# some signal space; e.g., a two-dimensional regular grid
# some signal space; e.g., a two-dimensional regular grid
...
@@ -57,10 +55,8 @@ n = N.get_random_field(domain=d_space) # generate
...
@@ -57,10 +55,8 @@ n = N.get_random_field(domain=d_space) # generate
d
=
R
(
s
)
+
n
# compute data
d
=
R
(
s
)
+
n
# compute data
j
=
R
.
adjoint_times
(
N
.
inverse_times
(
d
))
# define information source
j
=
R
.
adjoint_times
(
N
.
inverse_times
(
d
))
# define information source
D
=
propagator_operator
(
S
=
S
,
N
=
N
,
R
=
R
)
# define information propagator
D
=
propagator_operator
(
S
=
S
,
N
=
N
,
R
=
R
)
# define information propagator
def
eggs
(
x
):
def
eggs
(
x
):
...
@@ -68,17 +64,15 @@ def eggs(x):
...
@@ -68,17 +64,15 @@ def eggs(x):
Calculation of the information Hamiltonian and its gradient.
Calculation of the information Hamiltonian and its gradient.
"""
"""
Dx
=
D
.
inverse_times
(
x
)
D
I
x
=
D
.
inverse_times
(
x
)
H
=
0.5
*
Dx
.
dot
(
x
)
-
j
.
dot
(
x
)
# compute information Hamiltonian
H
=
0.5
*
D
I
x
.
dot
(
x
)
-
j
.
dot
(
x
)
# compute information Hamiltonian
g
=
Dx
-
j
# compute its gradient
g
=
D
I
x
-
j
# compute its gradient
return
H
,
g
return
H
,
g
m
=
field
(
x_space
,
target
=
k_space
)
# reconstruct map
m
=
field
(
x_space
,
target
=
k_space
)
# reconstruct map
m
,
convergence
=
steepest_descent
(
eggs
=
eggs
,
note
=
True
)(
m
,
tol
=
1E-4
,
clevel
=
3
)
m
,
convergence
=
steepest_descent
(
eggs
=
eggs
,
note
=
True
)(
m
,
tol
=
1E-4
,
clevel
=
3
)
s
.
plot
(
title
=
"signal"
)
# plot signal
s
.
plot
(
title
=
"signal"
)
# plot signal
d_
=
field
(
x_space
,
val
=
d
.
val
,
target
=
k_space
)
d_
=
field
(
x_space
,
val
=
d
.
val
,
target
=
k_space
)
d_
.
plot
(
title
=
"data"
,
vmin
=
s
.
val
.
min
(),
vmax
=
s
.
val
.
max
())
# plot data
d_
.
plot
(
title
=
"data"
,
vmin
=
s
.
val
.
min
(),
vmax
=
s
.
val
.
max
())
# plot data
...
...
nifty_core.py
View file @
de59bf62
...
@@ -486,7 +486,7 @@ class _about(object): ## nifty support class for global settings
...
@@ -486,7 +486,7 @@ class _about(object): ## nifty support class for global settings
"""
"""
## version
## version
self
.
_version
=
"0.
5.9
"
self
.
_version
=
"0.
6.0
"
## switches and notifications
## switches and notifications
self
.
_errors
=
notification
(
default
=
True
,
ccode
=
notification
.
_code
)
self
.
_errors
=
notification
(
default
=
True
,
ccode
=
notification
.
_code
)
...
@@ -11703,17 +11703,17 @@ class probing(object):
...
@@ -11703,17 +11703,17 @@ class probing(object):
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def
evaluate
(
self
,
sum
_
,
num
_
,
var
_
):
def
evaluate
(
self
,
sum
ma
,
num
,
var
):
"""
"""
Evaluates the probing results.
Evaluates the probing results.
Parameters
Parameters
----------
----------
sum
_
: numpy.array
sum
ma
: numpy.array
Sum of all probing results.
Sum of all probing results.
num
_
: int
num : int
Number of successful probings (not returning ``None``).
Number of successful probings (not returning ``None``).
var
_
: numpy.array
var : numpy.array
Sum of all squared probing results
Sum of all squared probing results
Returns
Returns
...
@@ -11727,27 +11727,27 @@ class probing(object):
...
@@ -11727,27 +11727,27 @@ class probing(object):
(`final`,`var`).
(`final`,`var`).
"""
"""
if
(
num
_
<
self
.
nrun
):
if
(
num
<
self
.
nrun
):
about
.
infos
.
cflush
(
" ( %u probe(s) failed, effectiveness == %.1f%% )
\n
"
%
(
self
.
nrun
-
num
_
,
100
*
num
_
/
self
.
nrun
))
about
.
infos
.
cflush
(
" ( %u probe(s) failed, effectiveness == %.1f%% )
\n
"
%
(
self
.
nrun
-
num
,
100
*
num
/
self
.
nrun
))
if
(
num
_
==
0
):
if
(
num
==
0
):
about
.
warnings
.
cprint
(
"WARNING: probing failed."
)
about
.
warnings
.
cprint
(
"WARNING: probing failed."
)
return
None
return
None
else
:
else
:
about
.
infos
.
cflush
(
"
\n
"
)
about
.
infos
.
cflush
(
"
\n
"
)
if
(
sum
_
.
size
==
1
):
if
(
sum
ma
.
size
==
1
):
sum
_
=
sum
_
.
flatten
(
order
=
'C'
)[
0
]
sum
ma
=
sum
ma
.
flatten
(
order
=
'C'
)[
0
]
var
_
=
var
_
.
flatten
(
order
=
'C'
)[
0
]
var
=
var
.
flatten
(
order
=
'C'
)[
0
]
if
(
np
.
iscomplexobj
(
sum
_
))
and
(
np
.
all
(
np
.
imag
(
sum
_
)
==
0
)):
if
(
np
.
iscomplexobj
(
sum
ma
))
and
(
np
.
all
(
np
.
imag
(
sum
ma
)
==
0
)):
sum
_
=
np
.
real
(
sum
_
)
sum
ma
=
np
.
real
(
sum
ma
)
final
=
sum
_
*
(
1
/
num
_
)
final
=
sum
ma
*
(
1
/
num
)
if
(
self
.
var
):
if
(
self
.
var
):
if
(
num
_
==
1
):
if
(
num
==
1
):
about
.
warnings
.
cprint
(
"WARNING: infinite variance."
)
about
.
warnings
.
cprint
(
"WARNING: infinite variance."
)
return
final
,
None
return
final
,
None
else
:
else
:
var
=
var
_
*
(
1
/
(
num
_
*
(
num
_
-
1
)))
-
np
.
real
(
np
.
conjugate
(
final
)
*
final
)
*
(
1
/
(
num
_
-
1
))
var
=
var
*
(
1
/
(
num
*
(
num
-
1
)))
-
np
.
real
(
np
.
conjugate
(
final
)
*
final
)
*
(
1
/
(
num
-
1
))
return
final
,
var
return
final
,
var
else
:
else
:
return
final
return
final
...
@@ -11858,7 +11858,7 @@ class probing(object):
...
@@ -11858,7 +11858,7 @@ class probing(object):
## evaluate
## evaluate
return
self
.
evaluate
(
_sum
,
_num
,
_var
)
return
self
.
evaluate
(
_sum
,
_num
,
_var
)
def
__call__
(
self
,
loop
=
False
,
**
kwargs
):
## FIXME: doc
def
__call__
(
self
,
loop
=
False
,
**
kwargs
):
"""
"""
Starts the probing process.
Starts the probing process.
...
@@ -12129,17 +12129,17 @@ class trace_probing(probing):
...
@@ -12129,17 +12129,17 @@ class trace_probing(probing):
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def
evaluate
(
self
,
sum
_
,
num
_
,
var
_
):
def
evaluate
(
self
,
sum
ma
,
num
,
var
):
"""
"""
Evaluates the probing results.
Evaluates the probing results.
Parameters
Parameters
----------
----------
sum
_
: scalar
sum
ma
: scalar
Sum of all probing results.
Sum of all probing results.
num
_
: int
num : int
Number of successful probings (not returning ``None``).
Number of successful probings (not returning ``None``).
var
_
: scalar
var : scalar
Sum of all squared probing results
Sum of all squared probing results
Returns
Returns
...
@@ -12153,24 +12153,24 @@ class trace_probing(probing):
...
@@ -12153,24 +12153,24 @@ class trace_probing(probing):
(`final`,`var`).
(`final`,`var`).
"""
"""
if
(
num
_
<
self
.
nrun
):
if
(
num
<
self
.
nrun
):
about
.
infos
.
cflush
(
" ( %u probe(s) failed, effectiveness == %.1f%% )
\n
"
%
(
self
.
nrun
-
num
_
,
100
*
num
_
/
self
.
nrun
))
about
.
infos
.
cflush
(
" ( %u probe(s) failed, effectiveness == %.1f%% )
\n
"
%
(
self
.
nrun
-
num
,
100
*
num
/
self
.
nrun
))
if
(
num
_
==
0
):
if
(
num
==
0
):
about
.
warnings
.
cprint
(
"WARNING: probing failed."
)
about
.
warnings
.
cprint
(
"WARNING: probing failed."
)
return
None
return
None
else
:
else
:
about
.
infos
.
cflush
(
"
\n
"
)
about
.
infos
.
cflush
(
"
\n
"
)
if
(
self
.
domain
.
datatype
in
[
np
.
complex64
,
np
.
complex128
]):
if
(
self
.
domain
.
datatype
in
[
np
.
complex64
,
np
.
complex128
]):
sum
_
=
np
.
real
(
sum
_
)
sum
ma
=
np
.
real
(
sum
ma
)
final
=
sum
_
/
num
_
final
=
sum
ma
/
num
if
(
self
.
var
):
if
(
self
.
var
):
if
(
num
_
==
1
):
if
(
num
==
1
):
about
.
warnings
.
cprint
(
"WARNING: infinite variance."
)
about
.
warnings
.
cprint
(
"WARNING: infinite variance."
)
return
final
,
None
return
final
,
None
else
:
else
:
var
=
var
_
/
(
num
_
*
(
num
_
-
1
))
-
np
.
real
(
np
.
conjugate
(
final
)
*
final
)
/
(
num
_
-
1
)
var
=
var
/
(
num
*
(
num
-
1
))
-
np
.
real
(
np
.
conjugate
(
final
)
*
final
)
/
(
num
-
1
)
return
final
,
var
return
final
,
var
else
:
else
:
return
final
return
final
...
...
nifty_power.py
View file @
de59bf62
...
@@ -28,11 +28,11 @@
...
@@ -28,11 +28,11 @@
.. /__/ /__/ /__/ /__/ \___/ \___ / power
.. /__/ /__/ /__/ /__/ \___/ \___ / power
.. /______/
.. /______/
NIFT
y
offers a number of automatized routines for handling
NIFT
Y
offers a number of automatized routines for handling
power spectra. It is possible to draw a field from a random distribution
power spectra. It is possible to draw a field from a random distribution
with a certain autocorrelation or, equivalently, with a certain
with a certain autocorrelation or, equivalently, with a certain
power spectrum in its conjugate space (see :py:func:`field.random`). In
power spectrum in its conjugate space (see :py:func:`field.random`). In
NIFT
y
, it is usually assumed that such a field follows statistical
NIFT
Y
, it is usually assumed that such a field follows statistical
homogeneity and isotropy. Fields which are only statistically homogeneous
homogeneity and isotropy. Fields which are only statistically homogeneous
can also be created using the diagonal operator routine.
can also be created using the diagonal operator routine.
...
...
nifty_tools.py
View file @
de59bf62
...
@@ -28,9 +28,12 @@
...
@@ -28,9 +28,12 @@
.. /__/ /__/ /__/ /__/ \___/ \___ / tools
.. /__/ /__/ /__/ /__/ \___/ \___ / tools
.. /______/
.. /______/
A nifty set of tools.
This module extends NIFTY with a nifty set of tools including further
operators, namely the :py:class:`invertible_operator` and the
## TODO: *DESCRIPTION*
:py:class:`propagator_operator`, and minimization schemes, namely
:py:class:`steepest_descent` and :py:class:`conjugate_gradient`. Those
tools are supposed to support the user in solving information field
theoretical problems (almost) without numerical pain.
"""
"""
from
__future__
import
division
from
__future__
import
division
...
@@ -51,9 +54,10 @@ class invertible_operator(operator):
...
@@ -51,9 +54,10 @@ class invertible_operator(operator):
NIFTY subclass for invertible, self-adjoint (linear) operators
NIFTY subclass for invertible, self-adjoint (linear) operators
The base NIFTY operator class is an abstract class from which other
The invertible operator class is an abstract class for self-adjoint or
specific operator subclasses, including those preimplemented in NIFTY
symmetric (linear) operators from which other more specific operator
(e.g. the diagonal operator class) must be derived.
subclassescan be derived. Such operators inherit an automated inversion
routine, namely conjugate gradient.
Parameters
Parameters
----------
----------
...
@@ -76,9 +80,9 @@ class invertible_operator(operator):
...
@@ -76,9 +80,9 @@ class invertible_operator(operator):
Notes
Notes
-----
-----
Operator classes derived from this one only need a `_multiply` or
This class is not meant to be instantiated. Operator classes derived
`_inverse_multiply` instance method to perform the other. However, on
e
from this one only need a `_multiply` or `_inverse_multiply` instanc
e
of them needs to be defined.
method to perform the other. However, one
of them needs to be defined.
Attributes
Attributes
----------
----------
...
@@ -275,8 +279,8 @@ class propagator_operator(operator):
...
@@ -275,8 +279,8 @@ class propagator_operator(operator):
NIFTY subclass for propagator operators (of a certain family)
NIFTY subclass for propagator operators (of a certain family)
The propagator operators :math:`D` implemented here have an inverse
The propagator operators :math:`D` implemented here have an inverse
formulation like :math:`S^{-1} + M`, :math:`S^{-1} + N^{-1}`, or
formulation like :math:`
(
S^{-1} + M
)
`, :math:`
(
S^{-1} + N^{-1}
)
`, or
:math:`S^{-1} + R^\dagger N^{-1} R` as appearing in Wiener filter
:math:`
(
S^{-1} + R^\dagger N^{-1} R
)
` as appearing in Wiener filter
theory.
theory.
Parameters
Parameters
...
@@ -296,7 +300,7 @@ class propagator_operator(operator):
...
@@ -296,7 +300,7 @@ class propagator_operator(operator):
Notes
Notes
-----
-----
The propagator will puzzle the operators `S` and `M` or `R`,`N` or
The propagator will puzzle the operators `S` and `M` or `R`,
`N` or
only `N` together in the predefined from, a domain is set
only `N` together in the predefined from, a domain is set
automatically. The application of the inverse is done by invoking a
automatically. The application of the inverse is done by invoking a
conjugate gradient.
conjugate gradient.
...
@@ -610,8 +614,8 @@ class conjugate_gradient(object):
...
@@ -610,8 +614,8 @@ class conjugate_gradient(object):
References
References
----------
----------
.. [#] J. R. Shewchuk, 1994, `"An Introduction to the Conjugate
.. [#] J. R. Shewchuk, 1994, `"An Introduction to the Conjugate
Gradient Method Without the Agonizing Pain"
Gradient Method Without the Agonizing Pain"
`
<http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf>`_
<http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf>`_
Examples
Examples
--------
--------
...
...
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