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,\
load_font_properties
from pysgpp.extensions.datadriven.uq.plot.plot2d import plotDensity2d
return np.prod([4 * xi * (1 - xi) for xi in x.array()])
func = pysgpp.multiFunc(g)
numDims = 2
if __name__ == "__main__":
parser = ArgumentParser(description='Get a program and run it with input')
parser.add_argument('--version', action='version', 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)
else:
marginal = Normal(0.5, 0.1, 0, 1)
dist = J([marginal] * numDims)
fig = plt.figure()
savefig(fig,
"/tmp/%s" % (args.marginalType,))
plt.close(fig)
w = pysgpp.singleFunc(marginal.pdf)
grids = pysgpp.AbstractPointHierarchyVector()
grids.push_back(pysgpp.CombiHierarchies.linearLeja(w))
grids.push_back(pysgpp.CombiHierarchies.linearLeja(w))
evaluators = pysgpp.FloatScalarAbstractLinearEvaluatorVector()
evaluators.push_back(pysgpp.CombiEvaluators.polynomialInterpolation())
evaluators.push_back(pysgpp.CombiEvaluators.polynomialInterpolation())
levelManager = pysgpp.WeightedRatioLevelManager()
operation = pysgpp.CombigridOperation(grids, evaluators, levelManager, func)
levelManager.addRegularLevels(args.level)
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)
plt.axis('off')
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))