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(); 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> /// <summary>
/// Get the y-values of the fitted model that correspond to the independent values. /// Get the y-values of the fitted model that correspond to the independent values.
/// </summary> /// </summary>
@ -38,6 +48,11 @@ namespace MathNet.Numerics.Optimization
/// </summary> /// </summary>
Matrix<double> Covariance { get; } Matrix<double> Covariance { get; }
/// <summary>
/// Get the correlation matrix.
/// </summary>
Matrix<double> Correlation { get; }
/// <summary> /// <summary>
/// Get the number of calls to function. /// Get the number of calls to function.
/// </summary> /// </summary>

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

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

Loading…
Cancel
Save