Skip to content

Commit 4d573eb

Browse files
committed
Added additional outputs to the running covariance matrix, uncertainty analysis results. Minor improvements to numerical derivative hessian and step size calculation. Refactored the vegas class to use better variable names. Improved the MCMC diagnostics class.
1 parent 8311b55 commit 4d573eb

34 files changed

Lines changed: 1637 additions & 1046 deletions

File tree

4.8.1/Numerics/Data/Statistics/RunningCovarianceMatrix.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
using System;
3333
using System.Collections.Generic;
3434
using System.Linq;
35+
using System.Reflection;
36+
using System.Runtime.Remoting.Messaging;
3537

3638
namespace Numerics.Data.Statistics
3739
{
@@ -74,6 +76,44 @@ public RunningCovarianceMatrix(int size)
7476
/// </summary>
7577
public Matrix Covariance { get; private set; }
7678

79+
/// <summary>
80+
/// The sample covariance matrix corrected by the sample size with the degrees of freedom adjustment.
81+
/// </summary>
82+
public Matrix SampleCovariance => (1d / (N - 1)) * Covariance;
83+
84+
/// <summary>
85+
/// The population covariance matrix corrected by the total sample size.
86+
/// </summary>
87+
public Matrix PopulationCovariance => (1d / N) * Covariance;
88+
89+
/// <summary>
90+
/// The sample correlation matrix.
91+
/// </summary>
92+
public Matrix SampleCorrelation
93+
{
94+
get
95+
{
96+
var D = Matrix.Diagonal(SampleCovariance);
97+
D.Sqrt();
98+
var invSqrtD = !D;
99+
return (invSqrtD * SampleCovariance) * invSqrtD;
100+
}
101+
}
102+
103+
/// <summary>
104+
/// The population correlation matrix.
105+
/// </summary>
106+
public Matrix PopulationCorrelation
107+
{
108+
get
109+
{
110+
var D = Matrix.Diagonal(PopulationCovariance);
111+
D.Sqrt();
112+
var invSqrtD = !D;
113+
return (invSqrtD * PopulationCovariance) * invSqrtD;
114+
}
115+
}
116+
77117
/// <summary>
78118
/// Add a new vector to the running statistics.
79119
/// </summary>

4.8.1/Numerics/Data/Time Series/Support/Series.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ object IList.this[int index]
116116
/// <inheritdoc/>
117117
public virtual void Add(SeriesOrdinate<TIndex, TValue> item)
118118
{
119+
if (item == null)
120+
throw new ArgumentNullException(nameof(item));
121+
119122
_seriesOrdinates.Add(item);
120123
if (SuppressCollectionChanged == false) { CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, _seriesOrdinates.Count - 1)); }
121124
}
@@ -132,6 +135,9 @@ public int Add(object item)
132135
/// <inheritdoc/>
133136
public virtual void Insert(int index, SeriesOrdinate<TIndex, TValue> item)
134137
{
138+
if (item == null)
139+
throw new ArgumentNullException(nameof(item));
140+
135141
_seriesOrdinates.Insert(index, item);
136142
if (SuppressCollectionChanged == false) { CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); }
137143
}

4.8.1/Numerics/Data/Time Series/Support/SeriesOrdinate.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ public virtual TValue Value
116116
/// <returns>True of the two SeriesOrdinate objects are equal and false otherwise.</returns>
117117
public static bool operator ==(SeriesOrdinate<TIndex, TValue> left, SeriesOrdinate<TIndex, TValue> right)
118118
{
119-
if (object.Equals(left, right) == false) { return false; }
120-
if (!EqualityComparer<TIndex>.Default.Equals(left.Index, right.Index)) { return false; }
121-
if (!EqualityComparer<TValue>.Default.Equals(left.Value, right.Value)) { return false; }
122-
return true;
119+
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
120+
return true;
121+
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
122+
return false;
123+
return EqualityComparer<TIndex>.Default.Equals(left.Index, right.Index) &&
124+
EqualityComparer<TValue>.Default.Equals(left.Value, right.Value);
123125
}
124126

125127
/// <summary>

0 commit comments

Comments
 (0)