MCPcopy Create free account
hub / github.com/PythonOT/POT / draw_cov

Function draw_cov

examples/gaussian_gmm/plot_GMM_flow.py:57–79  ·  view source on GitHub ↗
(mu, C, color=None, label=None, nstd=1, alpha=0.5)

Source from the content-addressed store, hash-verified

55
56
57def draw_cov(mu, C, color=None, label=None, nstd=1, alpha=0.5):
58 def eigsorted(cov):
59 if torch.is_tensor(cov):
60 cov = cov.detach().numpy()
61 vals, vecs = np.linalg.eigh(cov)
62 order = vals.argsort()[::-1].copy()
63 return vals[order], vecs[:, order]
64
65 vals, vecs = eigsorted(C)
66 theta = np.degrees(np.arctan2(*vecs[:, 0][::-1]))
67 w, h = 2 * nstd * np.sqrt(vals)
68 ell = Ellipse(
69 xy=(mu[0], mu[1]),
70 width=w,
71 height=h,
72 alpha=alpha,
73 angle=theta,
74 facecolor=color,
75 edgecolor=color,
76 label=label,
77 fill=True,
78 )
79 pl.gca().add_artist(ell)
80
81
82def draw_gmm(ms, Cs, ws, color=None, nstd=0.5, alpha=1):

Callers 1

draw_gmmFunction · 0.70

Calls 2

eigsortedFunction · 0.70
sqrtMethod · 0.45

Tested by

no test coverage detected