예제 #1
0
def getNextTodoPoints(maxPoints, precalculatedValues, dim, gridType, degree,
                      numTimeSteps, gridResolution, normalization, residual,
                      wave_type, distribution, minimum_allowed_height):
    okushiriFunc = okushiri(dim, numTimeSteps, gridResolution, normalization,
                            residual, wave_type, distribution,
                            minimum_allowed_height)
    lb, ub = okushiriFunc.getDomain()
    objFunc = vectorObjFuncSGpp(okushiriFunc)
    pdfs = objFunc.getDistributions()
    reSurf = pysgpp.SplineResponseSurfaceVector(
        objFunc, pysgpp.DataVector(lb), pysgpp.DataVector(ub),
        pysgpp.Grid.stringToGridType(gridType), degree)
    reSurf.regular(initialLevel)
    todoPointsDetermined = False
    counter = 0

    while not todoPointsDetermined:
        previousSize = reSurf.getSize()
        if previousSize > maxPoints:
            print(
                f"nothing to calculate for a maximum of {maxPoints} grid points"
            )
            return todoPointsDetermined, [], reSurf.getSize()

        reSurf.nextSurplusAdaptiveGrid(numRefine, verbose)
        #reSurf.nextDistributionAdaptiveGrid(numRefine, pdfs, verbose)
        todoPointsDetermined, todoPoints = checkPrecalc(
            reSurf, precalculatedValues)
        if not todoPointsDetermined:
            counter = counter + 1
            print(f"refining ({counter}), grid size: {reSurf.getSize()}")
            reSurf.refineSurplusAdaptive(numRefine, verbose)
            #reSurf.refineDistributionAdaptive(numRefine, pdfs, verbose)
    return todoPointsDetermined, todoPoints, reSurf.getSize()
예제 #2
0
def okushiri_forDakota(v):
    dim = 6  # 3
    gridResolution = 16
    okushiri_func = okushiri(dim,
                             451,
                             gridResolution,
                             normalization=1,
                             residual=0)
    dv = np.array(v)
    result = okushiri_func.eval(dv)
    okushiri_func.cleanUp()
    return result
예제 #3
0
def okushiri_forDakota(v):
    dim = 6  # 3
    gridResolution = 64
    okushiri_func = okushiri(dim,
                             451,
                             gridResolution,
                             normalization=1,
                             residual=0)
    dv = np.array(v)
    result = okushiri_func.eval(dv)
    okushiri_func.cleanUp()
    #print('I deactivated cleanup as there are currently no new calculations')
    return result
예제 #4
0
def do_plot(plot_mean, plot_opt, axis_off=0):
    fig = plt.figure(figsize=(8, 6))
    originalFunc = okushiri(dim, numTimeSteps, gridResolution, normalization=1, residual=1,
                            wave_type='original')
    originalRunup = originalFunc.eval([1]*dim)*400
    originalFunc.cleanUp()

    gs = gridspec.GridSpec(1, 2, width_ratios=[1, 4])
    ax = plt.subplot(gs[0])
    ax2 = plt.subplot(gs[1])

    if plot_mean == 1:
        if plotVar:
            # SD Plots
            # TODO Ich muss hier abs nehmen, das dürfte eigentlich nicht passieren. Var>0!
            lower_sd = means - 0.5 * np.sqrt(np.abs(variances_py))
            upper_sd = means + 0.5 * np.sqrt(np.abs(variances_py))
            ax2.fill_between(time, lower_sd, upper_sd, label='sd', color='r', linewidth=linewidth, alpha=0.5)
            #ax2.plot(time, upper_sd, label='sd', color='r', linewidth=linewidth)
        ax2.plot(time, means, 'C1', label='mean', linewidth=linewidth)
        #ax2.plot(time, dakota_means[-1, :], 'C8', label='Dakota mean', linewidth=linewidth)

    ax2.plot(time, percentiles[0, :], 'C0', label=f"{percentages[0]}th-{percentages[1]}th percentile")
    ax2.plot(time, percentiles[1, :], 'C0')
    ax2.fill_between(time, percentiles[0, :], percentiles[1, :], color='C0', alpha=0.4)

    # ax2.plot(time, mcMeans, 'C4-', label='mc mean', linewidth=linewidth)
    if plot_opt == 1:
        ax2.plot(time, maxTimeline, 'C3', label='max runup', linewidth=linewidth)
        # ax2.plot(time, maxTimeline_dakota, 'C4-', label='Dakota max runup', linewidth=linewidth)

    ax.plot(time, originalRunup, '-', color='grey', linewidth=linewidth)
    ax2.plot(time, originalRunup, '-', color='grey', label='original run-up', linewidth=linewidth)

    ax.set_xlim(0, 1)
    ax2.set_xlim(14, 22.5)
    ax.set_ylim(24, 31.5)
    ax2.set_ylim(24, 31.5)

    # https://stackoverflow.com/questions/32185411/break-in-x-axis-of-matplotlib
    # hide the spines between ax and ax2
    ax.spines['right'].set_visible(False)
    ax2.spines['left'].set_visible(False)
    # ax.yaxis.tick_left()
    # ax.tick_params(labelright='off')
    ax2.yaxis.tick_right()
    ax.tick_params(axis='both', which='major', labelsize=tickfontsize)
    ax2.tick_params(axis='both', which='major', labelsize=tickfontsize)

    # This looks pretty good, and was fairly painless, but you can get that
    # cut-out diagonal lines look with just a bit more work. The important
    # thing to know here is that in axes coordinates, which are always
    # between 0-1, spine endpoints are at these locations (0,0), (0,1),
    # (1,0), and (1,1).  Thus, we just need to put the diagonals in the
    # appropriate corners of each of our axes, and so long as we use the
    # right transform and disable clipping.
    if axis_off == 0:
        d = .015  # how big to make the diagonal lines in axes coordinates
        # arguments to pass plot, just so we don't keep repeating them
        kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
        ax.plot((1-d, 1+d), (-d, +d), **kwargs)
        ax.plot((1-d, 1+d), (1-d, 1+d), **kwargs)
        kwargs.update(transform=ax2.transAxes)  # switch to the bottom axes
        ax2.plot((-d, +d), (1-d, 1+d), **kwargs)
        ax2.plot((-d, +d), (-d, +d), **kwargs)
    # What's cool about this is that now if we vary the distance between
    # ax and ax2 via f.subplots_adjust(hspace=...) or plt.subplot_tool(),
    # the diagonal lines will move accordingly, and stay right at the tips
    # of the spines they are 'breaking'

    ax.set_ylabel('Height in m', fontsize=labelfontsize)
    ax2.set_xlabel('time in s', fontsize=labelfontsize)
    if axis_off == 0 and legendstyle != 'external':
        ax2.legend(loc='upper right', fontsize=legendfontsize)
    if axis_off == 1:
        ax.axis('off')
        ax2.axis('off')
    plt.tight_layout()

    return fig
예제 #5
0
residual = 0

use_nakbspllineboundary_2500_opt = 1
calcVar = 0
plotVar = 0

# percentiles:
percentages = [5, 95]  # [10, 90]
numSamples = 10000  # 100000

saveFig = 1
legendstyle = 'internal'    # internal / external
saveMean = 0

################# Initialization and loading #################
pyFunc = okushiri(dim, numTimeSteps, gridResolution, normalization, residual, 'bumps', distribution)
objFunc = vectorObjFuncSGpp(pyFunc)
lb = objFunc.getLowerBounds()
ub = objFunc.getUpperBounds()

# reference means
if distribution == 'uniform':
    reference_means = np.loadtxt(
        '/home/rehmemk/git/anugasgpp/Okushiri/data/referenceMean_quadOrder3Okushiri64_uniform_nakBsplineBoundary3_6D_uniform_level3_5_95.txt')
elif distribution == 'normal':
    reference_means = np.loadtxt(
        '/home/rehmemk/git/anugasgpp/Okushiri/data/referenceMean_quadOrder100Okushiri64_nakBsplineExtended3_6D_normal_level6_5_95.txt')

### Dakota ###
dakota_means = np.loadtxt(f'/home/rehmemk/git/anugasgpp/Okushiri/data/dakota_means_64_{distribution}.txt')
for l in [1, 2, 3, 4]:
예제 #6
0
sys.path.append('/home/rehmemk/git/anugasgpp/Okushiri')  # nopep8
from sgppOkushiri import okushiri, getMCFileName  # nopep8

numMCPoints = 10000
dim = 6
gridResolution = 64
normalization = 1
residual = 0
wave_type = 'bumps'  # 'bumps'/'shape'
distribution = 'uniform'  # 'uniform'/'normal'
minimum_allowed_height = 1e-5
maxNumPoints = 300

numTimeSteps = 451
okushiriFunc = okushiri(dim, numTimeSteps, gridResolution, normalization,
                        residual, wave_type, distribution,
                        minimum_allowed_height)

lb, ub = okushiriFunc.getDomain()

todoPoints = []
if distribution == 'uniform':
    unitpoints = np.random.rand(numMCPoints, dim)
    for point in unitpoints:
        for d in range(dim):
            point[d] = lb[d] + (ub[d] - lb[d]) * point[d]
        todoPoints.append(point)
elif distribution == 'normal':
    mu, sigma = 1.0, 0.125  # mean and standard deviation
    for m in range(numMCPoints):
        todoPoints.append(np.random.normal(mu, sigma, dim).tolist())
예제 #7
0
import numpy as np
import sys
import matplotlib.pyplot as plt

sys.path.append('/home/rehmemk/git/anugasgpp/Okushiri')  # nopep8
from sgppOkushiri import okushiri  # nopep8

dim = 6
gridResolution = 64
numTimeSteps = 451
normalization = 1
residual = 0
distribution = 'normal'
wave_type = 'original'

pyFunc = okushiri(dim, numTimeSteps, gridResolution, normalization, residual,
                  wave_type, distribution)

time = [t / 22.5 for t in range(451)]
runup = pyFunc.eval([1] * dim)
pyFunc.cleanUp()
plt.plot(time, runup * 400, label='average runup')

tickfontsize = 14
labelfontsize = 14
legendfontsize = 14
plt.xlabel('time in s', fontsize=labelfontsize)
plt.ylabel('height in m', fontsize=labelfontsize)
plt.gca().tick_params(axis='both', which='major', labelsize=tickfontsize)
# plt.legend(fontsize=legendfontsize)
# plt.show()
plt.savefig('/home/rehmemk/git/anugasgpp/Okushiri/plots/OriginalRunup.pdf')