confidence_ellipse_matrix

qctrlvisualizer.confidence_ellipse_matrix(hessian, cost, measurement_count, confidence_fraction=0.95)

Calculate a matrix that you can use to represent the confidence region of parameters that you estimated. Pass to this function the Hessian of the residual sum of squares with respect to the parameters, and use the output matrix to transform a hypersphere into a hyperellipse representing the confidence region. You can then plot this hyperellipse to visualize the confidence region using the plot_confidence_ellipses function.

Alternatively, you can apply a (2,2)-slice of the transformation matrix to a unit circle to visualize the confidence ellipse for a pair of estimated parameters.

Parameters:
  • hessian (np.ndarray) – The Hessian of the residual sum of squares cost with respect to the estimated parameters, \(H\). Must be a square matrix.

  • cost (float) – The residual sum of squares of the measurements with respect to the actual measurements, \(C_\mathrm{RSS}\). Must be positive.

  • measurement_count (int) – The number of measured data points, \(n\). Must be positive.

  • confidence_fraction (float, optional) – The confidence fraction for the ellipse, \(\alpha\). If provided, must be between 0 and 1. Defaults to 0.95.

Returns:

A \((p, p)\)-matrix which transforms a unit hypersphere in a p-dimensional space into a hyperellipse representing the confidence region for the confidence fraction \(\alpha\). Here \(p\) is the dimension of the Hessian matrix.

Return type:

np.ndarray

Notes

From the Hessian matrix of the residual sum of squares with respect to the estimated parameters \(\{\lambda_i\}\),

\[H_{ij} = \frac{\partial^2 C_\mathrm{RSS}}{\partial \lambda_i \partial \lambda_j} ,\]

we can estimate the covariance matrix for the estimated parameters

\[\Sigma = \left( \frac{n-p}{2 C_\mathrm{RSS}} H \right)^{-1} .\]

Finally, we can find a scaling factor \(z\), such that the matrix \(z \Sigma^{1/2}\) transforms the coordinates of a unit hypersphere in a p-dimensional space into a hyperellipse representing the confidence region

\[z = \sqrt{p F_{1-\alpha} \left( \frac{n-p}{2}, \frac{p}{2} \right)} ,\]

where \(F_{1-\alpha}(a,b)\) is the point of the F-distribution where the probability in the tail is equal to \(F_{1-\alpha}(a,b)\).

For more details, see the topic Characterizing your hardware using system identification in Boulder Opal and N. R. Draper and I. Guttman, The Statistician 44, 399 (1995).