atomica.optimization.IncreaseByMeasurable

class atomica.optimization.IncreaseByMeasurable(measurable_name, t, increase, pop_names=None, target_type='frac')[source]

Bases: atomica.optimization.Measurable

Increase quantity by percentage

This Measurable stores the value of a quantity using the original instructions. It then requires that there is a minimum increase in the value of the quantity during optimization. For example

>>> IncreaseByMeasurable('alive',2030,0.05)

This Measurable would correspond to an increase of 5% in the number of people alive in 2030.

The measurable returns np.inf if the condition is violated, and 0.0 otherwise.

Parameters
  • measurable_name – The base measurable class accepts the name of a program (for spending) or a quantity supported by Population.get_variable()

  • t – Single year, or a list of two start/stop years. If specifying a single year, that year must appear in the simulation output. The quantity will be summed over all simulation time points

  • increase – The amount by which to increase the measurable (e.g. 0.05 for a 5% increase). Use target_type='abs' to specify an absolute increase

  • pop_names – The base Measurable class takes in the names of the populations to use. If multiple populations are provided, the objective will be added across the named populations

  • target_type – Specify fractional ‘frac’ or absolute ‘abs’ increase (default is fractional)

Methods

eval

get_baseline

Return cached baseline values

get_objective_val

Return objective value

get_baseline(model)[source]

Return cached baseline values

Similar to get_hard_constraint, sometimes a relative Measurable might be desired e.g. ‘Reduce deaths by at least 50%’. In that case, we need to perform a procedure similar to getting a hard constraint, where the Measurable receives an initial Model object and extracts baseline data for subsequent use in get_objective_val.

Thus, the output of this function is paired to its usage in get_objective_val.

Parameters

model

Return type

float

Returns

The value to pass back to the Measurable during optimization

get_objective_val(model, baseline)[source]

Return objective value

This method should return the _unweighted_ objective value. Note that further transformation may occur

Parameters
  • model (Model) – A Model object after integration

  • baseline (float) – The baseline variable returned by this Measurable at the start of optimization

Return type

float

Returns

A scalar objective value