Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect gradients from simulation using ForwardDiff? #4

Open
andreas-brostrom opened this issue Nov 27, 2024 · 0 comments
Open

Incorrect gradients from simulation using ForwardDiff? #4

andreas-brostrom opened this issue Nov 27, 2024 · 0 comments

Comments

@andreas-brostrom
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant