optimization module¶
-
class
ezclimate.optimization.
CoordinateDescent
(utility, var_nums, accuracy=0.0001, iterations=100)[source]¶ Bases:
object
Coordinate descent optimization algorithm for the EZ-Climate model.
Parameters: - utility (Utility object) – object of utility class
- var_nums (int) – number of elements in array to optimize
- accuracy (float) – stop value for the utility increase
- iterations (int) – maximum number of iterations
-
utility
¶ Utility object – object of utility class
-
var_nums
¶ int – number of elements in array to optimize
-
accuracy
¶ float – stop value for the utility increase
-
iterations
¶ int – maximum number of iterations
-
class
ezclimate.optimization.
GeneticAlgorithm
(pop_amount, num_generations, cx_prob, mut_prob, bound, num_feature, utility, fixed_values=None, fixed_indicies=None, print_progress=False)[source]¶ Bases:
object
Optimization algorithm for the EZ-Climate model.
Parameters: - pop_amount (int) – number of individuals in the population
- num_feature (int) – number of elements in each individual, i.e. number of nodes in tree-model
- num_generations (int) – number of generations of the populations to be evaluated
- bound (float) – upper bound of mitigation in each node
- cx_prob (float) – probability of mating
- mut_prob (float) – probability of mutation.
- utility (Utility object) – object of utility class
- fixed_values (ndarray, optional) – nodes to keep fixed
- fixed_indicies (ndarray, optional) – indicies of nodes to keep fixed
- print_progress (bool, optional) – if the progress of the evolution should be printed
-
pop_amount
¶ int – number of individuals in the population
-
num_feature
¶ int – number of elements in each individual, i.e. number of nodes in tree-model
-
num_generations
¶ int – number of generations of the populations to be evaluated
-
bound
¶ float – upper bound of mitigation in each node
-
cx_prob
¶ float – probability of mating
-
mut_prob
¶ float – probability of mutation.
-
u
¶ Utility object – object of utility class
-
fixed_values
¶ ndarray, optional – nodes to keep fixed
-
fixed_indicies
¶ ndarray, optional – indicies of nodes to keep fixed
-
print_progress
¶ bool, optional – if the progress of the evolution should be printed
-
run
()[source]¶ Start the evolution process.
- The evolution steps are:
- Select the individuals to perform cross-over and mutation.
- Cross over among the selected candidate.
- Mutate result as offspring.
- Combine the result of offspring and parent together. And selected the top 80 percent of original population amount.
- Random Generate 20 percent of original population amount new individuals and combine the above new population.
Returns: final population and the fitness for the final population Return type: tuple Note
Uses the
multiprocessing
package.
-
class
ezclimate.optimization.
GradientSearch
(utility, var_nums, accuracy=1e-06, iterations=100, fixed_values=None, fixed_indicies=None, print_progress=False, scale_alpha=None)[source]¶ Bases:
object
Gradient search optimization algorithm for the EZ-Climate model.
Parameters: - utility (Utility object) – object of utility class
- learning_rate (float) – starting learning rate of gradient descent
- var_nums (int) – number of elements in array to optimize
- accuracy (float) – stop value for the gradient descent
- fixed_values (ndarray, optional) – nodes to keep fixed
- fixed_indicies (ndarray, optional) – indicies of nodes to keep fixed
- print_progress (bool, optional) – if the progress of the evolution should be printed
- scale_alpha (ndarray, optional) – array to scale the learning rate
-
utility
¶ Utility object – object of utility class
-
learning_rate
¶ float – starting learning rate of gradient descent
-
var_nums
¶ int – number of elements in array to optimize
-
accuracy
¶ float – stop value for the gradient descent
-
fixed_values
¶ ndarray, optional – nodes to keep fixed
-
fixed_indicies
¶ ndarray, optional – indicies of nodes to keep fixed
-
print_progress
¶ bool, optional – if the progress of the evolution should be printed
-
scale_alpha
¶ ndarray, optional – array to scale the learning rate
-
gradient_descent
(initial_point, return_last=False)[source]¶ Gradient descent algorithm. The initial_point is updated using the Adam algorithm. Adam uses the history of the gradient to compute individual step sizes for each element in the mitigation vector. The vector of step sizes are calculated using estimates of the first and second moments of the gradient.
Parameters: - initial_point (ndarray) – initial guess of the mitigation
- return_last (bool, optional) –
- if True the function returns the last point, else the point
- with highest utility
Returns: (best point, best utility)
Return type: tuple
-
numerical_gradient
(m, delta=1e-08, fixed_indicies=None)[source]¶ Calculate utility gradient numerically.
Parameters: - m (ndarray or list) – array of mitigation
- delta (float, optional) – change in mitigation
- fixed_indicies (ndarray or list, optional) – indicies of gradient that should not be calculated
Returns: gradient
Return type: ndarray
-
run
(initial_point_list, topk=4)[source]¶ Initiate the gradient search algorithm.
Parameters: - initial_point_list (list) – list of initial points to select from
- topk (int, optional) – select and run gradient descent on the topk first points of initial_point_list
Returns: best mitigation point and the utility of the best mitigation point
Return type: tuple
Raises: ValueError
– If topk is larger than the length of initial_point_list.Note
Uses the
multiprocessing
package.