# Simulated Annealing equivalent in PyMC3?

**URL:** <https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418>\
**Category:** Questions\
**Created:** [December 12, 2020, 8:31pm UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418 "2020-12-12T20:31:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbuddy\_13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jbuddy_13/32/5900_2.png) [@jbuddy\_13](https://discourse.pymc.io/u/jbuddy_13)\
**Post date:** [December 12, 2020, 8:31pm UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418/1 "2020-12-12T20:31:35Z")

</div>

I’m wondering, is there something analogous to simulated annealing in PyMC3?

The [scipy algorithm](https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.optimize.anneal.html) is deprecated and it’s effectively the application of Metropolis-Hastings to combinatorial optimization problems. For detailed specifics, see the [wikipedia entry.](https://en.wikipedia.org/wiki/Simulated_annealing)

generally speaking, the algorithm gets its namesake from metallurgy; a problem is “hot” in early iterations, which means large changes to parameters are accepted; as the problem “cools” only small changes to the optimization problem are accepted.

With PyMC3’s usage of HMC/NUTs, I thought it might be able to use gradient information to more efficiently explore the “reward space”. This might get rid of the random walk nature of SA and remove the need for the dynamic/shrinking proposal distribution.

As an aside: If this isn’t a thing in the PyMC3 ecosystem, does anyone see value in it? Would anyone like to collaborate with me on such a solution?

Cheers!

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [December 13, 2020, 10:54am UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418/2 "2020-12-13T10:54:37Z")

</div>

There is Sequential Monte Carlos which works similarly (ie based on importance sampling), we dont use it to do optimization thought.  
I guess the question of whether it would be useful for PyMC3 ecosystem depends on the use case: what kind of problems are uniquely suitable to use this type of algorithm?

---

<div class="post-metadata">

**Author:** ![jbuddy\_13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jbuddy_13/32/5900_2.png) [@jbuddy\_13](https://discourse.pymc.io/u/jbuddy_13)\
**Post date:** [December 13, 2020, 2:54pm UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418/3 "2020-12-13T14:54:18Z")

</div>

To your question, any sort of [combinatorial optimization](https://en.wikipedia.org/wiki/Combinatorial_optimization#:~:text=Some%20common%20problems%20involving%20combinatorial%20optimization%20are%20the,operations%20research%2C%20algorithm%20theory%2C%20and%20computational%20complexity%20theory.) problem is high impact for most businesses, especially as it relates to logistics. Skip down to “Specific Problems” for a quick glance at what this looks like.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [December 14, 2020, 6:46am UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418/4 "2020-12-14T06:46:22Z")

</div>

I see, so it is mostly discrete models right? I think those would be indeed very useful as currently inference on discrete model is pretty limited.

---

<div class="post-metadata">

**Author:** ![andyfaff](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/andyfaff/32/1684_2.png) [@andyfaff](https://discourse.pymc.io/u/andyfaff)\
**Post date:** [December 17, 2020, 8:06pm UTC](https://discourse.pymc.io/t/simulated-annealing-equivalent-in-pymc3/6418/5 "2020-12-17T20:06:15Z")

</div>

There is a [dual\_annealing](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.dual_annealing.html) function in scipy now.
