Commit a0bb1803 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'NIFTy_5' into operator_documentation

parents d3fb76f1 84625c98
...@@ -82,12 +82,14 @@ run_getting_started_1: ...@@ -82,12 +82,14 @@ run_getting_started_1:
script: script:
- python demos/getting_started_1.py - python demos/getting_started_1.py
- python3 demos/getting_started_1.py - python3 demos/getting_started_1.py
- mpiexec -n 2 --bind-to none python3 demos/getting_started_1.py 2> /dev/null
run_getting_started_2: run_getting_started_2:
stage: demo_runs stage: demo_runs
script: script:
- python demos/getting_started_2.py - python demos/getting_started_2.py
- python3 demos/getting_started_2.py - python3 demos/getting_started_2.py
- mpiexec -n 2 --bind-to none python3 demos/getting_started_2.py 2> /dev/null
run_getting_started_3: run_getting_started_3:
stage: demo_runs stage: demo_runs
......
...@@ -15,7 +15,7 @@ if __name__ == '__main__': ...@@ -15,7 +15,7 @@ if __name__ == '__main__':
position_space = ift.RGSpace([128, 128]) position_space = ift.RGSpace([128, 128])
# Setting up an amplitude model # Setting up an amplitude model
A, amplitude_internals = ift.library.make_amplitude_model( A, amplitude_internals = ift.make_amplitude_model(
position_space, 16, 1, 10, -4., 1, 0., 1.) position_space, 16, 1, 10, -4., 1, 0., 1.)
# Building the model for a correlated signal # Building the model for a correlated signal
...@@ -32,13 +32,13 @@ if __name__ == '__main__': ...@@ -32,13 +32,13 @@ if __name__ == '__main__':
correlated_field_h = Amp * xi correlated_field_h = Amp * xi
correlated_field = ht(correlated_field_h) correlated_field = ht(correlated_field_h)
# alternatively to the block above one can do: # alternatively to the block above one can do:
# correlated_field,_ = ift.library.make_correlated_field(position_space, A) # correlated_field,_ = ift.make_correlated_field(position_space, A)
# apply some nonlinearity # apply some nonlinearity
signal = ift.PointwisePositiveTanh(correlated_field) signal = ift.PointwisePositiveTanh(correlated_field)
# Building the Line of Sight response # Building the Line of Sight response
LOS_starts, LOS_ends = get_random_LOS(100) LOS_starts, LOS_ends = get_random_LOS(100)
R = ift.library.LOSResponse(position_space, starts=LOS_starts, R = ift.LOSResponse(position_space, starts=LOS_starts,
ends=LOS_ends) ends=LOS_ends)
# build signal response model and model likelihood # build signal response model and model likelihood
signal_response = R(signal) signal_response = R(signal)
......
from .version import __version__ from .version import __version__
from . import dobj from . import dobj
from .domains import *
from .domains.domain import Domain
from .domains.structured_domain import StructuredDomain
from .domains.unstructured_domain import UnstructuredDomain
from .domains.rg_space import RGSpace
from .domains.lm_space import LMSpace
from .domains.gl_space import GLSpace
from .domains.hp_space import HPSpace
from .domains.power_space import PowerSpace
from .domains.dof_space import DOFSpace
from .domains.log_rg_space import LogRGSpace
from .domain_tuple import DomainTuple from .domain_tuple import DomainTuple
from .field import Field from .field import Field
from .nonlinearities import Exponential, Linear, PositiveTanh, Tanh from .nonlinearities import Exponential, Linear, PositiveTanh, Tanh
from .models import * from .models.constant import Constant
from .operators import * from .models.linear_model import LinearModel
from .models.local_nonlinearity import (LocalModel, PointwiseExponential,
PointwisePositiveTanh, PointwiseTanh)
from .models.model import Model
from .models.multi_model import MultiModel
from .models.variable import Variable
from .operators.diagonal_operator import DiagonalOperator
from .operators.dof_distributor import DOFDistributor
from .operators.domain_distributor import DomainDistributor
from .operators.endomorphic_operator import EndomorphicOperator
from .operators.exp_transform import ExpTransform
from .operators.fft_operator import FFTOperator
from .operators.fft_smoothing_operator import FFTSmoothingOperator
from .operators.geometry_remover import GeometryRemover
from .operators.harmonic_transform_operator import HarmonicTransformOperator
from .operators.inversion_enabler import InversionEnabler
from .operators.laplace_operator import LaplaceOperator
from .operators.linear_operator import LinearOperator
from .operators.mask_operator import MaskOperator
from .operators.multi_adaptor import MultiAdaptor
from .operators.power_distributor import PowerDistributor
from .operators.qht_operator import QHTOperator
from .operators.sampling_enabler import SamplingEnabler
from .operators.sandwich_operator import SandwichOperator
from .operators.scaling_operator import ScalingOperator
from .operators.selection_operator import SelectionOperator
from .operators.slope_operator import SlopeOperator
from .operators.smoothness_operator import SmoothnessOperator
from .operators.symmetrizing_operator import SymmetrizingOperator
from .probing.utils import probe_with_posterior_samples, probe_diagonal, \ from .probing.utils import probe_with_posterior_samples, probe_diagonal, \
StatCalculator StatCalculator
from .minimization import *
from .minimization.line_search import LineSearch
from .minimization.line_search_strong_wolfe import LineSearchStrongWolfe
from .minimization.iteration_controller import IterationController
from .minimization.gradient_norm_controller import GradientNormController
from .minimization.minimizer import Minimizer
from .minimization.conjugate_gradient import ConjugateGradient
from .minimization.nonlinear_cg import NonlinearCG
from .minimization.descent_minimizer import DescentMinimizer
from .minimization.steepest_descent import SteepestDescent
from .minimization.vl_bfgs import VL_BFGS
from .minimization.l_bfgs import L_BFGS
from .minimization.relaxed_newton import RelaxedNewton
from .minimization.scipy_minimizer import ScipyMinimizer, NewtonCG, L_BFGS_B, ScipyCG
from .minimization.energy import Energy
from .minimization.quadratic_energy import QuadraticEnergy
from .minimization.line_energy import LineEnergy
from .minimization.energy_sum import EnergySum
from .sugar import * from .sugar import *
from .plotting.plot import plot from .plotting.plot import plot
from .library import * from .library.amplitude_model import make_amplitude_model
from .library.apply_data import ApplyData
from .library.gaussian_energy import GaussianEnergy
from .library.los_response import LOSResponse
from .library.point_sources import PointSources
from .library.poissonian_energy import PoissonianEnergy
from .library.wiener_filter_curvature import WienerFilterCurvature
from .library.wiener_filter_energy import WienerFilterEnergy
from .library.correlated_fields import make_correlated_field, make_mf_correlated_field
from . import extra from . import extra
from .utilities import memo from .utilities import memo
from .logger import logger from .logger import logger
from .multi import * from .multi.multi_domain import MultiDomain
from .multi.multi_field import MultiField
from .multi.block_diagonal_operator import BlockDiagonalOperator
from .energies import * from .energies.kl import SampledKullbachLeiblerDivergence
from .energies.hamiltonian import Hamiltonian
# We deliberately don't set __all__ here, because we don't want people to do a # We deliberately don't set __all__ here, because we don't want people to do a
# "from nifty5 import *"; that would swamp the global namespace. # "from nifty5 import *"; that would swamp the global namespace.
from .domain import Domain
from .unstructured_domain import UnstructuredDomain
from .structured_domain import StructuredDomain
from .rg_space import RGSpace
from .lm_space import LMSpace
from .hp_space import HPSpace
from .gl_space import GLSpace
from .dof_space import DOFSpace
from .power_space import PowerSpace
from .log_rg_space import LogRGSpace
__all__ = ["Domain", "UnstructuredDomain", "StructuredDomain", "RGSpace",
"LMSpace", "HPSpace", "GLSpace", "DOFSpace", "PowerSpace",
"LogRGSpace"]
...@@ -105,7 +105,7 @@ class GLSpace(StructuredDomain): ...@@ -105,7 +105,7 @@ class GLSpace(StructuredDomain):
LMSpace LMSpace
The partner domain The partner domain
""" """
from .. import LMSpace from ..domains.lm_space import LMSpace
return LMSpace(lmax=self._nlat-1, mmax=self._nlon//2) return LMSpace(lmax=self._nlat-1, mmax=self._nlon//2)
def check_codomain(self, codomain): def check_codomain(self, codomain):
...@@ -117,6 +117,6 @@ class GLSpace(StructuredDomain): ...@@ -117,6 +117,6 @@ class GLSpace(StructuredDomain):
This function only checks whether `codomain` is of type This function only checks whether `codomain` is of type
:class:`LMSpace`. :class:`LMSpace`.
""" """
from .. import LMSpace from ..domains.lm_space import LMSpace
if not isinstance(codomain, LMSpace): if not isinstance(codomain, LMSpace):
raise TypeError("codomain must be a LMSpace.") raise TypeError("codomain must be a LMSpace.")
...@@ -80,7 +80,7 @@ class HPSpace(StructuredDomain): ...@@ -80,7 +80,7 @@ class HPSpace(StructuredDomain):
The `lmax` and `mmax` parameters of the returned :class:`LMSpace` are The `lmax` and `mmax` parameters of the returned :class:`LMSpace` are
set to `2*self.nside`. set to `2*self.nside`.
""" """
from .. import LMSpace from ..domains.lm_space import LMSpace
return LMSpace(lmax=2*self.nside) return LMSpace(lmax=2*self.nside)
def check_codomain(self, codomain): def check_codomain(self, codomain):
...@@ -92,6 +92,6 @@ class HPSpace(StructuredDomain): ...@@ -92,6 +92,6 @@ class HPSpace(StructuredDomain):
This function only checks whether `codomain` is of type This function only checks whether `codomain` is of type
:class:`LMSpace`. :class:`LMSpace`.
""" """
from .. import LMSpace from ..domains.lm_space import LMSpace
if not isinstance(codomain, LMSpace): if not isinstance(codomain, LMSpace):
raise TypeError("codomain must be a LMSpace.") raise TypeError("codomain must be a LMSpace.")
...@@ -139,7 +139,7 @@ class LMSpace(StructuredDomain): ...@@ -139,7 +139,7 @@ class LMSpace(StructuredDomain):
GLSpace GLSpace
The partner domain The partner domain
""" """
from .. import GLSpace from ..domains.gl_space import GLSpace
return GLSpace(self.lmax+1, self.mmax*2+1) return GLSpace(self.lmax+1, self.mmax*2+1)
def check_codomain(self, codomain): def check_codomain(self, codomain):
...@@ -151,6 +151,7 @@ class LMSpace(StructuredDomain): ...@@ -151,6 +151,7 @@ class LMSpace(StructuredDomain):
This function only checks whether `codomain` is of type This function only checks whether `codomain` is of type
:class:`GLSpace` or :class:`HPSpace`. :class:`GLSpace` or :class:`HPSpace`.
""" """
from .. import GLSpace, HPSpace from ..domains.gl_space import GLSpace
from ..domains.hp_space import HPSpace
if not isinstance(codomain, (GLSpace, HPSpace)): if not isinstance(codomain, (GLSpace, HPSpace)):
raise TypeError("codomain must be a GLSpace or HPSpace.") raise TypeError("codomain must be a GLSpace or HPSpace.")
from .kl import SampledKullbachLeiblerDivergence
from .hamiltonian import Hamiltonian
from .amplitude_model import make_amplitude_model
from .apply_data import ApplyData
from .gaussian_energy import GaussianEnergy
from .los_response import LOSResponse
from .point_sources import PointSources
from .poissonian_energy import PoissonianEnergy
from .wiener_filter_curvature import WienerFilterCurvature
from .wiener_filter_energy import WienerFilterEnergy
from .correlated_fields import make_correlated_field, make_mf_correlated_field
...@@ -32,9 +32,13 @@ def make_amplitude_model(s_space, Npixdof, ceps_a, ceps_k, sm, sv, im, iv, ...@@ -32,9 +32,13 @@ def make_amplitude_model(s_space, Npixdof, ceps_a, ceps_k, sm, sv, im, iv,
im, iv : y-intercept_mean, y-intercept_variance of power_slope im, iv : y-intercept_mean, y-intercept_variance of power_slope
''' '''
from ..operators import (ExpTransform, QHTOperator, SlopeOperator, from ..operators.exp_transform import ExpTransform
SymmetrizingOperator) from ..operators.qht_operator import QHTOperator
from ..models import Variable, Constant, PointwiseExponential from ..operators.slope_operator import SlopeOperator
from ..operators.symmetrizing_operator import SymmetrizingOperator
from ..models.variable import Variable
from ..models.constant import Constant
from ..models.local_nonlinearity import PointwiseExponential
h_space = s_space.get_default_codomain() h_space = s_space.get_default_codomain()
p_space = PowerSpace(h_space) p_space = PowerSpace(h_space)
......
...@@ -8,8 +8,12 @@ def make_correlated_field(s_space, amplitude_model): ...@@ -8,8 +8,12 @@ def make_correlated_field(s_space, amplitude_model):
amplitude_model : model for correlation structure amplitude_model : model for correlation structure
''' '''
from .. import (FFTOperator, Field, MultiField, PointwiseExponential, from ..operators.fft_operator import FFTOperator
PowerDistributor, Variable) from ..field import Field
from ..multi.multi_field import MultiField
from ..models.local_nonlinearity import PointwiseExponential
from ..operators.power_distributor import PowerDistributor
from ..models.variable import Variable
h_space = s_space.get_default_codomain() h_space = s_space.get_default_codomain()
ht = FFTOperator(h_space, s_space) ht = FFTOperator(h_space, s_space)
p_space = amplitude_model.value.domain[0] p_space = amplitude_model.value.domain[0]
...@@ -35,10 +39,15 @@ def make_mf_correlated_field(s_space_spatial, s_space_energy, ...@@ -35,10 +39,15 @@ def make_mf_correlated_field(s_space_spatial, s_space_energy,
''' '''
Method for construction of correlated multi-frequency fields Method for construction of correlated multi-frequency fields
''' '''
from .. import (DomainTuple, Field, MultiField, from ..operators.fft_operator import FFTOperator
PointwiseExponential, Variable) from ..field import Field
from ..operators import (DomainDistributor, PowerDistributor, from ..multi.multi_field import MultiField
HarmonicTransformOperator) from ..models.local_nonlinearity import PointwiseExponential
from ..operators.power_distributor import PowerDistributor
from ..models.variable import Variable
from ..domain_tuple import DomainTuple
from ..operators.domain_distributor import DomainDistributor
from ..operators.harmonic_transform_operator import HarmonicTransformOperator
h_space_spatial = s_space_spatial.get_default_codomain() h_space_spatial = s_space_spatial.get_default_codomain()
h_space_energy = s_space_energy.get_default_codomain() h_space_energy = s_space_energy.get_default_codomain()
h_space = DomainTuple.make((h_space_spatial, h_space_energy)) h_space = DomainTuple.make((h_space_spatial, h_space_energy))
......
...@@ -2,10 +2,10 @@ import numpy as np ...@@ -2,10 +2,10 @@ import numpy as np
from scipy.stats import invgamma, norm from scipy.stats import invgamma, norm
from ..field import Field from ..field import Field
from ..sugar import makeOp from ..sugar import makeOp
from ..multi import MultiField from ..multi.multi_field import MultiField
from ..models import Model from ..models.model import Model
from ..operators import SelectionOperator from ..operators.selection_operator import SelectionOperator
from ..utilities import memo from ..utilities import memo
......
from .line_search import LineSearch
from .line_search_strong_wolfe import LineSearchStrongWolfe
from .iteration_controller import IterationController
from .gradient_norm_controller import GradientNormController
from .minimizer import Minimizer
from .conjugate_gradient import ConjugateGradient
from .nonlinear_cg import NonlinearCG
from .descent_minimizer import DescentMinimizer
from .steepest_descent import SteepestDescent
from .vl_bfgs import VL_BFGS
from .l_bfgs import L_BFGS
from .relaxed_newton import RelaxedNewton
from .scipy_minimizer import ScipyMinimizer, NewtonCG, L_BFGS_B, ScipyCG
from .energy import Energy
from .quadratic_energy import QuadraticEnergy
from .line_energy import LineEnergy
from .energy_sum import EnergySum
__all__ = ["LineSearch", "LineSearchStrongWolfe",
"IterationController", "GradientNormController",
"Minimizer", "ConjugateGradient", "NonlinearCG", "DescentMinimizer",
"SteepestDescent", "VL_BFGS", "RelaxedNewton", "ScipyMinimizer",
"NewtonCG", "L_BFGS_B", "ScipyCG", "Energy", "QuadraticEnergy",
"LineEnergy", "L_BFGS", "EnergySum"]
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
import numpy as np import numpy as np
from ..field import Field from ..field import Field
from ..multi import MultiField
from ..utilities import NiftyMetaBase, memo from ..utilities import NiftyMetaBase, memo
......
from .constant import Constant
from .linear_model import LinearModel
from .local_nonlinearity import (LocalModel, PointwiseExponential,
PointwisePositiveTanh, PointwiseTanh)
from .model import Model
from .multi_model import MultiModel
from .variable import Variable
__all__ = ['Model', 'Constant', 'LocalModel', 'Variable',
'LinearModel', 'PointwiseTanh', 'PointwisePositiveTanh',
'PointwiseExponential', 'MultiModel']
from .multi_domain import MultiDomain
from .multi_field import MultiField
from .block_diagonal_operator import BlockDiagonalOperator
__all__ = ["MultiDomain", "MultiField", "BlockDiagonalOperator"]
from .diagonal_operator import DiagonalOperator
from .dof_distributor import DOFDistributor
from .domain_distributor import DomainDistributor
from .endomorphic_operator import EndomorphicOperator
from .exp_transform import ExpTransform
from .fft_operator import FFTOperator
from .fft_smoothing_operator import FFTSmoothingOperator
from .geometry_remover import GeometryRemover
from .harmonic_transform_operator import HarmonicTransformOperator
from .inversion_enabler import InversionEnabler
from .laplace_operator import LaplaceOperator
from .linear_operator import LinearOperator
from .mask_operator import MaskOperator
from .multi_adaptor import MultiAdaptor
from .power_distributor import PowerDistributor
from .qht_operator import QHTOperator
from .sampling_enabler import SamplingEnabler
from .sandwich_operator import SandwichOperator
from .scaling_operator import ScalingOperator
from .selection_operator import SelectionOperator
from .slope_operator import SlopeOperator
from .smoothness_operator import SmoothnessOperator
from .symmetrizing_operator import SymmetrizingOperator
__all__ = ["LinearOperator", "EndomorphicOperator", "ScalingOperator",
"DiagonalOperator", "HarmonicTransformOperator", "FFTOperator",
"FFTSmoothingOperator", "GeometryRemover", "MaskOperator",
"LaplaceOperator", "SmoothnessOperator", "PowerDistributor",
"InversionEnabler", "SandwichOperator", "SamplingEnabler",
"DOFDistributor", "SelectionOperator", "MultiAdaptor",
"ExpTransform", "SymmetrizingOperator", "QHTOperator",
"SlopeOperator", "DomainDistributor"]
import numpy as np import numpy as np
from ..domain_tuple import DomainTuple from ..domain_tuple import DomainTuple
from ..domains import PowerSpace, RGSpace from ..domains.power_space import PowerSpace
from ..domains.rg_space import RGSpace
from ..field import Field from ..field import Field
from .linear_operator import LinearOperator from .linear_operator import LinearOperator
from .. import dobj from .. import dobj
...@@ -52,7 +53,7 @@ class ExpTransform(LinearOperator): ...@@ -52,7 +53,7 @@ class ExpTransform(LinearOperator):
# 0 <= frac < 1. # 0 <= frac < 1.
self._frac[i] = coord - self._bindex[i] self._frac[i] = coord - self._bindex[i]
from ..domains import LogRGSpace from ..domains.log_rg_space import LogRGSpace
log_space = LogRGSpace(2*dof+1, bindistances, log_space = LogRGSpace(2*dof+1, bindistances,
t_mins, harmonic=False) t_mins, harmonic=False)
self._target = DomainTuple.make(target) self._target = DomainTuple.make(target)
......
...@@ -198,7 +198,8 @@ class LinearOperator(NiftyMetaBase()): ...@@ -198,7 +198,8 @@ class LinearOperator(NiftyMetaBase()):
def __call__(self, x): def __call__(self, x):
"""Same as :meth:`times`""" """Same as :meth:`times`"""
from ..models import LinearModel, Model from ..models.model import Model
from ..models.linear_model import LinearModel
if isinstance(x, Model): if isinstance(x, Model):
return LinearModel(x, self) return LinearModel(x, self)
return self.apply(x, self.TIMES) return self.apply(x, self.TIMES)
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from ..multi import MultiDomain, MultiField from ..multi.multi_domain import MultiDomain
from ..multi.multi_field import MultiField
from .linear_operator import LinearOperator from .linear_operator import LinearOperator
......
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