Commit b81eb80e authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'field_docu' into docstring_operators

parents 8bb5b571 223f71e3
Pipeline #12476 passed with stage
in 9 minutes and 4 seconds
......@@ -13,7 +13,7 @@ before_script:
- apt-get update
- >
apt-get install -y build-essential python python-pip python-dev git
autoconf gsl-bin libgsl-dev wget python-numpy cython
autoconf gsl-bin libgsl-dev wget python-numpy
- pip install --upgrade -r ci/requirements_base.txt
- chmod +x ci/*.sh
......
# This Makefile implements common tasks needed by developers
# A list of implemented rules can be obtained by the command "make help"
.DEFAULT_GOAL=build
.PHONY .SILENT : help
help :
echo
echo " Implemented targets:"
echo
echo " build build pypmc for python2 and python3"
echo " buildX build pypmc for pythonX only where X is one of {2,3}"
echo " build-sdist build pypmc from the dist directory (python 2 and 3)"
echo " build-sdistX build pypmc from the dist directory (pythonX, X in {2,3})"
echo " check use nosetests to test pypmc with python 2.7 and 3"
echo " checkX use nosetests to test pypmc with python 2.7 or 3,"
echo " where X is one of {2,3}"
echo " check-fast use nosetests to run only quick tests of pypmc"
echo " using nosetests-2.7 and nosetests3"
echo " check-sdist use nosetests-2.7 and nosetests3 to test the distribution"
echo " generated by 'make sdist'"
echo " check-sdistX use nosetests-2.7 or nosetests3 to test the distribution"
echo " generated by 'make sdist', where X is one of {2,3}"
echo " clean delete compiled and temporary files"
echo " coverage produce and show a code coverage report"
echo " Note: Cython modules cannot be analyzed"
echo " distcheck runs 'check', check-sdist', 'run-examples' and"
echo " opens a browser with the built documentation"
echo " doc build the html documentation using sphinx"
echo " doc-pdf build the pdf documentation using sphinx"
echo " help show this message"
echo " run-examples run all examples using python 2 and 3"
echo " sdist make a source distribution"
echo " show-todos show todo marks in the source code"
echo
.PHONY : clean
clean:
#remove build doc
rm -rf ./doc/_build
#remove .pyc files created by python 2.7
rm -f ./*.pyc
find -P . -name '*.pyc' -delete
#remove .pyc files crated by python 3
rm -rf ./__pycache__
find -P . -name __pycache__ -delete
#remove build folder in root directory
rm -rf ./build
#remove cythonized C source and object files
find -P . -name '*.c' -delete
#remove variational binaries only if command line argument specified
find -P . -name '*.so' -delete
#remove backup files
find -P . -name '*~' -delete
#remove files created by coverage
rm -f .coverage
rm -rf coverage
# remove egg info
rm -rf pypmc.egg-info
# remove downloaded seutptools
rm -f setuptools-3.3.zip
# remove dist/
rm -rf dist
.PHONY : build
build : build2
.PHONY : build2
build2 :
python2 setup.py build_ext --inplace
.PHONY :
check : check2
.PHONY : check2
check2 : build2
@ # run tests
nosetests-2.7 --processes=-1 --process-timeout=60
# run tests in parallel
mpirun -n 2 nosetests-2.7
.PHONY : check-fast
check-fast : build
nosetests-2.7 -a '!slow' --processes=-1 --process-timeout=60
nosetests3 -a '!slow' --processes=-1 --process-timeout=60
.PHONY : .build-system-default
.build-system-default :
python setup.py build_ext --inplace
.PHONY : doc
doc : .build-system-default
cd doc && make html
.PHONY : doc-pdf
doc-pdf : .build-system-default
cd doc; make latexpdf
.PHONY : run-examples
run-examples : build
cd examples ; \
for file in $$(ls) ; do \
echo running $${file} with python2 && \
python2 $${file} && \
echo running $${file} with python3 && \
python3 $${file} && \
\
# execute with mpirun if mpi4py appears in the file \
if grep -Fq 'mpi4py' $${file} ; then \
echo "$${file}" is mpi parallelized && \
echo running $${file} in parallel with python2 && \
mpirun -n 2 python2 $${file} && \
echo running $${file} in parallel with python3 && \
mpirun -n 2 python3 $${file} ; \
fi \
; \
done
.PHONY : sdist
sdist :
python setup.py sdist
.PHONY : build-sdist
build-sdist : build-sdist2 build-sdist3
./dist/pypmc*/NUL : sdist
cd dist && tar xaf *.tar.gz && cd *
.PHONY : build-sdist2
build-sdist2 : ./dist/pypmc*/NUL
cd dist/pypmc* && python2 setup.py build
.PHONY : build-sdist3
build-sdist3 : ./dist/pypmc*/NUL
cd dist/pypmc* && python3 setup.py build
.PHONY : check-sdist
check-sdist : check-sdist2 check-sdist3
.PHONY : check-sdist2
check-sdist2 : build-sdist2
cd dist/*/build/lib*2.7 && \
nosetests-2.7 --processes=-1 --process-timeout=60 && \
mpirun -n 2 nosetests-2.7
.PHONY : check-sdist3
check-sdist3 : build-sdist3
cd dist/*/build/lib*3.* && \
nosetests3 --processes=-1 --process-timeout=60 && \
mpirun -n 2 nosetests3
.PHONY : distcheck
distcheck : check check-sdist doc
@ # execute "run-examples" after all other recipes makes are done
make run-examples
xdg-open link_to_documentation
.PHONY : show-todos
grep_cmd = ack-grep -i --no-html --no-cc [^"au""sphinx.ext."]todo
show-todos :
@ # suppress errors here
@ # note that no todo found is considered as error
$(grep_cmd) doc ; \
$(grep_cmd) pypmc ; \
$(grep_cmd) examples ; echo \
.PHONY : coverage
coverage : .build-system-default
rm -rf coverage
nosetests --with-coverage --cover-package=nifty --cover-html --cover-html-dir=coverage
xdg-open coverage/index.html
Metadata-Version: 1.0
Name: ift_nifty
Version: 1.0.6
Summary: Numerical Information Field Theory
Home-page: http://www.mpa-garching.mpg.de/ift/nifty/
Author: Theo Steininger
Author-email: theos@mpa-garching.mpg.de
License: GPLv3
Description: UNKNOWN
Platform: UNKNOWN
......@@ -15,7 +15,7 @@ Summary
a versatile library designed to enable the development of signal
inference algorithms that operate regardless of the underlying spatial
grid and its resolution. Its object-oriented framework is written in
Python, although it accesses libraries written in Cython, C++, and C for
Python, although it accesses libraries written in C++ and C for
efficiency.
NIFTY offers a toolkit that abstracts discretized representations of
......@@ -71,7 +71,6 @@ Installation
- [Python](http://www.python.org/) (v2.7.x)
- [NumPy](http://www.numpy.org/)
- [Cython](http://cython.org/)
### Download
......@@ -95,7 +94,7 @@ Starting with a fresh Ubuntu installation move to a folder like
- Using pip install numpy etc...:
sudo pip install numpy cython
sudo pip install numpy
- Install pyHealpix:
......@@ -147,10 +146,9 @@ MacPorts, missing ones need to be installed manually. It may also be
mentioned that one should only use one package manager, as multiple ones
may cause trouble.
- Install basic packages numpy and cython:
- Install numpy:
sudo port install py27-numpy
sudo port install py27-cython
- Install pyHealpix:
......
numpy
cython
mpi4py
matplotlib
plotly
......
......@@ -12,15 +12,35 @@ if __name__ == "__main__":
distribution_strategy = 'not'
#Setting up physical constants
#total length of Interval or Volume the field lives on, e.g. in meters
L = 2.
#typical distance over which the field is correlated (in same unit as L)
correlation_length = 0.1
#variance of field in position space sqrt(<|s_x|^2>) (in unit of s)
field_variance = 2.
#smoothing length that response (in same unit as L)
response_sigma = 0.1
#defining resolution (pixels per dimension)
N_pixels = 512
#Setting up derived constants
k_0 = 1./correlation_length
#note that field_variance**2 = a*k_0/4. for this analytic form of power
#spectrum
a = field_variance**2/k_0*4.
pow_spec = (lambda k: a / (1 + k/k_0) ** 4)
pixel_width = L/N_pixels
# Setting up the geometry
s_space = RGSpace([512, 512])
s_space = RGSpace([N_pixels, N_pixels], distances = pixel_width)
fft = FFTOperator(s_space)
h_space = fft.target[0]
p_space = PowerSpace(h_space, distribution_strategy=distribution_strategy)
# Creating the mock data
pow_spec = (lambda k: 42 / (k + 1) ** 3)
S = create_power_operator(h_space, power_spectrum=pow_spec,
distribution_strategy=distribution_strategy)
......@@ -30,7 +50,7 @@ if __name__ == "__main__":
sh = sp.power_synthesize(real_signal=True)
ss = fft.inverse_times(sh)
R = SmoothingOperator(s_space, sigma=0.1)
R = SmoothingOperator(s_space, sigma=response_sigma)
signal_to_noise = 1
N = DiagonalOperator(s_space, diagonal=ss.var()/signal_to_noise, bare=True)
......
......@@ -91,7 +91,7 @@ if __name__ == "__main__":
x1 = HPSpace(64)
k1 = HPLMTransformation.get_codomain(x1)
p1 = PowerSpace(harmonic_domain=k1, log=False)
p1 = PowerSpace(harmonic_partner=k1, logarithmic=False)
# creating Power Operator with given spectrum
spec = (lambda k: a_s / (1 + (k / k_0) ** 2) ** 2)
......@@ -107,7 +107,7 @@ if __name__ == "__main__":
exposure=[exposure])
# drawing a random field
sk = p_field.power_synthesize(decompose_power=True, mean=0.)
sk = p_field.power_synthesize(real_power=True, mean=0.)
s = Fft_op.adjoint_times(sk)
signal_to_noise = 1
......
This diff is collapsed.
......@@ -24,7 +24,7 @@ from diagonal_operator import DiagonalOperator
from endomorphic_operator import EndomorphicOperator
from smoothing_operator import SmoothingOperator
from smoothing_operator import *
from fft_operator import *
......
......@@ -20,45 +20,53 @@ from nifty.operators.linear_operator import LinearOperator
class ComposedOperator(LinearOperator):
""" NIFTY class for composed operators.
"""NIFTY class for composed operators.
The NIFTY composed operator class inherits multiple Operators of various kinds acting on
a Field living over a product space.
The NIFTY composed operator class combines multiple linear operators.
Parameters
----------
Operators : tuple(NIFTy.LinearOperators)
Contains the list of LinearOperators.
operators : tuple of NIFTy Operators
The tuple of LinearOperators.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : NIFTy.space
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The NIFTy.space in which the operator is defined.
target : NIFTy.space
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The NIFTy.space in which the outcome of the operator lives
unitary : boolean
Indicates whether the Operator is unitary or not.
Raises
------
TypeError
Raised if
* the elements of the operator list is not an instance of the
LinearOperator-baseclass
* an element of the operator list is not an instance of the
LinearOperator-baseclass.
Notes
-----
Very usefull in case one has to transform a NIFTy.Field living over the product space. (see example below)
Very usefull in case one has to transform a Field living over a product
space (see example below).
Examples
--------
Minimal example of transforming a Field living on two domains into its harmonic space.
Minimal example of transforming a Field living on two domains into its
harmonic space.
>>> x1 = RGSpace(5)
>>> x2 = RGSpace(10)
>>> k1 = RGRGTransformation.get_codomain(x1)
>>> k2 = RGRGTransformation.get_codomain(x2)
>>> FFT1 = FFTOperator(domain=x1, target=k1, domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT2 = FFTOperator(domain=x2, target=k2, domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT1 = FFTOperator(domain=x1, target=k1,
domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT2 = FFTOperator(domain=x2, target=k2,
domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT = ComposedOperator((FFT1, FFT2)
>>> f = Field.from_random('normal', domain=(x1,x2))
>>> FFT.times(f)
......
......@@ -28,32 +28,46 @@ from nifty.operators.endomorphic_operator import EndomorphicOperator
class DiagonalOperator(EndomorphicOperator):
""" NIFTY class for diagonal operators.
"""NIFTY class for diagonal operators.
The NIFTY DiagonalOperator class is a subclass derived from the
EndomorphicOperator.
EndomorphicOperator. It multiplies an input field pixel-wise with its
diagonal.
Parameters
----------
domain : NIFTy.Space
The Space on which the operator acts
diagonal : {scalar, list, array, NIFTy.Field, d2o-object}
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
diagonal : {scalar, list, array, Field, d2o-object}
The diagonal entries of the operator.
bare : boolean
Indicates whether the diagonal entries are bare or not
(default: False)
Indicates whether the input for the diagonal is bare or not
(default: False).
copy : boolean
Internal copy of the diagonal (default: True)
distribution_strategy : string
setting the prober distribution_strategy of the
diagonal (default : None). In case diagonal is d2o-object or Field,
their distribution_strategy is reused.
their distribution_strategy is used as a fallback.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
distribution_strategy : string
Defines the diagonal is distributed among the nodes.
Defines the distribution_strategy of the distributed_data_object
in which the diagonal entries are stored in.
Raises
------
......@@ -71,12 +85,12 @@ class DiagonalOperator(EndomorphicOperator):
Examples
--------
>>> x_space = RGSpace(5)
>>> D = DiagonalOperator(x_space, diagonal=2.)
>>> f = Field(x_space, val=1.)
>>> D = DiagonalOperator(x_space, diagonal=[1., 3., 2., 4., 6.])
>>> f = Field(x_space, val=2.)
>>> res = D.times(f)
>>> res.val
<distributed_data_object>
array([ 2., 2., 2., 2., 2.])
array([ 2., 6., 4., 8., 12.])
See Also
--------
......@@ -119,7 +133,7 @@ class DiagonalOperator(EndomorphicOperator):
operation=lambda z: z.adjoint().__rdiv__)
def diagonal(self, bare=False, copy=True):
""" Returns the diagonal of the operator.
""" Returns the diagonal of the Operator.
Parameters
----------
......@@ -130,11 +144,9 @@ class DiagonalOperator(EndomorphicOperator):
Returns
-------
out : NIFTy.Field
the diagonal of the Operator
out : Field
The diagonal of the Operator.
See Also
--------
"""
if bare:
diagonal = self._diagonal.weight(power=-1)
......@@ -154,11 +166,9 @@ class DiagonalOperator(EndomorphicOperator):
Returns
-------
out : NIFTy.Field
the inverse-diagonal of the Operator
out : Field
The inverse of the diagonal of the Operator.
See Also
--------
"""
return 1./self.diagonal(bare=bare, copy=False)
......@@ -173,10 +183,8 @@ class DiagonalOperator(EndomorphicOperator):
Returns
-------
out : scalar
the trace of the Operator
The trace of the Operator.
See Also
--------
"""
return self.diagonal(bare=bare, copy=False).sum()
......@@ -191,25 +199,19 @@ class DiagonalOperator(EndomorphicOperator):
Returns
-------
out : scalar
the inverse-trace of the Operator
The inverse of the trace of the Operator.
See Also
--------
"""
return self.inverse_diagonal(bare=bare).sum()
def trace_log(self):
""" Returns the trave-log of the operator.
Parameters
----------
Returns
-------
out : scalar
the trace-log of the Operator
the trace of the logarithm of the Operator.
See Also
--------
"""
log_diagonal = nifty_log(self.diagonal(copy=False))
return log_diagonal.sum()
......@@ -217,46 +219,38 @@ class DiagonalOperator(EndomorphicOperator):
def determinant(self):
""" Returns the determinant of the operator.
Parameters
----------
Returns
-------
out : scalar
out : scalar
the determinant of the Operator
See Also
--------
"""
return self.diagonal(copy=False).val.prod()
def inverse_determinant(self):
""" Returns the inverse-determinant of the operator.
Parameters
----------
Returns
-------
out : scalar
the inverse-determinant of the Operator
See Also
--------
"""
return 1/self.determinant()
def log_determinant(self):
""" Returns the log-eterminant of the operator.
Parameters
----------
Returns
-------
out : scalar
the log-determinant of the Operator
See Also
--------
"""
return np.log(self.determinant())
# ---Mandatory properties and methods---
......@@ -285,18 +279,14 @@ class DiagonalOperator(EndomorphicOperator):
"""
distribution_strategy : string
Defines the way how the diagonal operator is distributed
among the nodes.
Popoular ones are:
'fftw'
'all'
'local'
'slicing'
'not'
'hdf5'
among the nodes. Available distribution_strategies are:
'fftw', 'equal' and 'not'.
Notes :
https://arxiv.org/abs/1606.05385
"""
return self._distribution_strategy
def _parse_distribution_strategy(self, distribution_strategy, val):
......@@ -318,22 +308,16 @@ class DiagonalOperator(EndomorphicOperator):
Parameters
----------
diagonal : {scalar, list, array, NIFTy.Field, d2o-object}
diagonal : {scalar, list, array, Field, d2o-object}
The diagonal entries of the operator.
bare : boolean
Indicates whether the diagonal entries are bare or not
(default: False)
Indicates whether the input for the diagonal is bare or not
(default: False).
copy : boolean
Internal copy of the diagonal (default: True)
Specifies if a copy of the input shall be made (default: True).
Returns
-------