## Author: Júlio Hoffimann Mendes import numpy as np import pylab as pl from pyhum.decomposition import KernelPCA # make sure results are reproducible np.random.seed(2014) # load ensemble from disk (nfeatures x nsamples) X = np.loadtxt("ensemble.csv", delimiter=",", skiprows=1, usecols=xrange(100)) fig = pl.figure() for d in xrange(1, 5): kpca = KernelPCA(degree=d) ncomps = kpca.train(X, ncomps=50) img = kpca.predict(np.ones(ncomps)) denoised = kpca.denoise(img) pl.subplot(2, 4, d) pl.title("d = %i" % d) pl.imshow(img.reshape(250, 250), cmap="PuBu") pl.axis("off") pl.subplot(2, 4, d + 4) pl.imshow(denoised.reshape(250, 250), cmap="PuBu") pl.axis("off") fig.tight_layout(h_pad=0.5, w_pad=0.5) bbox_props = dict(boxstyle="rarrow,pad=0.3", fc="white", ec="b", lw=2)
# only 44550 of 60048 cells are active mask = np.loadtxt("null.inc", dtype=bool, skiprows=2) X = X[mask, :] pool.wait() # evaluate forward operator on prior ensemble and save results if pool.is_master(): D = np.array(pool.map(G, [m for m in X.T])).T np.savetxt("Dprior.dat", D) pool.proceed() # ensemble in feature space (ncomps << nfeatures) kpca = KernelPCA() kpca.train(X, ncomps=ncomps) CSI = kpca.featurize(X) mprior = Nonparametric(CSI.T) # KDE-based proposal def kde_proposal(CSI): return mprior.sample(n_samples=nsamples) from utils import alltimes, history timesteps = [1812, 2421, 3029] # chosen timesteps for Bayesian inference # history-based uncertainty mitigation