:py:mod:`fragile.optimize.env` ============================== .. py:module:: fragile.optimize.env Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: fragile.optimize.env.Minimizer fragile.optimize.env.MinimizerWrapper fragile.optimize.env.ParticleSimulation .. py:class:: Minimizer(function, bounds=None, **kwargs) Apply ``scipy.optimize.minimize`` to a :class:`Function`. .. py:method:: minimize(x) Apply ``scipy.optimize.minimize`` to a single point. :param x: Array representing a single point of the function to be minimized. :returns: Optimization result object returned by ``scipy.optimize.minimize``. .. py:method:: minimize_point(x) Minimize the target function passing one starting point. :param x: Array representing a single point of the function to be minimized. :returns: Tuple containing a numpy array representing the best solution found, and the numerical value of the function at that point. .. py:method:: minimize_batch(x) Minimize a batch of points. :param x: Array representing a batch of points to be optimized, stacked across the first dimension. :returns: Tuple of arrays containing the local optimum found for each point, and an array with the values assigned to each of the points found. .. py:class:: MinimizerWrapper(function, **kwargs) Bases: :py:obj:`fragile.core.env.Function` Wrapper that applies a local minimization process to the observations returned by a :class:`Function`. .. py:method:: shape() :property: Return the shape of the wrapped environment. .. py:method:: function() :property: Return the function of the wrapped environment. .. py:method:: bounds() :property: Return the bounds of the wrapped environment. .. py:method:: custom_domain_check() :property: Return the custom_domain_check of the wrapped environment. .. py:method:: __getattr__(item) .. py:method:: __repr__() Return repr(self). .. py:method:: setup(swarm) Prepare the component during the setup phase of the :class:`Swarm`. .. py:method:: make_transitions(inplace = True, **kwargs) Perform a local optimization process to the observations returned after calling ``make_transitions`` on the wrapped :class:`Function`. .. py:class:: ParticleSimulation(step_size=1.0, steps=10, **kwargs) Bases: :py:obj:`fragile.core.env.Function` Environment that represents an arbitrary mathematical function bounded in a given interval. .. py:attribute:: default_inputs .. py:attribute:: default_outputs :annotation: = ['observs', 'rewards', 'oobs', 'velocities'] .. py:method:: from_instance(function, step_size = 1, steps=1, x0=None, start_same_pos = False) :classmethod: .. py:method:: param_dict() :property: Return the dictionary defining all the data attributes that the component requires. .. py:method:: calculate_forces(observs, **kwargs) .. py:method:: fai_leapfrog(init_pos, init_momentum, grad, step_size, function, force=None) Perfom a leapfrog jump in the Hamiltonian space INPUTS ------ init_pos: ndarray[float, ndim=1] initial parameter position init_momentum: ndarray[float, ndim=1] initial momentum grad: float initial gradient value step_size: float step size function: callable it should return the log probability and gradient evaluated at theta logp, grad = function(theta) OUTPUTS ------- new_position: ndarray[float, ndim=1] new parameter position new_momentum: ndarray[float, ndim=1] new momentum gradprime: float new gradient new_potential: float new lnp .. py:method:: step(actions, observs, velocities, **kwargs) Sum the target action to the observations to obtain the new points, and evaluate the reward and boundary conditions. :returns: Dictionary containing the information of the new points evaluated. ``{"states": new_points, "observs": new_points, "rewards": typing.Scalar array, "oobs": boolean array}``