Calculates the contours of a two dimensional normal distribution of a desired amount of probability. The idea is to transform the ellipse to a circle and calculate the integral of the PDF, set it equal to a quantile and tranform it back. The main steps are as follows:
Get a dictionary containing semi-major axis, semi-minor axis and the angle of the ellipse w.r.t to the major axis from example_ellipse_prop.py by the arguments of confidence as list and covariance matrix of your probability distribution function.
from numpy.random import randint
from numpy import dot, array
# A random covariance matrix
off_diag = randint(10)
a, b = randint(1, 10), randint(1, 10)
A = array([
[a, off_diag],
[off_diag, b]
])
cov = dot(A, A.T)
cov
can now be used in make_ellipse_parameter_dict
:
from contourlevels import make_ellipse_parameter_dict
confidence_regions = [.5,.9,.99] # Your desired confidence regions
ell_props = make_ellipse_parameter_dict(cov, confidence_regions)
The variable cov
can be manipulated to any desired covariance matrix as long the mathmatical necessities are full filled.
For a single ellipse use get_ellipse_props(cov, confidence)
.
cov = # Your covariance matrix
confidence = 0.5
major_axis, minor_axis, angle = get_ellipse_props(cov, confidence)