# 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$**cost**(*float*) – The residual sum of squares of the measurements with respect to the actual measurements, $C_\mathrm{RSS}$**measurement_count**(*int*) – The number of measured data points, $n$**confidence_fraction**(*float**,**optional*) – The confidence fraction for the ellipse, $\alpha$

### 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$

### 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}$

$z = \sqrt{p F_{1-\alpha} \left( \frac{n-p}{2}, \frac{p}{2} \right)} ,$where $F_{1-\alpha}(a,b)$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).