# Repeated solution of a parametric rootfinding problem

**URL:** <https://discourse.julialang.org/t/repeated-solution-of-a-parametric-rootfinding-problem/24199>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [May 14, 2019, 8:20am UTC](https://discourse.julialang.org/t/repeated-solution-of-a-parametric-rootfinding-problem/24199 "2019-05-14T08:20:04Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [May 14, 2019, 8:20am UTC](https://discourse.julialang.org/t/repeated-solution-of-a-parametric-rootfinding-problem/24199/1 "2019-05-14T08:20:04Z")

</div>

For a given set of parameters \theta, I am solving

f(x, \theta) \approx 0

numerically for x(\theta), then obtain simulated moments S(x(\theta)) (which is stochastic), minimizing

\min\_x \| S(x(\theta)) - D \|

where D is the data moments.

The most costly step is solving the rootfinding problem in the first equation — I found that of course having a good starting point helps.

I am wondering about the following heuristic solution: maintain a list of (x\_i, \theta\_i) pairs I solved for, and for a new \theta', use the x\_i from the “nearest” \theta\_i, or a convex combination of several nearest ones.

This is the part I need help with: I can of course find the nearest x\_i's numerically, but I am wondering if there is an existing data structure/implementation that would make it easier.

As for the dimensionality of the problem: x, \theta \in \mathbb{R}^7.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [May 14, 2019, 9:34am UTC](https://discourse.julialang.org/t/repeated-solution-of-a-parametric-rootfinding-problem/24199/2 "2019-05-14T09:34:05Z")

</div>

Check [GitHub - KristofferC/NearestNeighbors.jl: High performance nearest neighbor data structures and algorithms for Julia.](https://github.com/KristofferC/NearestNeighbors.jl) for the nearest neighbor bit. If f and S are analytic functions, you can also try throwing the whole thing in a JuMP model and send it to Ipopt to solve for x and \theta simultaneously.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [May 14, 2019, 9:44am UTC](https://discourse.julialang.org/t/repeated-solution-of-a-parametric-rootfinding-problem/24199/3 "2019-05-14T09:44:10Z")

</div>

If a linear interpolation of the function x, theta → f is appropriate, you can also try to reuse that information to help your root solver (eg to seed the jacobian in a quasi Newton algorithm)
