VeereshKulli / accord

Automatically exported from code.google.com/p/accord
0 stars 0 forks source link

Bug: NullReferenceException in Mixture.cs #73

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In your Mixture.cs file. If the first question I ask is what is the 
StandardDeviation for the distribution, the StandardDeviation doesn't contain a 
value yet so it will calculated it by taking the Sqrt(Variance).

However, the Variance doesn't exist yet so it calculates by the following:
        public override double Variance
        {
            get
            {
                if (variance == null)
                {
                    double var = 0.0;
                    for (int i = 0; i < coefficients.Length; i++)
                    {
                        double w = coefficients[i];
                        double m = components[i].Mean;
                        double v = components[i].Variance;
                        var += w * (v + m * m);
                    }

                    variance = var - mean * mean;
                }

                return variance.Value;
            }
        }

However! The mean is currently NULL because the mean hasn't been calculated 
yet, thus a NULL reference exception.

This line of code
                    variance = var - mean * mean;
Should read:
                    variance = var - Mean * Mean;

Thus allowing the mean to calculated if needed.

I suspect that bug is in other distributions as well.

Original issue reported on code.google.com by Tristen....@gmail.com on 21 Sep 2013 at 8:08

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks! Changes have been added to the project's development branch on GitHub:

https://github.com/accord-net/framework/commit/4dfa3da9a28ce3474019d09b2602892ef
e04dff3

Original comment by cesarso...@gmail.com on 4 Oct 2013 at 1:36

GoogleCodeExporter commented 8 years ago
Fixed in the 2.11 release.

Original comment by cesarso...@gmail.com on 27 Oct 2013 at 4:53