misc.optimizers package

Submodules

misc.optimizers.cem module

class misc.optimizers.cem.CEMOptimizer(sol_dim, max_iters, popsize, num_elites, constrains, tf_session=None, epsilon=0.001, alpha=0.25, max_resamples=10)

Bases: misc.optimizers.optimizer.Optimizer

A Tensorflow-compatible CEM optimizer.

Parameters:
  • sol_dim (int) – The dimensionality of the problem space
  • max_iters (int) – The maximum number of iterations to perform during optimization
  • popsize (int) – The number of candidate solutions to be sampled at every iteration
  • num_elites (int) – The number of top solutions that will be used to obtain the distribution at the next iteration.
  • constrains (array) – [[np.array([min v, min q]), np.array([max v, max q])], [min q/v, max q/v], [min q/sqrt(v), max q/sqrt(v)]]
  • tf_session (tf.Session) – (optional) Session to be used for this optimizer. Defaults to None, in which case any functions passed in cannot be tf.Tensor-valued.
  • epsilon (float) – A minimum variance. If the maximum variance drops below epsilon, optimization is stopped.
  • alpha (float) – Controls how much of the previous mean and variance is used for the next iteration. next_mean = alpha * old_mean + (1 - alpha) * elite_mean, and similarly for variance.
changeSolDim(sol_dim)

Change the dimension of the CEM optimisation solution.

Parameters:sol_dim (int) – New dimension of the CEM optimisation solution.
obtain_solution(init_mean, init_var)

Optimizes the cost function using the provided initial candidate distribution

Parameters:
  • init_mean (np.ndarray) – The mean of the initial candidate distribution.
  • init_var (np.ndarray) – The variance of the initial candidate distribution.
reset()

Blank function for compatibility with optimisation class framework.

setup(cost_function, tf_compatible)

Sets up this optimizer using a given cost function.

Parameters:
  • cost_function (func) – A function for computing costs over a batch of candidate solutions.
  • tf_compatible (bool) – True if the cost function provided is tf.Tensor-valued.

Returns: None

misc.optimizers.optimizer module

class misc.optimizers.optimizer.Optimizer(*args, **kwargs)

Bases: object

Framework for Optimizer subclasses

obtain_solution(*args, **kwargs)

Compute optimisation problem solution

reset()

Function iteratively called at MPC.act()

setup(cost_function, tf_compatible)

Function called upon initialisation of the MPC class.

misc.optimizers.random module

class misc.optimizers.random.RandomOptimizer(sol_dim, popsize, tf_session, upper_bound=None, lower_bound=None)

Bases: misc.optimizers.optimizer.Optimizer

Random shooting optimisation.

Parameters:
  • sol_dim (int) – The dimensionality of the problem space
  • popsize (int) – The number of candidate solutions to be sampled at every iteration
  • num_elites (int) – The number of top solutions that will be used to obtain the distribution at the next iteration.
  • tf_session (tf.Session) – (optional) Session to be used for this optimizer. Defaults to None, in which case any functions passed in cannot be tf.Tensor-valued.
  • upper_bound (np.array) – An array of upper bounds
  • lower_bound (np.array) – An array of lower bounds
obtain_solution(*args, **kwargs)

Optimizes the cost function provided in setup().

Parameters:
  • init_mean (np.ndarray) – The mean of the initial candidate distribution.
  • init_var (np.ndarray) – The variance of the initial candidate distribution.
reset()

Function iteratively called at MPC.act()

setup(cost_function, tf_compatible)

Sets up this optimizer using a given cost function.

Parameters:
  • cost_function (func) – A function for computing costs over a batch of candidate solutions.
  • tf_compatible (bool) – True if the cost function provided is tf.Tensor-valued.

Returns: None

Module contents