# Does automatic differentiation work for function with discrete argument?

**URL:** <https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947>\
**Category:** Optimization (Mathematical)\
**Created:** [March 13, 2020, 9:03pm UTC](https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947 "2020-03-13T21:03:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 14, 2020, 6:27am UTC](https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947/4 "2020-03-14T06:27:24Z")

</div>

> [@zxjroger](#):
>
> The function g(⋅)g(\cdot) is kind of smooth, although argument HH is discrete.

But the function you are dealing with is f(\theta) = g(H(X \mid \theta), X) which in general will not be continuous(ly differentiable) if H isn’t, even if g is.

Depending on how bad things are, stochastic (eg simulated annealing) or robust deterministic derivative-free optimization methods are used in these cases. See

> [@Latest recommendations for global optimization](https://discourse.julialang.org/t/latest-recommendations-for-global-optimization/17718):
>
> What are people’s recommendations for a global optimizer? I’m trying to do simulated method of moments (choosing a set of parameters for an economic model to minimise the distance between model predictions and data) and have so far been using blackboxoptim. I find it somewhat unreliable: running exactly the same code on the same data I find sometimes the optimizer gives me a parameter choice that provides a close fit to the data, but sometimes it just seems to get stuck without converging). Any …

> [@Global optimization: Simulated Method of Moments](https://discourse.julialang.org/t/global-optimization-simulated-method-of-moments/23844):
>
> I work with non-linear models that need to be calibrated to match data moments. The setup is simple. I have a function that takes a set of parameters as input (for example, a vector of floats), solves the model, and returns a measure of the distance between the model-generated moments and the data moments. Typically there are more moments than parameters. Hence, I use some simple weighting function to summarize the differences between model and data moments into one float. The objective is to m…

---

_[View the full topic](https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947)._
