Commit 3c771b2f authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'master' of gitlab.mpcdf.mpg.de:ift/NIFTy

parents 9ee541a0 1c1b6377
Pipeline #17228 passed with stages
in 25 minutes and 7 seconds
from critical_filter import *
from log_normal_wiener_filter import *
from wiener_filter import *
from .critical_filter import *
from .log_normal_wiener_filter import *
from .wiener_filter import *
# -*- coding: utf-8 -*-
from critical_power_curvature import CriticalPowerCurvature
from critical_power_energy import CriticalPowerEnergy
from .critical_power_curvature import CriticalPowerCurvature
from .critical_power_energy import CriticalPowerEnergy
from nifty.operators.endomorphic_operator import EndomorphicOperator
from nifty.operators.invertible_operator_mixin import InvertibleOperatorMixin
from nifty.operators.diagonal_operator import DiagonalOperator
from ...operators.endomorphic_operator import EndomorphicOperator
from ...operators.invertible_operator_mixin import InvertibleOperatorMixin
from ...operators.diagonal_operator import DiagonalOperator
class CriticalPowerCurvature(InvertibleOperatorMixin, EndomorphicOperator):
......
from ...energies.energy import Energy
from ...operators.smoothness_operator import SmoothnessOperator
from . import CriticalPowerCurvature
from ...energies.memoization import memo
from nifty.energies.energy import Energy
from nifty.operators.smoothness_operator import SmoothnessOperator
from nifty.library.critical_filter import CriticalPowerCurvature
from nifty.energies.memoization import memo
from nifty.sugar import generate_posterior_sample
from nifty import Field, exp
from ...sugar import generate_posterior_sample
from ... import Field, exp
class CriticalPowerEnergy(Energy):
......
# -*- coding: utf-8 -*-
from log_normal_wiener_filter_curvature import LogNormalWienerFilterCurvature
from log_normal_wiener_filter_energy import LogNormalWienerFilterEnergy
from .log_normal_wiener_filter_curvature import LogNormalWienerFilterCurvature
from .log_normal_wiener_filter_energy import LogNormalWienerFilterEnergy
from nifty.operators import EndomorphicOperator,\
from ...operators import EndomorphicOperator,\
InvertibleOperatorMixin
from nifty.energies.memoization import memo
from nifty.basic_arithmetics import clipped_exp
from nifty.sugar import create_composed_fft_operator
from ...energies.memoization import memo
from ...basic_arithmetics import clipped_exp
from ...sugar import create_composed_fft_operator
class LogNormalWienerFilterCurvature(InvertibleOperatorMixin,
......
from nifty.energies.energy import Energy
from nifty.energies.memoization import memo
from nifty.library.log_normal_wiener_filter import \
LogNormalWienerFilterCurvature
from nifty.sugar import create_composed_fft_operator
from ...energies.energy import Energy
from ...energies.memoization import memo
from . import LogNormalWienerFilterCurvature
from ...sugar import create_composed_fft_operator
class LogNormalWienerFilterEnergy(Energy):
......
# -*- coding: utf-8 -*-
from wiener_filter_curvature import WienerFilterCurvature
from wiener_filter_energy import WienerFilterEnergy
from .wiener_filter_curvature import WienerFilterCurvature
from .wiener_filter_energy import WienerFilterEnergy
from nifty.operators import EndomorphicOperator,\
InvertibleOperatorMixin
from ...operators import EndomorphicOperator,\
InvertibleOperatorMixin
class WienerFilterCurvature(InvertibleOperatorMixin, EndomorphicOperator):
......
from nifty.energies.energy import Energy
from nifty.energies.memoization import memo
from nifty.library.wiener_filter import WienerFilterCurvature
from ...energies.energy import Energy
from ...energies.memoization import memo
from . import WienerFilterCurvature
class WienerFilterEnergy(Energy):
......
......@@ -16,9 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from line_searching import *
from conjugate_gradient import ConjugateGradient
from descent_minimizer import DescentMinimizer
from steepest_descent import SteepestDescent
from vl_bfgs import VL_BFGS
from relaxed_newton import RelaxedNewton
from .line_searching import *
from .conjugate_gradient import ConjugateGradient
from .descent_minimizer import DescentMinimizer
from .steepest_descent import SteepestDescent
from .vl_bfgs import VL_BFGS
from .relaxed_newton import RelaxedNewton
......@@ -16,17 +16,19 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
import abc
from nifty.nifty_meta import NiftyMeta
from ..nifty_meta import NiftyMeta
import numpy as np
from keepers import Loggable
from .line_searching import LineSearchStrongWolfe
from future.utils import with_metaclass
class DescentMinimizer(Loggable, object):
class DescentMinimizer(with_metaclass(NiftyMeta, type('NewBase', (Loggable, object), {}))):
""" A base class used by gradient methods to find a local minimum.
Descent minimization methods are used to find a local minimum of a scalar
......@@ -77,8 +79,6 @@ class DescentMinimizer(Loggable, object):
"""
__metaclass__ = NiftyMeta
def __init__(self, line_searcher=LineSearchStrongWolfe(), callback=None,
convergence_tolerance=1E-4, convergence_level=3,
iteration_limit=None):
......
......@@ -16,5 +16,5 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from line_search import LineSearch
from line_search_strong_wolfe import LineSearchStrongWolfe
from .line_search import LineSearch
from .line_search_strong_wolfe import LineSearchStrongWolfe
......@@ -20,10 +20,11 @@ import abc
from keepers import Loggable
from nifty import LineEnergy
from ...energies import LineEnergy
from future.utils import with_metaclass
class LineSearch(Loggable, object):
class LineSearch(with_metaclass(abc.ABCMeta, type('NewBase', (Loggable, object), {}))):
"""Class for determining the optimal step size along some descent direction.
Initialize the line search procedure which can be used by a specific line
......
......@@ -16,6 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import print_function
from __future__ import division
from builtins import range
import numpy as np
from .line_search import LineSearch
......@@ -121,10 +124,10 @@ class LineSearchStrongWolfe(LineSearch):
if alpha1 < 0:
alpha1 = 1.0
else:
alpha1 = 1.0
alpha1 = 1.0/pk.norm()
# start the minimization loop
for i in xrange(self.max_iterations):
for i in range(self.max_iterations):
if alpha1 == 0:
self.logger.warn("Increment size became 0.")
return le_0.energy
......@@ -152,7 +155,7 @@ class LineSearchStrongWolfe(LineSearch):
# update alphas
alpha0, alpha1 = alpha1, min(2*alpha1, self.max_step_size)
if alpha1 == self.max_step_size:
print "reached max step size, bailing out"
print ("reached max step size, bailing out")
return le_alpha1.energy
phi_alpha0 = phi_alpha1
......@@ -207,7 +210,7 @@ class LineSearchStrongWolfe(LineSearch):
assert phi_lo <= phi_0 + self.c1*alpha_lo*phiprime_0
assert phiprime_lo*(alpha_hi-alpha_lo) < 0.
for i in xrange(self.max_zoom_iterations):
for i in range(self.max_zoom_iterations):
# assert phi_lo <= phi_0 + self.c1*alpha_lo*phiprime_0
# assert phiprime_lo*(alpha_hi-alpha_lo)<0.
delta_alpha = alpha_hi - alpha_lo
......
from __future__ import division
# 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
......@@ -16,6 +17,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
from .descent_minimizer import DescentMinimizer
......
......@@ -16,6 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
from builtins import range
from builtins import object
import numpy as np
from .descent_minimizer import DescentMinimizer
......@@ -81,7 +84,7 @@ class VL_BFGS(DescentMinimizer):
delta = self._information_store.delta
descent_direction = delta[0] * b[0]
for i in xrange(1, len(delta)):
for i in range(1, len(delta)):
descent_direction += delta[i] * b[i]
return descent_direction
......@@ -154,14 +157,15 @@ class InformationStore(object):
result = []
m = self.history_length
mmax = self.max_history_length
k = self.k
k = self.k
s = self.s
for i in xrange(m):
for i in range(m):
result.append(s[(k-m+i) % mmax])
y = self.y
for i in xrange(m):
for i in range(m):
result.append(y[(k-m+i) % mmax])
result.append(self.last_gradient)
......@@ -188,18 +192,18 @@ class InformationStore(object):
# update the stores
k1 = (k-1) % mmax
for i in xrange(m):
for i in range(m):
kmi = (k-m+i) % mmax
self.ss[kmi, k1] = self.ss[k1, kmi] = self.s[kmi].vdot(self.s[k1])
self.yy[kmi, k1] = self.yy[k1, kmi] = self.y[kmi].vdot(self.y[k1])
self.sy[kmi, k1] = self.s[kmi].vdot(self.y[k1])
for j in xrange(m-1):
for j in range(m-1):
kmj = (k-m+j) % mmax
self.sy[k1, kmj] = self.s[k1].vdot(self.y[kmj])
for i in xrange(m):
for i in range(m):
kmi = (k-m+i) % mmax
for j in xrange(m):
for j in range(m):
kmj = (k-m+j) % mmax
result[i, j] = self.ss[kmi, kmj]
result[i, m+j] = result[m+j, i] = self.sy[kmi, kmj]
......@@ -233,16 +237,16 @@ class InformationStore(object):
alpha = np.empty(m, dtype=np.float)
for j in xrange(m-1, -1, -1):
delta_b_b = sum([delta[l] * b_dot_b[l, j] for l in xrange(2*m+1)])
for j in range(m-1, -1, -1):
delta_b_b = sum([delta[l] * b_dot_b[l, j] for l in range(2*m+1)])
alpha[j] = delta_b_b/b_dot_b[j, m+j]
delta[m+j] -= alpha[j]
for i in xrange(2*m+1):
for i in range(2*m+1):
delta[i] *= b_dot_b[m-1, 2*m-1]/b_dot_b[2*m-1, 2*m-1]
for j in xrange(m):
delta_b_b = sum([delta[l]*b_dot_b[m+j, l] for l in xrange(2*m+1)])
for j in range(m):
delta_b_b = sum([delta[l]*b_dot_b[m+j, l] for l in range(2*m+1)])
beta = delta_b_b/b_dot_b[j, m+j]
delta[j] += (alpha[j] - beta)
......
......@@ -17,7 +17,7 @@ class DocStringInheritor(type):
if doc:
clsdict['__doc__'] = doc
break
for attr, attribute in clsdict.items():
for attr, attribute in list(clsdict.items()):
if not attribute.__doc__:
for mro_cls in (mro_cls for base in bases
for mro_cls in base.mro()
......
......@@ -16,6 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from builtins import next
from builtins import range
import numpy as np
from itertools import product
......@@ -53,7 +55,7 @@ def get_slice_list(shape, axes):
raise ValueError("axes(axis) does not match shape.")
axes_select = [0 if x in axes else 1 for x, y in enumerate(shape)]
axes_iterables = \
[range(y) for x, y in enumerate(shape) if x not in axes]
[list(range(y)) for x, y in enumerate(shape) if x not in axes]
for index in product(*axes_iterables):
it_iter = iter(index)
slice_list = [
......@@ -94,7 +96,7 @@ def cast_axis_to_tuple(axis, length=None):
def parse_domain(domain):
from nifty.domain_object import DomainObject
from .domain_object import DomainObject
if domain is None:
domain = ()
elif isinstance(domain, DomainObject):
......
......@@ -18,24 +18,24 @@
from __future__ import division
from linear_operator import LinearOperator
from .linear_operator import LinearOperator
from diagonal_operator import DiagonalOperator
from .diagonal_operator import DiagonalOperator
from endomorphic_operator import EndomorphicOperator
from .endomorphic_operator import EndomorphicOperator
from smoothing_operator import *
from .smoothing_operator import *
from fft_operator import *
from .fft_operator import *
from invertible_operator_mixin import InvertibleOperatorMixin
from .invertible_operator_mixin import InvertibleOperatorMixin
from projection_operator import ProjectionOperator
from .projection_operator import ProjectionOperator
from composed_operator import ComposedOperator
from .composed_operator import ComposedOperator
from response_operator import ResponseOperator
from .response_operator import ResponseOperator
from laplace_operator import LaplaceOperator
from .laplace_operator import LaplaceOperator
from smoothness_operator import SmoothnessOperator
from .smoothness_operator import SmoothnessOperator
Supports Markdown
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