Accord.NET Framework

## UnivariateContinuousDistributionFit Method (Double, Int32) |

Fits the underlying distribution to a given set of observations.

Syntax

Request Example
View Source#### Parameters

- observations
- Type: SystemDouble

The array of observations to fit the model against. The array elements can be either of type double (for univariate data) or type double[] (for multivariate data). - weights
- Type: SystemInt32

The weight vector containing the weight for each of the samples.

Remarks

Although both double[] and double[][] arrays are supported,
providing a double[] for a multivariate distribution or a
double[][] for a univariate distribution may have a negative
impact in performance.

Examples

The following example shows how to fit a NormalDistribution using the Fit(Double, Double) method. However, any other kind of distribution could be fit in the exactly same way. Please consider the code below as an example only:

// Let's say we have a UnivariateContinuousDistribution that we have // built somehow, either using a constructor for a common distribution // or that we have received as the output of a method we have called: UnivariateContinuousDistribution dist = new NormalDistribution(); // Let's say we have a set of observations, and some optional weights: double[] observations = { 0.12, 2, 0.52 }; // Note: the weights are optional. You do not need to have different weights // for the different observations you would like to fit, but we will use them // as an example to show that it is also possible to specify them if we would // like to, but we could also set them to null in case we do not need them: double[] weights = { 0.25, 0.25, 0.50 }; // could also be null // Now, we can finally fit the distribution to the observations that we have: dist.Fit(observations, weights); // changes 'dist' to become the dist we need // Now we can verify that the distribution has been updated: double mean = dist.Mean; // should be 0.79 double var = dist.Variance; // should be 0.82352 double stdDev = dist.StandardDeviation; // should be 0.90748002732842559

If you would like futher examples, please take a look at the documentation page for the distribution you would like to fit for more details and configuration options you would like or need to control.

See Also