Example #1
0
 def __init__(self, dim, numTimeSteps=451, gridResolution=16):
     self.dim = dim
     self.out = numTimeSteps
     self.gridResolution = gridResolution
     self.okushiriStorage = okushiriStorage(dim, numTimeSteps,
                                            self.gridResolution)
     self.pdfs = pysgpp.DistributionsVector()
     for d in range(self.dim):
         self.pdfs.push_back(pysgpp.DistributionUniform(0.0, 2.0))
Example #2
0
 def __init__(self,
              dim,
              numTimeSteps=451,
              gridResolution=16,
              normalization=1,
              residual=0,
              wave_type='bumps',
              distribution='normal',
              minimum_allowed_height=1e-5):
     self.dim = dim
     self.out = numTimeSteps
     self.gridResolution = gridResolution  # 16/128
     self.normalization = normalization
     self.residual = residual
     self.wave_type = wave_type
     self.okushiriStorage = okushiriStorage(dim, numTimeSteps,
                                            self.gridResolution,
                                            self.normalization,
                                            self.residual, self.wave_type)
     self.pdfs = pysgpp.DistributionsVector()
     self.distribution = distribution
     self.minimum_allowed_height = minimum_allowed_height
     if wave_type == 'bumps':
         for d in range(self.dim):
             if self.distribution == 'uniform':
                 self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
             elif self.distribution == 'normal':
                 self.pdfs.push_back(
                     pysgpp.DistributionTruncNormal(1.0, 0.125, 0.5, 1.5))
                 # self.pdfs.push_back(pysgpp.DistributionNormal(1.0, 0.125))
     # elif wave_type == 'shape':
     #     # TODO REPLACE THESE WITH NORMAL DISTRIBUTIONS WHEN CALCULATING STOCHASTIC MOMENTS
     #     self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
     #     self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
     #     self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
     #     self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
     #     self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
     #     self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
     elif wave_type == 'original':
         for _ in range(self.dim):
             self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
Example #3
0
 def __init__(self, dim, normalization=1, residual=1):
     self.dim = dim
     self.normalization = normalization
     self.residual = residual
     self.out = 451
     self.pdfs = pysgpp.DistributionsVector()
     for d in range(dim):
         self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
     data = np.loadtxt(
         '/home/rehmemk/git/anugasgpp/Okushiri/data/boundary_wave_original.txt',
         skiprows=1)
     self.t = data[:, 0]
     self.y = data[:, 1]
     self.energy = np.trapz(self.y**2, self.t)
Example #4
0
 def __init__(self,
              dim,
              reallb,
              realub,
              numTimeSteps=451,
              gridResolution=16,
              normalization=1,
              residual=0):
     self.dim = dim
     self.reallb = reallb
     self.realub = realub
     self.gridResolution = gridResolution
     self.numTimeSteps = numTimeSteps
     self.normalization = normalization
     self.residual = residual
     self.okushiriStorage = okushiriStorage(dim, self.numTimeSteps,
                                            self.gridResolution,
                                            self.normalization,
                                            self.residual)
     self.pdfs = pysgpp.DistributionsVector()
     for _ in range(dim):
         self.pdfs.push_back(pysgpp.DistributionUniform(0.0, 1.0))
Example #5
0
    def __init__(self, gridResolution=16, normalization=1):
        self.dim = 6
        self.gridResolution = gridResolution
        self.normalization = normalization
        self.numTimeSteps = 451
        residual = 0
        self.wave_type = 'shape'
        self.okushiriStorage = okushiriStorage(self.dim, self.numTimeSteps,
                                               self.gridResolution,
                                               self.normalization, residual,
                                               self.wave_type)

        self.pdfs = pysgpp.DistributionsVector()
        # TODO REPLACE THESE WITH NORMAL DISTRIBUTIONS WHEN CALCULATING STOCHASTIC MOMENTS
        self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
        self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
        self.pdfs.push_back(pysgpp.DistributionUniform(0.5, 1.5))
        self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
        self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
        self.pdfs.push_back(pysgpp.DistributionUniform(1.0, 2.0))
Example #6
0
reSurf.surplusAdaptive(numPoints, initialLevel, numRefine, verbose)

# Now the surrogate has been created and we can use it to calculate various
# quantities of interest

# evaluate the surrogate
evalPoint = pysgpp.DataVector([0.3, 0.6])
print(f'reSurf: {reSurf.eval(evalPoint)}     truth: {objFunc.eval(evalPoint)}')

# evaluate the surrogate's gradient
gradient = pysgpp.DataVector(dim, 0)
reSurf.evalGradient(evalPoint, gradient)
print(f'gradient: {gradient.toString()}')

# integrate the surrogate
print(f'integral: {reSurf.getIntegral()}')

# calculate stochastic moments
# first specify distibutions
pdfs = pysgpp.DistributionsVector()
pdfs.push_back(pysgpp.DistributionNormal(0.5, 0.1))
pdfs.push_back(pysgpp.DistributionUniform(0, 1))
# set quadrature order appropriate for the distributions and desired accuracy
quadOrder = 15
print(f'mean: {reSurf.getMean(pdfs,quadOrder)}')
v = reSurf.getVariance(pdfs, quadOrder)
print(f'variance: {v[0]}')

# optimize the surrogate
print(f'Optimum: {reSurf.optimize()}')