Click or drag to resize
Accord.NET (logo)

MonteCarloIntegration Class

Monte Carlo method for multi-dimensional integration.
Inheritance Hierarchy
SystemObject
  Accord.Math.IntegrationMonteCarloIntegration

Namespace:  Accord.Math.Integration
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public class MonteCarloIntegration : INumericalIntegration, 
	ICloneable, IMultidimensionalIntegration
Request Example View Source

The MonteCarloIntegration type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyArea
Gets the numerically computed result of the definite integral for the specified function.
Public propertyError
Gets the integration error for the computed Area value.
Public propertyFunction
Gets or sets the multidimensional function whose integral should be computed.
Public propertyIterations
Gets or sets the number of random samples (iterations) generated by the algorithm.
Public propertyNumberOfParameters
Gets the number of parameters expected by the Function to be integrated.
Public propertyRandom
Gets or sets the random generator algorithm to be used within this Monte Carlo method.
Public propertyRange
Gets or sets the range of each input variable under which the integral must be computed.
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
Public methodCompute
Computes the area of the function under the selected Range. The computed value will be available at this object's Area.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberIntegrate(FuncDouble, Double, Double, Double)
Computes the area of the function under the selected Range. The computed value will be available at this object's Area.
Public methodStatic memberIntegrate(FuncDouble, Double, Double, Double, Int32)
Computes the area under the integral for the given function, in the given integration interval, using a Monte Carlo integration algorithm.
Public methodStatic memberIntegrate(FuncDouble, Double, Double, Double, Int32)
Computes the area of the function under the selected Range. The computed value will be available at this object's Area.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReset
Manually resets the previously computed area and error estimates, so the integral can be computed from scratch without reusing previous computations.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

In mathematics, Monte Carlo integration is a technique for numerical integration using random numbers. It is a particular Monte Carlo method that numerically computes a definite integral. While other algorithms usually evaluate the integrand at a regular grid, Monte Carlo randomly choose points at which the integrand is evaluated. This method is particularly useful for higher-dimensional integrals. There are different methods to perform a Monte Carlo integration, such as uniform sampling, stratified sampling and importance sampling.

References:

Examples

A common Monte-Carlo integration example is to compute the value of Pi. This is the same example given in Wikipedia's page for Monte-Carlo Integration, available at https://en.wikipedia.org/wiki/Monte_Carlo_integration#Example

// Define a function H that tells whether two points 
// are inside a unit circle (a circle of radius one):
// 
Func<double, double, double> H = 
    (x, y) => (x * x + y * y <= 1) ? 1 : 0;

// We will check how many points in the square (-1,-1), (-1,+1), 
// (+1, -1), (+1, +1) fall into the circle defined by function H.
// 
double[] from = { -1, -1 };
double[] to   = { +1, +1 };

int samples = 100000;

// Integrate it! 
double area = MonteCarloIntegration.Integrate(x => H(x[0], x[1]), from, to, samples);

// Output should be approximately 3.14.
See Also