def __init__(self, problem, inner_product="L2", parameters=None): """ Create a new OptizelleSolver. The argument inner_product specifies the inner product to be used for the control space. To set optizelle-specific options, do e.g. solver = OptizelleSolver(problem, parameters={'maximum_iterations': 100, 'optizelle_parameters': {'krylov_iter_max': 100}}) """ try: import Optizelle import Optizelle.Unconstrained.State import Optizelle.Unconstrained.Functions import Optizelle.Unconstrained.Algorithms import Optizelle.Constrained.State import Optizelle.Constrained.Functions import Optizelle.Constrained.Algorithms import Optizelle.EqualityConstrained.State import Optizelle.EqualityConstrained.Functions import Optizelle.EqualityConstrained.Algorithms import Optizelle.InequalityConstrained.State import Optizelle.InequalityConstrained.Functions import Optizelle.InequalityConstrained.Algorithms except ImportError: print("Could not import Optizelle.") raise DolfinVectorSpace.inner_product = inner_product OptimizationSolver.__init__(self, problem, parameters) self.__build_optizelle_state()
def __init__(self, problem, parameters=None): """ Create a new OptizelleSolver. To set optizelle-specific options, do e.g. solver = OptizelleSolver(problem, parameters={'maximum_iterations': 100, 'optizelle_parameters': {'krylov_iter_max': 100}}) """ try: import Optizelle import Optizelle.Unconstrained.State import Optizelle.Unconstrained.Functions import Optizelle.Unconstrained.Algorithms import Optizelle.Constrained.State import Optizelle.Constrained.Functions import Optizelle.Constrained.Algorithms import Optizelle.EqualityConstrained.State import Optizelle.EqualityConstrained.Functions import Optizelle.EqualityConstrained.Algorithms import Optizelle.InequalityConstrained.State import Optizelle.InequalityConstrained.Functions import Optizelle.InequalityConstrained.Algorithms except ImportError: print("Could not import Optizelle.") raise OptimizationSolver.__init__(self, problem, parameters) self.__build_optizelle_state()
def __init__(self, problem, parameters=None): try: import pyipopt except ImportError: print("You need to install pyipopt. It is recommended to install IPOPT with HSL support!") raise OptimizationSolver.__init__(self, problem, parameters) self.__build_pyipopt_problem() self.__set_parameters()
def solve(self): # split to YUV channels y_channel, u_channel, v_channel = self.__get_yuv_channels_from_matrices() has_hints = abs(self.__grayscale_bgr_matrix - self.__marked_bgr_matrix).sum(2) > 0.01 wrs = self.__compute_weights(has_hints, y_channel) # perform optimization optimization_solver = OptimizationSolver(wrs, has_hints) new_u, new_v = optimization_solver.optimize(u_channel, v_channel) return yuv_channels_to_bgr_image(y_channel, new_u, new_v)
def __init__(self, problem, parameters=None, riesz_map=None, prefix=""): try: from petsc4py import PETSc except: raise Exception, "Could not find petsc4py. Please install it." try: TAO = PETSc.TAO except: raise Exception, "Your petsc4py version does not support TAO. Please upgrade to petsc4py >= 3.5." self.PETSc = PETSc # Use PETSc forms if riesz_map is not None: # Handle the case where the user supplied riesz_maps.L2(V) if hasattr(riesz_map, "assemble"): riesz_map = riesz_map.assemble() self.riesz_map = as_backend_type(riesz_map).mat() else: self.riesz_map = None if len(prefix) > 0 and prefix[-1] != "_": prefix += "_" self.prefix = prefix OptimizationSolver.__init__(self, problem, parameters) self.tao = PETSc.TAO().create(PETSc.COMM_WORLD) self.__build_app_context() self.__set_parameters() self.__build_tao()