-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from UCL-CCS/fix_MC_for_one_param
Fix MCSampler for 1D problems
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
import chaospy as cp | ||
from easyvvuq.sampling import MCSampler | ||
from easyvvuq.sampling.base import Vary | ||
|
||
|
||
def test_sampling(): | ||
vary = {'a': cp.Uniform(-5, 0), 'b': cp.Uniform(2, 10)} | ||
sampler = MCSampler(vary, 100) | ||
assert(sampler.n_samples() == 400) | ||
for _ in range(sampler.n_samples()): | ||
sample = next(sampler) | ||
assert(sample['a'] >= -5 and sample['a'] <= 0) | ||
assert(sample['b'] >= 2 and sample['b'] <= 10) | ||
with pytest.raises(StopIteration): | ||
next(sampler) | ||
|
||
|
||
def test_sampling_1D(): | ||
vary = {'a': cp.Uniform(-1, 1)} | ||
sampler = MCSampler(vary, 100) | ||
# This used to fail in the saltelli subroutine if there was only 1 input | ||
for _ in range(sampler.n_samples()): | ||
sample = next(sampler) |