Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b9539ab
implemented custom pdf, cdf, icdf method for Uniform.py
connor-krill Jun 2, 2023
f98071a
implemented custom pdf, cdf method for Normal.py
connor-krill Jun 2, 2023
8db235f
new validation type for NumericArrayLikes and appropriate tests for n…
connor-krill Jun 2, 2023
b3907b9
added scratch folder
connor-krill Jun 2, 2023
2f895b4
removed inverse cdf for normal bc it was slow and inaccurate
connor-krill Sep 1, 2023
83058db
Merge remote-tracking branch 'origin/Development' into feature/distri…
connor-krill Sep 1, 2023
ce7ccad
Merge branch 'Development' into feature/distribution_speed_up
dimtsap Sep 2, 2023
fc0dac7
renamed variable input for consistency and to pass unit tests
connor-krill Sep 5, 2023
1e91dc8
Merge remote-tracking branch 'origin/feature/distribution_speed_up' i…
connor-krill Sep 5, 2023
8114bcd
changed return behavior for floats and ints in custom pdf, cdf, icdf …
connor-krill Sep 12, 2023
d65483b
improved documentation, imports, and beartype
connor-krill May 22, 2024
7c3bdc6
moved tests for custom uniform and normal pdf, cdf, icdf to test_norm…
connor-krill May 22, 2024
c5f1783
cleaned up formatting
connor-krill May 22, 2024
26ff00e
added custom inverse function
connor-krill May 28, 2024
298ccb6
added int as allowed output type
connor-krill May 28, 2024
d10e00f
improved tests
connor-krill May 28, 2024
fbd3aa7
added tests for not-a-number and infinity
connor-krill Oct 15, 2024
290a3cf
added __repr__ method
connor-krill Mar 5, 2025
bdb68d3
added tests for __repr__ method
connor-krill Mar 5, 2025
5258497
added tests for custom pdf, cdf, icdf methods
connor-krill Mar 5, 2025
ce275bf
minor improvements to docstrings
connor-krill Mar 17, 2025
7cb5f53
Merge branch 'Development' into feature/distribution_speed_up
connor-krill Mar 18, 2025
60d56dc
fixed how types are handled in `if` statement
connor-krill Mar 18, 2025
98149f8
Merge remote-tracking branch 'origin/feature/distribution_speed_up' i…
connor-krill Mar 18, 2025
36c33d8
Merge branch 'Development' into feature/distribution_speed_up
connor-krill May 19, 2025
29fe99a
added Triangular distribution to address issue #262
connor-krill May 29, 2025
bcf6122
Merge remote-tracking branch 'origin/feature/distribution_speed_up' i…
connor-krill May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new validation type for NumericArrayLikes and appropriate tests for n…
…ew pdf, cdf, icdf methods in Uniform and Normal
  • Loading branch information
connor-krill committed Jun 2, 2023
commit 8db235f16aab2e8c4b6e6d2875738bff49790999
2 changes: 2 additions & 0 deletions src/UQpy/utilities/ValidationTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import numpy as np
from beartype.vale import Is


RandomStateType = Union[None, int, np.random.RandomState]
PositiveInteger = Annotated[int, Is[lambda number: number > 0]]
PositiveFloat = Annotated[float, Is[lambda number: number > 0]]
NumericArrayLike = Union[int, float, list, tuple, np.ndarray]
Numpy2DFloatArray = Annotated[
np.ndarray,
Is[lambda array: array.ndim == 2 and np.issubdtype(array.dtype, float)],
Expand Down
66 changes: 66 additions & 0 deletions tests/unit_tests/distributions/test_distribution_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from UQpy.distributions import *
import numpy as np
import pytest
import scipy


# Test all functions for one type of continuous distribution: uniform
dist_continuous = Uniform(loc=1., scale=2.)
Expand Down Expand Up @@ -81,3 +84,66 @@ def test_update_params_copula():
copula = Gumbel(theta=2.)
copula.update_parameters(theta=1.)
assert copula.get_parameters()['theta'] == 1.


# Test function for custom implementation of Uniform PDF and CDF
@pytest.mark.parametrize("value,expected_probability", [
(-4, 0),
(0, 1),
(0.5, 1),
(1, 1),
(12, 0),
([-1, 0, 0.5, 1, 2], [0, 1, 1, 1, 0]),
((-1, 0, 0.5, 1, 2), (0, 1, 1, 1, 0)),
(np.array([-1, 0, 0.5, 1, 2]), np.array([0, 1, 1, 1, 0]))
])
def test_uniform_pdf(value, expected_probability):
uniform = Uniform()
assert all(uniform.pdf(value) == expected_probability)


@pytest.mark.parametrize("value,expected_probability", [
(-0.1245, 0),
(0.4, 0.4),
(3.14159, 1),
([-4, 0.2, 0.75, 1, 6], [0, 0.2, 0.75, 1, 1]),
((-4, 0.2, 0.75, 1, 6), (0, 0.2, 0.75, 1, 1)),
(np.array([-4, 0.2, 0.75, 1, 6]), np.array([0, 0.2, 0.75, 1, 1])),
])
def test_uniform_cdf(value, expected_probability):
uniform = Uniform()
assert all(uniform.cdf(value) == expected_probability)


@pytest.mark.parametrize("probability,expected_value", [
(-1, np.nan),
(0, 0),
(0.123, 0.123),
(1, 1),
(1.2, np.nan),
((-0.5, 0, 0.5, 1, 1.5), (np.nan, 0, 0.5, 1, np.nan)),
([-0.5, 0, 0.5, 1, 1.5], [np.nan, 0, 0.5, 1, np.nan]),
(np.array([-0.5, 0, 0.5, 1, 1.5]), np.array([np.nan, 0, 0.5, 1, np.nan]))
])
def test_uniform_icdf(probability, expected_value):
uniform = Uniform()
assert np.array_equal(uniform.icdf(probability), np.atleast_1d(expected_value), equal_nan=True)


@pytest.mark.parametrize("value", [-3, -2.5, -1, 0, 1, 2.415, 6.168, np.array([-8, -4.13, -1, 0, 2])])
def test_normal_pdf(value):
normal = Normal()
assert (np.isclose(normal.pdf(value), scipy.stats.norm.pdf(value))).all()


@pytest.mark.parametrize("value", [-4, -2.7, -0.4, 0, 0.4321, 2, 8, np.array([-3, -2, 0, 1, 4])])
def test_normal_cdf(value):
normal = Normal()
assert (np.isclose(normal.cdf(value), scipy.stats.norm.cdf(value))).all()


@pytest.mark.parametrize("probability", [-1, 0, 1e-9, 0.15, 0.6626, 1-1e-9, 1, 2, np.array([-1, 0, 0.321123, 1, 5])])
def test_normal_icdf(probability):
normal = Normal()
expected_value = np.atleast_1d(scipy.stats.norm.ppf(probability))
assert np.allclose(normal.icdf(probability), expected_value, equal_nan=True)