9

I know FindRoot can solve nonlinear equations, but now I'm interested in solving such an equation using a Monte Carlo method. Can somebody show how that could be done for the equation below?

Exp[-x^3] - Tan[x] + 800 == 0

For convinience:The root is restrained in the interval (0,π/2).

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
keanhy14
  • 469
  • 2
  • 9

1 Answers1

2

Isn't basically just setting the likelihood and sampling x-values?
Let's define f[x]

f[x_] := Exp[-x^3] - Tan[x] + 800;

(Just Solve for comparing with monte-carlo)

NMinimize[{Abs[f[x]], 0 <= x <= Pi/2}, x]

{7.34717*10^-6, {x -> 1.56955}}


Think Distribution of $y=f[x]$.
Delta Method can be used.

joint[x_, y_, sigma_] := 
  PDF[NormalDistribution[f[x], Evaluate@D[f[x], x]*sigma], y];

because here we have $y=0(f[x]=0)$,we can obtain the likelihood $L[x]$

L[x_?NumericQ, sigma_?NumericQ] := Evaluate@joint[x, 0, sigma];

Let's sampling x-values with mathematica-mcmc

Import["https://raw.githubusercontent.com/joshburkart/mathematica-\
mcmc/master/mcmc.m"]

SeedRandom[1234];
mcmc = MCMC[
  L[x, sigma], {{x, 0.01, 0.01, Range[0, Pi/2, 0.01]}, {sigma, 100, 
    100, Range[100, 100000, 100]}}, 10000000]

obtain distribution of x-values

dst = mcmc["ParameterRun"][[;; , 1]] // SmoothKernelDistribution;
Plot[{Evaluate@PDF[dst, x]}, {x, 0, 2}]

Mathematica graphics

MAP estimating

Last@NMaximize[Evaluate@PDF[dst, x], x]

{x -> 1.10409}
Xminer
  • 1
  • 7
  • 15
  • Thanks! Is it convenient to provide some materials (book or article) to understand your code? – keanhy14 Dec 27 '19 at 01:46
  • I'd like to recommend course slides(generative models,1~4) of "Machine Learning for Engineers" – Xminer Dec 27 '19 at 03:01
  • Isn't the problem with the accuracy explained by the large derivative at or near the minimum/root, which is next to the asymptote of f[x]? – Michael E2 Dec 27 '19 at 15:04
  • @MichaelE2 At First,I felt that there was a problem with accuracy because the convergence destination differs depending on the given initial interval. However, it doesn't seem to make much difference for MAP estimation if given sample is enoguh. So I corrected the article. – Xminer Dec 28 '19 at 08:49