Browse Source

Add Correlation matrix to ObjectiveModel.

arrays
diluculo 8 years ago
parent
commit
99abb36a88
  1. 15
      src/Numerics/Optimization/IObjectiveModel.cs
  2. 16
      src/Numerics/Optimization/ObjectiveModels/FittingObjectiveModel.cs

15
src/Numerics/Optimization/IObjectiveModel.cs

@ -6,6 +6,16 @@ namespace MathNet.Numerics.Optimization
{
IObjectiveModel CreateNew();
/// <summary>
/// Get the y-values of the observations.
/// </summary>
Vector<double> ObservedY { get; }
/// <summary>
/// Get the values of the weights for the observations.
/// </summary>
Matrix<double> Weights { get; }
/// <summary>
/// Get the y-values of the fitted model that correspond to the independent values.
/// </summary>
@ -38,6 +48,11 @@ namespace MathNet.Numerics.Optimization
/// </summary>
Matrix<double> Covariance { get; }
/// <summary>
/// Get the correlation matrix.
/// </summary>
Matrix<double> Correlation { get; }
/// <summary>
/// Get the number of calls to function.
/// </summary>

16
src/Numerics/Optimization/ObjectiveModels/FittingObjectiveModel.cs

@ -123,6 +123,11 @@ namespace MathNet.Numerics.Optimization.ObjectiveModels
/// </summary>
public Matrix<double> Covariance { get; private set; }
/// <summary>
/// Get the correlation matrix.
/// </summary>
public Matrix<double> Correlation { get; private set; }
/// <summary>
/// Get the number of calls to function.
/// </summary>
@ -484,18 +489,23 @@ namespace MathNet.Numerics.Optimization.ObjectiveModels
EvaluateFunction(Pext);
EvaluateJacobian(Pext);
// restore isBounded
this.IsBounded = (LowerBound != null || UpperBound != null);
if (Hessian == null || Residuals == null || DegreeOfFreedom < 1)
{
Covariance = null;
Correlation = null;
return;
}
var covariance = Hessian.PseudoInverse() * Residuals.DotProduct(Residuals) / DegreeOfFreedom;
Covariance = covariance;
// restore isBounded
this.IsBounded = (LowerBound != null || UpperBound != null);
var correlation = covariance.Clone();
var d = correlation.Diagonal().PointwiseSqrt();
var dd = d.OuterProduct(d);
Correlation = correlation.PointwiseDivide(dd);
return;
}

Loading…
Cancel
Save