When running the optimization example in examples/optimization.jl, it appears that the optimization does not care about the part of the cost function that actually comes from the simulation results (delay_benefit), but only the direct dependencies on the varying parameters (wall_height and wall_position):
wall_cost = 1000 * (wall_height - 1.0)^2 + 2000
delay_benefit = 100 * exp(-(total_water_at_cell - 50)^2) # <------------ This does not have any effect
position_cost = 50 + 1000 * (sin(1 / 50 * pi * wall_position)^2)
total_costs = wall_cost - delay_benefit + position_cost
The result is that total_costs gets minimized to the sum of the minimized wall_cost and position_cost (since they are independent). The gradients of total_water_at_cell, coming from the simulator through a callback, looks to be wrong (typically blown up >1e100). When running the optimizer without providing a gradient function [ForwardDiff.gradient(...)], finite differences are used instead, which seems produce results which are at least dependent on the total_water_at_cell.
As a side note, the delay_benefit part of the cost function vanishes completely when |total_water_at_cell - 50| is large, so I think a better way of incorporating total_water_at_cell (or some other simulation output) into the cost function is necessary.
When running the optimization example in
examples/optimization.jl, it appears that the optimization does not care about the part of the cost function that actually comes from the simulation results (delay_benefit), but only the direct dependencies on the varying parameters (wall_heightandwall_position):The result is that
total_costsgets minimized to the sum of the minimizedwall_costandposition_cost(since they are independent). The gradients oftotal_water_at_cell, coming from the simulator through a callback, looks to be wrong (typically blown up >1e100). When running the optimizer without providing a gradient function [ForwardDiff.gradient(...)], finite differences are used instead, which seems produce results which are at least dependent on thetotal_water_at_cell.As a side note, the
delay_benefitpart of the cost function vanishes completely when|total_water_at_cell - 50|is large, so I think a better way of incorporatingtotal_water_at_cell(or some other simulation output) into the cost function is necessary.