Created
June 17, 2020 08:14
-
-
Save saccadic/97ce02ca52bb0bcf38e600aa52f45bc9 to your computer and use it in GitHub Desktop.
2次元の座標群に対する確率楕円を計算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #https://github.com/joferkington/oost_paper_code/blob/master/error_ellipse.py | |
| def confidence_ellipse(x, y, n_std=3.0): | |
| def eigsorted(cov): | |
| vals, vecs = np.linalg.eigh(cov) | |
| order = vals.argsort()[::-1] | |
| return vals[order], vecs[:,order] | |
| xy = (np.mean(x), np.mean(y)) | |
| cov = np.cov(x, y) | |
| vals, vecs = eigsorted(cov) | |
| theta = np.degrees(np.arctan2(*vecs[:,0][::-1])) | |
| width, height = 2 * n_std * np.sqrt(vals) | |
| ellip = (xy[0], xy[1]), width, height, theta | |
| return ellip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment