def pca_reconstruction(x, basis, xmean=None):
    """Map x in the PCA space back to the original space using the basis and
    mean of the PCA mapping."""
    xrec = x.dot(basis.T)
    if xmean is not None:
        xrec += xmean
    return xrec