This project has moved and is read-only. For the latest updates, please go here.

Math.Net User Guide

Math.Net Numerics is an open souce .NET library for numerical computation. The library was built by merging the feature sets of the dnAnalytics and Math.Net Iridium projects. In this user guide, we will explore the basic architecture of Math.Net Numerics and give an overview of the features it supports.

Quality Assurance

We aim to make Math.Net a very high quality numerical library; to do so we set a very high standard on fixing bugs fast (generally within 24 to 48 hours). If you run across any issues with the library, please report them to our issue tracker. That being said, our library does not come with any warranty, it is provided "as is". Contact any of the main developers if you have any questions regarding using Math.Net in your project.

Architecture

The Math.Net architecture is illustrated in the diagram below. The core of Math.Net Numerics is a managed front-end API that provides a set of numerical procedures. Documentation for this API can be found TODO here. On top of the front-end API is an F# specific API which introduces a number of methods to help functional programmers use Math.Net.

Architecture.png

Math.Net implements two different kinds of back-ends: a managed and a native backend. Although both the managed and the native backend have functionality implemented in managed code (C# actually), the native backend offers faster implementation of some numerical routines (mostly numerical linear algebra). The native back-ends are implemented in a mix of C, C++ and optimized assembler and hence cannot be used in managed only environments. The currently offered native back-ends are based on the ATLAS/LAPACK implementation and the Intel MKL libraries.

All of the managed code requires .NET 4.0.

Parallelism and Thread Safety

Math.Net uses the parallelism features introduces in .NET 4.0 for improving it's performance. Particularly in the linear algebra classes, there are many operations which are parallelized. To turn off parallelism, one can set Control.DisableParallelization to true. To control the number of threads which Math.Net uses for parallelism one can set Control.NumberOfParallelWorkerThreads . By default the standard Math.Net release uses the number of processors as the number of worker threads whereas the Silverlight version of Math.Net default to to one thread.

Generally, the methods and classes in Math.Net do not perform locking for thread safety. For some classes this can be enabled/disabled. The random number generators are thread safe by default but this can be switched off by setting Control.ThreadSafeRandomNumberGenerators = false;

Feature Overview

Math.Net consists of a number of relatively independent components each in their own namespace. Below we provide a brief introduction to each of the components and provide some code samples to get started.

Distributions

In MathNet.Numerics.Distributions we have various probability distributions. They are divided up into univariate continuous, univariate discrete and multivariate distributions. All the univariate distributions derive from the IDistribution interface whereas the continuous ones derive from IContinuousDistribution and the discrete distributions derive from IDiscreteDistribution . There is no particular class hierarchy for the multivariate distributions: as their domains can be quite different it would be hard to come up with a simple and clean unifying interface.

One has to be very careful when using the distributions. There are many ways to parameterize one distribution in the literature; when using the default constructor, study carefully which parameters it requires. If they do not suite your needs, there will very likely be static method which can construct the distribution for you. E.g. var n = new Normal(0.0, 2.0); constructs a normal distribution with mean 0.0 and standard deviation 2.0. If you'd rather parameterize the normal distribution using a mean and precision, one can use the following code var n = Normal.WithMeanPrecision(0.0,0.25); .

All the distributions implement a basic set of operations such as computing the mean, standard deviation, density, etc. Note that it is often much faster to compute quantities in the log domain; for some quantities (e.g. Density) we implement an equivalent method that does all computations in the log domain (e.g. DensityLn).

Each distribution provides methods to generate random numbers from that distribution. These random variate generators work by accessing the distribution's member RandomSource (which is a subclass of System.Random , see below) to provide uniform random numbers. By default, this member is an instance of System.Random but one can easily replace this with more sophisticated random number generators from MathNet.Numerics.Random. Each distribution class has two static and two class methods: for each pair (static and class), one of them generates a single sample, the other will generate an IEnumerable<T> of samples. The static methods allow random number generation without instantiating the actual class.

Integral Transforms

Integration

Interpolation

Linear Algebra

Number Theory

Under the MathNet.Numerics.NumberTheory namespace we provide methods for arithmetic on different integers types. The integer types are int and long but plans are underway to extend to the BigInteger type from .NET 4.0. Some of the algorithms in here are Euclid's algorithm for computing the greatest common divisor, checking for perfect squares etc.

Random Number Generators

Special Functions

Statistics

Last edited May 6, 2010 at 10:08 AM by cdrnet, version 14

Comments

No comments yet.