3
$\begingroup$

I'm trying to calculate first passage time distribution for some processes in Mathematica. First I tried to calculate this for Wiener process with zero drift and $\sigma = 1$ and the absorbing boundary at $a = 2%$. It's the well-known formula (Levy-Smirnov distribution) $${f_{FP}} = \frac{a}{{\sqrt {2\pi {\sigma ^2}{t^3}} }}{e^{ - \frac{{{a^2}}}{{2{\sigma ^2}t}}}}$$

I used this code

sample = Map[FirstCase[#, _?(Last[#] >= 2 &)] &, 
   RandomFunction[WienerProcess[0, 1], {0, 15, 0.001}, 10^4][
    "Paths"]];
data0 = DeleteCases[sample, {}][[All, 1]];
data = Cases[data0, _?Positive];
Show[Histogram[data, 40, "PDF"], 
 Plot[2/Sqrt[2*\[Pi]*t^3]*Exp[-(2^2/(2*t))], {t, 0, 15}, 
  PlotStyle -> Thick]]

but the result was strange enter image description here

I haven't got any idea why the simplest case failed. Could someone help me with this? Thanks in advance

P.S. I'm sorry for terrible English

$\endgroup$
2
  • 1
    $\begingroup$ FYI: InverseGammaDistribution[] is built-in, so you can do PDF[InverseGammaDistribution[1/2, a^2/(2 σ^2)], x]. $\endgroup$ Commented Oct 1, 2017 at 18:19
  • $\begingroup$ Yes, but I want to understand, why the numeric results don't agree with exact formula, because I'm going to calculate FPT for non-Markovian process (and there is no exact formula). $\endgroup$
    – Msdos4
    Commented Oct 1, 2017 at 18:24

1 Answer 1

5
$\begingroup$

Perhaps you were expecting this:

pdf = 2/Sqrt[2*π*t^3]*Exp[-(2^2/(2*t))];
normalization = NIntegrate[pdf, {t, 0, 15}];
Show[Histogram[data, 40, "PDF"], 
 Plot[pdf/normalization, {t, 0, 15}, PlotStyle -> Thick]]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ The function being plotted here is effectively PDF[TruncatedDistribution[{0, 15}, InverseGammaDistribution[1/2, 2]], t]; that is, the expected heavy tail distribution with a good amount of the tail cut off. $\endgroup$ Commented Oct 1, 2017 at 19:58
  • $\begingroup$ Thank you, I didn't think about normalization. But are there ways to normalize data (histogram), not function? $\endgroup$
    – Msdos4
    Commented Oct 1, 2017 at 20:31
  • 2
    $\begingroup$ @Msdos4 Yes, the third argument of Histogram, where you have "PDF", can take an arbitrary function. See the documentation "Details" section of Histogram. $\endgroup$
    – Michael E2
    Commented Oct 1, 2017 at 21:13
  • $\begingroup$ Thank you once again! Sorry for stupid questions, I'm not good in Mathematica but I want to learn. $\endgroup$
    – Msdos4
    Commented Oct 1, 2017 at 21:18
  • $\begingroup$ @Msdos4 You're welcome. :) $\endgroup$
    – Michael E2
    Commented Oct 1, 2017 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.