plots anisotropic full grids that form part of the combination technique

from argparse import ArgumentParser
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import pysgpp
from pysgpp.pysgpp_swig import DataVector, CombigridOperation
from pysgpp.extensions.datadriven.uq.dists import J, Beta, Uniform, Normal
from pysgpp.extensions.datadriven.uq.plot.colors import load_color, savefig,\
from pysgpp.extensions.datadriven.uq.plot.plot2d import plotDensity2d
def g(x):
return[4 * xi * (1 - xi) for xi in x.array()])
# We have to wrap f in a pysgpp.MultiFunction object.
func = pysgpp.multiFunc(g)
numDims = 2
if __name__ == "__main__":
# parse the input arguments
parser = ArgumentParser(description='Get a program and run it with input', version='%(prog)s 1.0')
parser.add_argument('--level', default=2, type=int, help="minimum level of regular grids")
parser.add_argument('--marginalType', default="beta", type=str, help="marginals")
args = parser.parse_args()
if args.marginalType == "uniform":
marginal = Uniform(0, 1)
elif args.marginalType == "beta":
marginal = Beta(5, 10)
marginal = Normal(0.5, 0.1, 0, 1)
# plot pdf
dist = J([marginal] * numDims)
fig = plt.figure()
savefig(fig, "/tmp/%s" % (args.marginalType,))
w = pysgpp.singleFunc(marginal.pdf)
grids = pysgpp.AbstractPointHierarchyVector()
evaluators = pysgpp.FloatScalarAbstractLinearEvaluatorVector()
# To create a CombigridOperation object with our own configuration, we have to provide a
# LevelManager as well:
levelManager = pysgpp.WeightedRatioLevelManager()
operation = pysgpp.CombigridOperation(grids, evaluators, levelManager, func)
# We can add regular levels like before:
# We can also fetch the used grid points and plot the grid:
grid = levelManager.getGridPointMatrix()
gridList = [[grid.get(r, c) for c in range(grid.getNcols())] for r in range(grid.getNrows())]
fig = plt.figure()
plt.plot(gridList[0], gridList[1], " ",
marker='o', markersize=10)
currentAxis = plt.gca()
currentAxis.add_patch(Rectangle((0, 0), 1, 1, fill=None, alpha=1, linewidth=2))
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.title(r"Sparse Grid $\ell=%i$" % args.level,
savefig(fig, "/tmp/sparse_grid_l%i_%s" % (args.level, args.marginalType))