In [ ]:
import astropy.units as u
import astropy.coordinates as coord
import numpy as np
from numpy.polynomial.polynomial import polyval
import matplotlib.pyplot as pl
pl.style.use('apw-notebook')
%matplotlib inline
import h5py
from scipy.ndimage import gaussian_filter
from scipy.stats import scoreatpercentile
from astroML.density_estimation import XDGMM
from astroML.utils import log_multivariate_gaussian
from astroML.plotting.tools import draw_ellipse
from scipy.misc import logsumexp
In [ ]:
XCov_filename = "/Users/adrian/projects/globber/data/ngc5897/XCov_med.h5"
In [ ]:
with h5py.File(XCov_filename, "r") as f:
cluster_X = f['cluster']['X'][:]
cluster_Cov = f['cluster']['Cov'][:]
In [ ]:
cluster_X.shape
In [ ]:
clf = XDGMM(n_components=16, verbose=True, n_iter=128)
In [ ]:
clf.fit(cluster_X, cluster_Cov)
In [ ]:
sample_X = clf.sample(size=4096)
In [ ]:
fig,axes = pl.subplots(1,3,figsize=(12,6),sharex=True,sharey=True)
axes[0].plot(cluster_X[:,1], cluster_X[:,0], ls='none', alpha=0.5)
axes[1].plot(sample_X[:,1], sample_X[:,0], ls='none', alpha=0.5)
for i in range(clf.n_components):
draw_ellipse(clf.mu[i,:2][::-1], clf.V[i,:2,:2][::-1,::-1], scales=[2],
ec='k', fc='gray', alpha=0.2, ax=axes[2])
pl.xlim(0,0.7)
pl.ylim(22,14)
In [ ]:
import pickle
In [ ]:
with open("/Users/adrian/projects/globber/data/ngc5897/xd_trained.pickle", 'wb') as f:
pickle.dump(clf, f)
In [ ]:
logprob = clf.logprob_a(cluster_X, cluster_Cov)
In [ ]:
logprob.shape
In [ ]:
logsumexp(self.logprob_a(X, Xerr), -1)