Docsity

Approcci numerici per l'integrazione: metodo Monte Carlo e metodo Hit and Miss, Appunti di Matematica Computazionale

Anteprima parziale del testo

Scarica Approcci numerici per l'integrazione: metodo Monte Carlo e metodo Hit and Miss e più Appunti in PDF di Matematica Computazionale solo su Docsity!

  • Professor Ioannis Ntzoufras Department of StatisticsAthens University of Economics & Business Computational StatisticsMarch
    • 1 / 168I. Ntzoufras, AUEB
    • 2 / 168I. Ntzoufras, AUEB
  • Computational StatisticsPart B:Monte Carlo IntegrationMarch

Computer intensive methods for integrationHere we will deal with

Monte Carlo Integration Which is based on simulation that we have thoroughly seen inthe first part of the courseNevertheless, we will also make a short tour in numericalmethods in order to have an understanding of the mainalternative and why at the end MC integration is a goodalternative (and finally very popular in Statistics).

I. Ntzoufras, AUEB 2021^ 4 / 168

Introduction to IntegrationThe problem:^ Consider a one-dimensional integral of the form

௕ 𝑓 𝑥 𝑑𝑥׬ (^) ௔ For only a few functions,

f^ , can the value of the integral be derived analytically. For the rest, numerical approximations of the integral can be usedExamples of integration in statistics: Likelihood based inference: when the likelihood itself is afunction of one or more integralsExamples: Factor Analysis and Random effects models Bayesian inference: is solely based on integrals inhabited inposterior moments (e.g. mean or variance) which typically cannotbe evaluated analytically.

I. Ntzoufras, AUEB 2021^ 5 / 168

-4^ -^

x

Approach 1: Numerical Integration0.7 * exp(-x^2) + 0.3 * exp(-(x - 4)^2/3)

మమ^ ௫ ௫ିସ^ /ଷ 𝑓 𝑥 ൌ 0.7𝑒ି ൅ 0.3𝑒ି^ I. Ntzoufras, AUEB 2021^ 7 / 168

-4^ -^

x

Approach 1: Numerical Integrationmyfunction(x)

଺ି න 𝑓 𝑥 𝑑𝑥ଶ I. Ntzoufras, AUEB 2021^ 8 / 168

-4^ -^

x

Approach 1: Numerical Integration0.7 * exp(-x^2) + 0.3 * exp(-(x - 4)^2/3)

Intervals of length 0.5K=16 intervals I. Ntzoufras, AUEB 2021^ 10 / 168

-4^ -^

x

Approach 1: Numerical Integration0.7 * exp(-x^2) + 0.3 * exp(-(x - 4)^2/3)

Intervals of length 0.2K=40 intervals I. Ntzoufras, AUEB 2021^ 11 / 168

-4^ -^

x

Approach 1: Numerical Integrationmyfunction(x)

Intervals of length 0.1K=80 intervalsNo borders! I. Ntzoufras, AUEB 2021^ 13 / 168

Two approaches to approximating integralsApproach 1: Numerical IntegrationA Simple Algorithm^ Partition the interval

[a, b]^ into^ K^ sub-intervals,

[x, x]^ for kk+ k =0, 2, ..., K-1^ with

x= a^ and^ x= b.^0 K^ Calculate the mid-point

௠௜ௗ^ of each interval௞

[x, x] bykk+ ௠௜ௗ^ =^ (x+x)/2 ௞ k+1^ k Calculate the integral as The larger is^ K^ (the number of intervals) the more accurate isthe calculation (but with increased computational time)

I. Ntzoufras, AUEB 2021^ 14 / 168

Approach 1: Numerical Integration

I. Ntzoufras, AUEB 2021^ 16 / 168

devtools::install_github("jabiru/tictoc")library(tictoc)for (j in 1:7){step <‐ 10^(‐j)x<‐seq(a,b,step)K<‐length(x)‐1x1<‐x[1:(K‐1)]x2<‐x[2:K]xmid <‐ (x1+x2)/2Dx<‐ x2‐x1f <‐ myfunction(xmid)tic()res <‐ sum(f*Dx)toc()print(c(j, step, res))}

‐k K=1‐7 step= Integral

Two approaches to approximating integralsApproach 2: Monte Carlo Integration^ To approximate

μ= E(X)^ =^

, we can obtain an i.i.d. random sample^ X

,... , X from^ f^ and then approximate n^1

μ^ via

the sample average:

௡^ ௜ ௜ୀଵ These approaches are useful in many contexts, but moresophisticated approaches are often necessary.

I. Ntzoufras, AUEB 2021^ 17 / 168

Numerical Methods: The general approachThe integral is calculated byThe method I demonstrated considers

m=2 , ∗ ∗ ௠௜ௗ∗^ 𝑥ൌ x , 𝑥ൌ 𝑥,^ 𝑥= x ௞଴ k ௞ଵ௞௞ଶ k+1 and A=0, A=(x–x) and A=0.k0k1kk-1k Hence

I. Ntzoufras, AUEB 2021^ 19 / 168

Newton-Cotes quadrature methodCharacteristics^ Equally spaced nodes in each sub-interval^ Same number of nodes in each sub-interval^ Use polynomials of of m-th degree of the type^ to interpolate between nodes^ Also set^ A=^ kj

௫ೖశభ௜௝௫ೖ

I. Ntzoufras, AUEB 2021^ 20 / 168