Page MenuHomec4science

parameter_sampling.py
No OneTemporary

File Metadata

Created
Tue, May 7, 00:03

parameter_sampling.py

# Copyright (C) 2018 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/>.
#
#import pytest
import numpy as np
from rrompy.utilities.parameter_sampling import (ManualSampler,
QuadratureSampler, RandomSampler, FFTSampler)
def test_manual():
sampler = ManualSampler(lims = [0, 3], points = np.linspace(0, 3, 101),
scaling = lambda x: np.power(x, 2.),
scalingInv = lambda x: np.power(x, .5))
assert sampler.name() == "ManualSampler"
x, w = sampler.generatePoints(10)
assert np.allclose(x, np.linspace(0, 3, 101)[:10])
assert np.allclose(w, np.ones(10) * .9)
def test_quadrature():
sampler = QuadratureSampler(lims = [0, 3], kind = "CHEBYSHEV")
x, w = sampler.generatePoints(9)
assert np.isclose(x[2], 1.5)
assert np.allclose(w, np.ones(9) / 3.)
def test_random():
sampler = RandomSampler(lims = [0, 3], kind = "SOBOL")
x, w = sampler.generatePoints(100, seed = 13432)
assert np.isclose(x[47], 0.55609130859375)
assert np.allclose(w, np.ones(100) * .03)
def test_fft():
sampler = FFTSampler(lims = [-1, 1])
x, w = sampler.generatePoints(100)
assert np.allclose(np.power(x, 100), 1.)
assert np.allclose(w, np.ones(100) * .01)

Event Timeline