Пример #1
0
 def __init__(self, function, args=(), bounds=None,
              callback=None, options=None, processes=None):
     ParallelResources().arguments = args
     ParallelResources().custom_function = function
     self.xval = None
     self.function_value = None
     self.jacobian_value = None
     self.precision = self.K.np.finfo(self.K.qnp.dtypes("DTYPE")).eps
     self.bounds = bounds
     self.callback = callback
     self.options = options
     self.processes = processes
Пример #2
0
    def run(self, x0):
        """Executes parallel L-BFGS-B minimization.
        Args:
            x0 (numpy.array): guess for initial solution.

        Returns:
            scipy.minimize result object
        """
        ParallelResources().lock = self.mp.Lock()
        with self.mp.Pool(processes=self.processes) as self.pool:
            from scipy.optimize import minimize
            out = minimize(fun=self.fun, x0=x0, jac=self.jac, method='L-BFGS-B',
                           bounds=self.bounds, callback=self.callback, options=self.options)
        ParallelResources().reset()
        out.hess_inv = out.hess_inv * self.K.np.identity(len(x0))
        return out