Skip to content

Incorrect gradients from simulation using ForwardDiff? #4

@andreas-brostrom

Description

@andreas-brostrom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions