Page MenuHomec4science

sparse_grid_sampler_two_way.py
No OneTemporary

File Metadata

Created
Wed, May 8, 03:03

sparse_grid_sampler_two_way.py

# Copyright (C) 2018-2020 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
from itertools import product
import numpy as np
from .sparse_grid_sampler import SparseGridSampler
from rrompy.utilities.base.types import Tuple, List
from rrompy.utilities.exception_manager import RROMPyException
__all__ = ['SparseGridSamplerTwoWay']
class SparseGridSamplerTwoWay(SparseGridSampler):
"""Generator of sparse grid sample points with two-way refinement."""
def refine(self, active : List[int] = None) -> Tuple[List[int], List[int]]:
if active is None: active = np.arange(self.npoints)
active = np.array(active)
if np.any(active < 0) or np.any(active >= self.npoints):
raise RROMPyException(("Active indices must be between 0 "
"(included) and npoints (excluded)."))
newIdxs, oldIdxs = [], []
for act in active:
point, dpt = self.points[act], self.depth[act]
for jdelta, signdelta, backwards in product(range(self.npar),
[-1., 1.], [0, 1]):
if backwards: dpt[jdelta] -= 1
idx = self.addForwardPoint(point, dpt, jdelta, signdelta)
if idx is not None:
if idx > 0: newIdxs += [idx]
elif - idx not in newIdxs: oldIdxs += [- idx]
if backwards: dpt[jdelta] += 1
return newIdxs, oldIdxs

Event Timeline