numerical-methods-montecarlointegrati
on-exercise
In this exercise, you should implement classes that provide a reasonably flexible
framework for Monte-Carlo integration.
The framework should be flexible enough to allow
• integration of different functions f : Rn → R
• flexible specification of the integration domains using a transformation from
[0,1]n to a subset of Rn
• flexible use for different random number generators
For convenience, we provide the interfaces that define the framework. You can find
these interfaces in the package
info.quantlab.numericalmethods.lecture.montecarlo.integration
Interfaces (provided)
• Integrand
• IntegrationDomain
• Integrator
• MonteCarloIntegratorFactory
The MonteCarloIntegratorFactory's method requires a class implementing
a RandomNumberGenerator. This interface and some classes implementing this interface can
be found in the package
info.quantlab.numericalmethods.lecture.randomnumbers
Integrand and IntegrationDomain
• Objects implementing Integrand provide a function f : A
ightarrow R defined on a domain
A.
• Objects implementing IntegrationDomain provide a bijective function g : [0,1]^{n}
ightarrow
A that transforms the integration domain and the determinant of the derivative (Jacobi matrix)
dg/dx.
• Objects implementing Integrator provide the integral int_A f(z) dz using substitution z =
f(x).
Classes
You may use the classes providing random number generators that will be or were
developed during the lecture, e.g.,
• RandomNumberGeneratorFrom1D
• MersenneTwister
Task
The exercise consists of two separate tasks.
Task 1: A MonteCarloIntegrator
To complete your task:
•
i. Implement a class implementing the interface Integrator that performs a general
Monte-Carlo integration of arbitrary functions on general domains.
The function to integrate will be provided to the integrator's method integrate as an
object implementing the interface Integrand.
The integration domain will be provided to the integrator's method integrate as an
object implementing the interface IntegrationDomain.
•
ii. Implement a class implementing the interface MonteCarloIntegratorFactory that
allows creating an object of the class that you have implemented in 1). Note:
the MonteCarloIntegratorFactory simply calls the constructor of your class.
•
ii. To allow us to test you implementation, complete the implementation of the
method getMonteCarloIntegratorFactory of MonteCarloIntegrationAssignmentSolutio
n. This allows the creation of an object of your MonteCarloIntegratorFactory. Our unit
tests will use this to test your code.
•
ii. Feel free to create your own UnitTests and JavaDoc documentation.
Suggestion: you may test your integrator with different random number generators,
e.g. MersenneTwister via
final long seed = 3141;
RandomNumberGenerator randomNumberGenerator = new RandomNumberGeneratorFrom1D(new
MersenneTwister(seed), domain.getDimension());
or a HaltonSequence.
Task 2: Using your MonteCarloIntegrator to calculate the integral
of a DoubleBinaryFunction
•
v. Complete the method getIntegral of MonteCarloIntegrationAssignmentSolution. Use
your Monte-Carlo integrator with approximately 1 million sample points to calculate
the integral.
Tasks 3: Implement a SimpsonsIntegrator for the general
Simpson's rule in d dimension
To complete your task:
•
vi. Implement a class implementing the interface Integrator that performs a general
(composite) Simpson's rule integration in d dimension of arbitrary functions on
general domains.
The function to integrate will be provided to the integrator's method integrate as an
object implementing the interface Integrand.
The integration domain will be provided to the integrator's method integrate as an
object implementing the interface IntegrationDomain.
•
vii. Implement a class implementing the interface IntegratorFactory that allows creating
an object of the class that you have implemented in 1). Note:
the IntegratorFactory simply calls the constructor of your class.
•
vii. To allow us to test you implementation, complete the implementation of the
method getSimpsonsIntegratorFactory of MonteCarloIntegrationAssignment. This
allows the creation of an object of your IntegratorFactory. Our unit tests will use this
to test your code.
•
vii. Feel free to create your own UnitTests and JavaDoc documentation.
Hints
• Note that your Simpsons integral and your Monte-Carlo integral only operator
on [0,1]^d (the object implementing the Domain will provide you with the
transformation).
• Your Simpsons integrator should accept the numberOfValuationPoints as an
argument. This should be the minimum total number of valuation points. Since
the Simpsons rule uses an odd number of points in every dimension, you may
use the following code to round this number appropriately
to numberOfSamplePointsEffective, using numberOfSamplePointsPerDimension per
dimension.
int dimension = integrationDomain.getDimension();
int numberOfValuationPointsPerDimension = 2 * (int)
(Math.ceil(Math.pow(numberOfValuationPoints, 1.0/dimension))/2) + 1;
int numberOfValuationPointsEffective = (int)
Math.pow(numberOfValuationPointsPerDimension, dimension);
• You might realise that you need to think a bit to find a short algorithm to implement the
Simpsons integration in arbitrary dimensions. It is possible to create a fairly short
implementation if you implement a multi-index index - an array of length dimension where
each entry runs from 0 to numberOfSamplePointsPerDimension-1.
Unit Tests
We encourage you to write your own unit tests.
Further Research
This project offers the opportunity to explore Monte-Carlo integration in more detail for
those interested. Here are a few suggestions:
• Explore the dependency on the dimension: Consider the integration of x →
product(i=0,...,d-1) sin(xi) for 0 < xi < π. The value of the integral is 2^d. This is an
d-dimensional integral. For this function, compare the accuracy of Monte-Carlo
integration and Simpsons integration with d = 1, 2, 4, 8 using for example n =
5^8 = 390625 sample points.
• Explore the dependency on the smoothness of the function: Consider the
integration of (x0,x1) → x0
2 + x1
2 < 1.0 ? 1.0 : 0.0 for 0 < xi < 1. The analytic value of
this integral π. For this function, compare the accuracy of Monte-Carlo
integration and Simpsons integration using n = 101^2 = 10201 sample points.
请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 赛诺威盛:大孔径专科化CT领航者
- 网易硬刚腾讯 两大游戏玩家之间的口水仗不断
- 全球“最独特”的一台华为 nova 6 5G 版手机是什么样子的?
- 拼多多抖音淘宝京东,谁是真低价?
- 老杨第一次再度抓握住一瓶水,他由此产生了新的憧憬
- 丰田章男称未来依然需要内燃机 已经启动电动机新项目
- B站更新决策机构名单:共有 29 名掌权管理者,包括陈睿、徐逸、李旎、樊欣等人
- 苹果罕见大降价,华为的压力给到了?
- 三明列东又有房子要拆迁!住这里的人要发了!
- 放大招后,广州又忍不住了…
- 私募积极加仓,百亿股票私募仓位指数创出近八周新高
- 他,传闻中马云最想见的人
- 升级的脉脉,正在以招聘业务铺开商业化版图
- 如何经营一家好企业,需要具备什么要素特点
- 智慧驱动 共创未来| 东芝硬盘创新数据存储技术