Objective Functions

This module provides a library of pre-defined ParMOO objective function implementations and templates to define your own objective function.

ObjectiveFunction Template (ABC)

An abstract base class (ABC) for ParMOO objective functions.

class objectives.obj_func.ObjectiveFunction(des_type, sim_type)

ABC defining ParMOO objective functions.

Extend this class to create a callable object that matches ParMOO can use as a objective function, such as an Objective or its Gradient.

Contains 2 methods:
  • __init__(des_type, sim_type)

  • __call__(x, sx)

The __init__ method is already implemented, and is the constructor. It can be overwritten if additional inputs (besides the design variable and simulation output types) are needed.

The __call__ method is left to be implemented, and performs the objective function evaluation.

__init__(des_type, sim_type)

Constructor for ObjectiveFunction class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

Objective Function Library

This module contains a library of common objective functions, matching ParMOO’s interface.

The common objectives are:
  • SingleSimObjective – min or max a single simulation output

  • SumOfSimSquaresObjective – min or max several squared sim outputs

  • SumOfSimsObjective – min or max the (absolute) sum of sim outputs

And the corresponding gradients are defined in:
  • SingleSimGradient

  • SumOfSimSquaresGradient

  • SumOfSimsGradient

class objectives.obj_lib.SingleSimObjective(des_type, sim_type, sim_ind, goal='min')

Class for min/maxing a single simulation’s output.

If minimizing:

def ObjectiveFunction(x, sx): return sx[self.sim_ind]

If maximizing:

def ObjectiveFunction(x, sx): return -sx[self.sim_ind]

Also supports derivative usage.

Contains 2 methods:
  • __init__(des_type, sim_type, sim_ind, goal='min')

  • __call__(x, sim)

The __init__ method inherits from the ObjectiveFunction ABC.

The __call__ returns sim[self.sim_ind].

__init__(des_type, sim_type, sim_ind, goal='min')

Constructor for SingleSimObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_ind (str or tuple) – The name (or name, output index pair for simulations with more than one output field) designating the simulation output to minimize or maximize.

  • goal (str) – Either ‘min’ to minimize or ‘max’ to maximize. Defaults to ‘min’.

__call__(x, sx)

Define objective evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The output of the simulation at self.sim_ind given the input x.

Return type:

float

class objectives.obj_lib.SumOfSimSquaresObjective(des_type, sim_type, sim_inds, goal='min')

Class for min/maxing the sum-of-squared simulation outputs.

If minimizing, equivalent to:

``` def ObjectiveFunction(x, sx):

return sum([sx[i]**2 for i in sim_inds])

```

If maximizing, equivalent to:

``` def ObjectiveFunction(x, sx):

return -sum([sx[i]**2 for i in sim_inds])

```

Also supports derivative usage.

Contains 2 methods:
  • __init__(des_type, sim_type, sim_inds, goal='min')

  • __call__(x, sx)

The __init__ method inherits from the ObjectiveFunction ABC.

The __call__ evaluates the sum-of-squared simulation outputs.

__init__(des_type, sim_type, sim_inds, goal='min')

Constructor for SumOfSimSquaresObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_inds (list) – The list of names (or name, index pairs for sims with more than one output) of the simulation outputs to sum over.

  • goal (str) – Either ‘min’ to minimize SOS or ‘max’ to maximize SOS. Defaults to ‘min’.

__call__(x, sx)

Define objective evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The sum of squared outputs of the simulation at indices in self.sim_ind given the input x.

Return type:

float

class objectives.obj_lib.SumOfSimsObjective(des_type, sim_type, sim_inds, goal='min', absolute=False)

Class for min/maxing the sum of simulation outputs.

If minimizing:

def ObjectiveFunction(x, sx): return sum([sx[i] for i in sim_inds])

If maximizing:

def ObjectiveFunction(x, sx): return -sum([sx[i] for i in sim_inds])

If minimizing absolute sum:

` def ObjectiveFunction(x, sx): return sum([abs(sx[i]) for i in sim_inds]) `

If maximizing absolute sum:

` def ObjectiveFunction(x, sx): return -sum([abs(sx[i]) for i in sim_inds]) `

Also supports derivative usage.

Contains 2 methods:
  • __init__(des_type, sim_type, sim_inds, goal='min', absolute=False)

  • __call__(x, sx)

The __init__ method inherits from the ObjectiveFunction ABC.

The __call__ evaluate the (absolute) sum outputs.

__init__(des_type, sim_type, sim_inds, goal='min', absolute=False)

Constructor for SumOfSimsObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_inds (list) – The list of indices or names of the simulation outputs to sum over.

  • goal (str) – Either ‘min’ to minimize sum or ‘max’ to maximize sum. Defaults to ‘min’.

  • absolute (bool) – True to min/max absolute sum, False to min/max raw sum. Defaults to False.

__call__(x, sx)

Define objective evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The sum of the simulation outputs at indices in self.sim_ind given the input x.

Return type:

float

class objectives.obj_lib.SingleSimGradient(des_type, sim_type, sim_ind, goal='min')

Gradient class for SingleSimObjective.

Inherits from the SingleSimObjective class, but overwrites the __call__ method to return the gradients wrt x and sx, respectively.

__init__(des_type, sim_type, sim_ind, goal='min')

Constructor for SingleSimObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_ind (str or tuple) – The name (or name, output index pair for simulations with more than one output field) designating the simulation output to minimize or maximize.

  • goal (str) – Either ‘min’ to minimize or ‘max’ to maximize. Defaults to ‘min’.

__call__(x, sx)

Define gradient evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The gradient output of the simulation at self.sim_ind given the input (x, sx) wrt x and sx, respectively.

Return type:

dict, dict

class objectives.obj_lib.SumOfSimSquaresGradient(des_type, sim_type, sim_inds, goal='min')

Gradient class for SumOfSimSquaresObjective.

Inherits from the SumOfSimSquaresObjective class, but overwrites the __call__ method to return the gradients wrt x and sx, respectively.

__init__(des_type, sim_type, sim_inds, goal='min')

Constructor for SumOfSimSquaresObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_inds (list) – The list of names (or name, index pairs for sims with more than one output) of the simulation outputs to sum over.

  • goal (str) – Either ‘min’ to minimize SOS or ‘max’ to maximize SOS. Defaults to ‘min’.

__call__(x, sx)

Define gradient evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The gradient of the sum of squared simulation outputs given the input (x, sx) wrt x and sx, respectively.

Return type:

dict, dict

class objectives.obj_lib.SumOfSimsGradient(des_type, sim_type, sim_inds, goal='min', absolute=False)

Gradient class for SumOfSimsObjective.

Inherits from the SumOfSimsObjective class, but overwrites the __call__ method to return the gradients wrt x and sx, respectively.

__init__(des_type, sim_type, sim_inds, goal='min', absolute=False)

Constructor for SumOfSimsObjective class.

Parameters:
  • des_type (np.dtype) – The numpy.dtype of the design variables.

  • sim_type (np.dtype) – The numpy.dtype of the simulation outputs.

  • sim_inds (list) – The list of indices or names of the simulation outputs to sum over.

  • goal (str) – Either ‘min’ to minimize sum or ‘max’ to maximize sum. Defaults to ‘min’.

  • absolute (bool) – True to min/max absolute sum, False to min/max raw sum. Defaults to False.

__call__(x, sx)

Define gradient evaluation.

Parameters:
  • x (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of a design point to evaluate.

  • sx (dict or structured array) – A Python dictionary or numpy structured array containing the names (as keys) and corresponding values of the simulation output(s) at x.

Returns:

The gradient of the sum of (absolute) simulation outputs given the input (x, sx) wrt x and sx, respectively.

Return type:

dict, dict