Skip to content

Commit

Permalink
Merge pull request #245 from SURGroup/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
dimtsap authored Sep 15, 2024
2 parents f8d0b1d + 03e338d commit bd510fb
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 104 deletions.
50 changes: 27 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@
:alt: bear-ified


*******************************************
**********************************************
Uncertainty Quantification with python (UQpy)
*******************************************
**********************************************

|logo|

====

+-----------------------+------------------------------------------------------------------+
| **Product Owner:** | Michael D. Shields |
+-----------------------+------------------------------------------------------------------+
| **Lead Developers:** | Dimitris Giovanis, Audrey Olivier, Dimitris Tsapetis |
+-----------------------+------------------------------------------------------------------+
| **Development Team:** | Aakash Bangalore Satish, Mohit Singh Chauhan, Lohit Vandanapu, |
+ + +
| | Ketson RM dos Santos, Katiana Kontolati, Dimitris Loukrezis, |
+ + +
| | Promit Chakroborty, Lukáš Novák, Andrew Solanto, Connor Krill |
+-----------------------+------------------------------------------------------------------+
| **Contributors:** | Michael Gardner, Prateek Bhustali, Julius Schultz, Ulrich Römer |
+-----------------------+------------------------------------------------------------------+
================================================================================================

.. list-table::
:widths: 100, 200
:header-rows: 0

* - **Product Owner:**
- Michael D. Shields

* - **Lead Developers:**
- Dimitris Giovanis, Audrey Olivier, Dimitris Tsapetis

* - **Development Team:**
- Aakash Bangalore Satish, Mohit Singh Chauhan, Lohit Vandanapu, Ketson RM dos Santos, Katiana Kontolati, Dimitris Loukrezis, Promit Chakroborty, Lukáš Novák, Andrew Solanto, Connor Krill

* - **Contributors:**
- Michael Gardner, Prateek Bhustali, Julius Schultz, Ulrich Römer



Contact
===========
Expand All @@ -54,7 +58,7 @@ Website:
https://uqpyproject.readthedocs.io

Dependencies
===========
===============

* ::
Expand All @@ -65,7 +69,7 @@ License
===========
UQpy is distributed under the MIT license

Copyright (C) <2018> <Michael D. Shields>
Copyright (C) <2024> <Michael D. Shields>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand All @@ -75,7 +79,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI


Installation
===========
===============

From PyPI

Expand Down Expand Up @@ -109,13 +113,13 @@ Olivier, A., Giovanis, D.G., Aakash, B.S., Chauhan, M., Vandanapu, L., and Shiel


Help and Support
===========
==================

For assistance with the UQpy software package, please raise an issue on the Github Issues page. Please use the appropriate labels to indicate which module you are specifically inquiring about.

.. |logo| image:: logo.jpg
:scale: 25 %
:target: https://gihub.com/SURGroup/UQpy
:height: 250px
:target: https://github.com/SURGroup/UQpy



26 changes: 13 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
numpy == 1.22.0
scipy == 1.8.0
matplotlib == 3.5.2
scikit-learn == 1.0.2
fire == 0.4.0
pytest == 6.1.2
coverage == 5.3
pytest-cov == 2.10.1
pylint == 2.6.0
wheel == 0.38.1
pytest-azurepipelines == 0.8.0
twine == 3.4.1
numpy == 1.26.4
scipy == 1.6.0
matplotlib == 3.8.4
scikit-learn == 1.4.2
fire == 0.6.0
pytest == 8.2.0
coverage == 7.5.0
pytest-cov == 5.0.0
pylint == 3.1.0
wheel == 0.43.0
pytest-azurepipelines == 1.0.5
twine == 5.0.0
pathlib~=1.0.1
beartype ==0.9.1
beartype == 0.18.5
setuptools~=65.5.1
27 changes: 24 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@
del sys.argv[1]
from setuptools import setup, find_packages

from pathlib import Path
this_directory = Path(__file__).parent
long_description = (this_directory / "README.rst").read_text()

setup(
name='UQpy',
version=version,
url='https://github.com/SURGroup/UQpy',
description="UQpy is a general purpose toolbox for Uncertainty Quantification",
long_description=long_description,
author="Michael D. Shields, Dimitris G. Giovanis, Audrey Olivier, Aakash Bangalore-Satish, Mohit Chauhan, "
"Lohit Vandanapu, Ketson R.M. dos Santos",
author_email="UQpy.info@gmail.com",
license='MIT',
platforms=["OSX", "Windows", "Linux"],
packages=find_packages("src"),
package_dir={"": "src"},
package_data={"": ["*.pdf"]},
python_requires='>3.9.0',
install_requires=[
"numpy", "scipy", "matplotlib", "scikit-learn", 'fire',
"beartype==0.9.1",
"numpy", "scipy>=1.6.0", "matplotlib", "scikit-learn", 'fire',
"beartype==0.18.5",
],
extras_require={
'dev': [
'pytest == 8.2.0',
'pytest-cov == 5.0.0',
'pylint == 3.1.0',
'pytest-azurepipelines == 1.0.5',
'pytest-cov == 5.0.0',
'wheel == 0.43.0',
'twine == 5.0.0',
'sphinx_autodoc_typehints == 1.23.0',
'sphinx_rtd_theme == 1.2.0',
'sphinx_gallery == 0.13.0',
'sphinxcontrib_bibtex == 2.5.0',
'Sphinx==6.1.3',
]
},
classifiers=[
'Programming Language :: Python :: 3',
'Intended Audience :: Science/Research',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _fit(self):
transition_matrix = d_star_inv_d.dot(l_star)

if self.is_sparse:
is_symmetric = sp.sparse.linalg.norm(transition_matrix - transition_matrix.T, sp.inf) < 1e-08
is_symmetric = sp.sparse.linalg.norm(transition_matrix - transition_matrix.T, np.inf) < 1e-08
else:
is_symmetric = np.allclose(transition_matrix, transition_matrix.T, rtol=1e-5, atol=1e-08)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from scipy.special import logsumexp
from scipy.integrate import trapz
from scipy.integrate import trapezoid

from UQpy.sampling.mcmc import MetropolisHastings
from UQpy.sampling.mcmc.baseclass.MCMC import *
Expand Down Expand Up @@ -216,7 +216,7 @@ def evaluate_normalization_constant(self, compute_potential, log_Z0: float = Non
# use quadrature to integrate between 0 and 1
temper_param_list_for_integration = np.copy(np.array(self.tempering_parameters))
log_pdf_averages = np.array(log_pdf_averages)
int_value = trapz(x=temper_param_list_for_integration, y=log_pdf_averages)
int_value = trapezoid(x=temper_param_list_for_integration, y=log_pdf_averages)
if log_Z0 is None:
samples_p0 = self.distribution_reference.rvs(nsamples=nsamples_from_p0)
log_Z0 = np.log(1. / nsamples_from_p0) + logsumexp(
Expand Down
16 changes: 8 additions & 8 deletions src/UQpy/sampling/stratified_sampling/strata/VoronoiStrata.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ def sample_strata(self, nsamples_per_stratum, random_state):

# Compute volume of each delaunay
volume = list()
for i in range(len(delaunay_obj.vertices)):
vert = delaunay_obj.vertices[i]
for i in range(len(delaunay_obj.simplices)):
vert = delaunay_obj.simplices[i]
ch = ConvexHull(seed_and_vertices[vert])
volume.append(ch.volume)

temp_prob = np.array(volume) / sum(volume)
a = list(range(len(delaunay_obj.vertices)))
a = list(range(len(delaunay_obj.simplices)))
for k in range(int(nsamples_per_stratum[j])):
simplex = random_state.choice(a, p=temp_prob)

new_samples = SimplexSampling(
nodes=seed_and_vertices[delaunay_obj.vertices[simplex]],
nodes=seed_and_vertices[delaunay_obj.simplices[simplex]],
nsamples=1,
random_state=self.random_state,
).samples
Expand All @@ -205,15 +205,15 @@ def compute_centroids(self):

for j in range(self.mesh.nsimplex):
try:
ConvexHull(self.points[self.mesh.vertices[j]])
ConvexHull(self.points[self.mesh.simplices[j]])
self.mesh.centroids[j, :], self.mesh.volumes[j] = \
DelaunayStrata.compute_delaunay_centroid_volume(self.points[self.mesh.vertices[j]])
DelaunayStrata.compute_delaunay_centroid_volume(self.points[self.mesh.simplices[j]])
except qhull.QhullError:
self.mesh.centroids[j, :], self.mesh.volumes[j] = (np.mean(self.points[self.mesh.vertices[j]]), 0,)

def initialize(self, samples_number, training_points):
self.add_boundary_points_and_construct_delaunay(samples_number, training_points)
self.mesh.old_vertices = self.mesh.vertices.copy()
self.mesh.old_vertices = self.mesh.simplices.copy()

def add_boundary_points_and_construct_delaunay(
self, samples_number, training_points
Expand Down Expand Up @@ -377,7 +377,7 @@ def _update_strata(self, new_point, samples_u01):
p_ = new_point.shape[0]
# Update the matrices to have recognize the new point
self.points_to_samplesU01 = np.hstack([self.points_to_samplesU01, np.arange(i_, i_ + p_)])
self.mesh.old_vertices = self.mesh.vertices
self.mesh.old_vertices = self.mesh.simplices

# Update the Delaunay triangulation mesh to include the new point.
self.mesh.add_points(new_point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ def predict(self, points, return_std: bool = False, hyperparameters: list = None
else:
mu1 = np.einsum("ij,jk->ik", fx, self.beta)

self.kernel.kernel_parameter = kernelparameters[:-1]
sigma = kernelparameters[-1]
if kernelparameters is not None:
self.kernel.kernel_parameter = kernelparameters[:-1]
sigma = kernelparameters[-1]

k = sigma**2*self.kernel.calculate_kernel_matrix(x=x_, s=s_)
y = mu1 + k @ alpha_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self, x: np.ndarray, y: np.ndarray, design_matrix: np.ndarray):
n_samples, inputs_number = x.shape

reg = regresion.Lars(fit_intercept=self.fit_intercept, verbose=self.verbose,
n_nonzero_coefs=self.n_nonzero_coefs, normalize=self.normalize)
n_nonzero_coefs=self.n_nonzero_coefs)
reg.fit(design_matrix, y)

# LarsBeta = reg.coef_path_
Expand Down
2 changes: 1 addition & 1 deletion src/UQpy/utilities/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def correlation_distortion(dist_object, rho):
:rtype: float
"""

if rho == 1.0:
if np.isclose(rho, 1.0):
rho = 0.999
n = 512
zmax = 8
Expand Down
6 changes: 3 additions & 3 deletions src/UQpy/utilities/kernels/euclidean_kernels/Matern.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def __init__(self, kernel_parameter: Union[int, float] = 1, nu=1.5):
def calculate_kernel_matrix(self, x, s):
l = self.kernel_parameter
stack = cdist(x / l, s / l, metric='euclidean')
if self.nu == 0.5:
if np.isclose(self.nu, 0.5):
self.kernel_matrix = np.exp(-np.abs(stack))
elif self.nu == 1.5:
elif np.isclose(self.nu,1.5):
self.kernel_matrix = (1 + np.sqrt(3) * stack) * np.exp(-np.sqrt(3) * stack)
elif self.nu == 2.5:
elif np.isclose(self.nu, 2.5):
self.kernel_matrix = (1 + np.sqrt(5) * stack + 5 * (stack ** 2) / 3) * np.exp(-np.sqrt(5) * stack)
elif self.nu == np.inf:
self.kernel_matrix = np.exp(-(stack ** 2) / 2)
Expand Down
20 changes: 10 additions & 10 deletions tests/unit_tests/dimension_reduction/test_POD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Define a dataset to test DirectPOD, SnapshotPOD and HOSVD methods
import pytest
from beartype.roar import BeartypeCallHintPepParamException
from beartype.roar import BeartypeCallHintParamViolation

from UQpy.dimension_reduction.pod.DirectPOD import DirectPOD
from UQpy.dimension_reduction.pod.SnapshotPOD import SnapshotPOD
Expand Down Expand Up @@ -65,17 +65,17 @@ def test_HOSVD():


def test_DirectPOD_modes_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
pod_dir = DirectPOD(solution_snapshots=Data, n_modes=-1)


def test_DirectPOD_mode_non_integer():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
pod_dir = DirectPOD(solution_snapshots=Data, n_modes=1.5)


def test_DirectPOD_reconstr_perc_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
pod_dir = DirectPOD(solution_snapshots=Data, reconstruction_percentage=-1)


Expand All @@ -85,17 +85,17 @@ def test_DirectPOD_both_modes_and_reconstr_error():


def test_HOSVD_modes_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
hosvd = HigherOrderSVD(solution_snapshots=Data, modes=-1)


def test_HOSVD_mode_non_integer():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
hosvd = HigherOrderSVD(solution_snapshots=Data, modes=1.5)


def test_HOSVD_reconstr_perc_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
hosvd = HigherOrderSVD(solution_snapshots=Data, reconstruction_percentage=-1)


Expand All @@ -105,17 +105,17 @@ def test_HOSVD_both_modes_and_reconstr_error():


def test_SnapshotPOD_modes_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
snap = SnapshotPOD(solution_snapshots=Data, n_modes=-1)


def test_SnapshotPOD_mode_non_integer():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
snap = SnapshotPOD(solution_snapshots=Data, n_modes=1.5)


def test_SnapshotPOD_reconstr_perc_less_than_zero():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
snap = SnapshotPOD(solution_snapshots=Data, reconstruction_percentage=-1)


Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/run_model/test_RunModel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shutil

from beartype.roar import BeartypeCallHintPepParamException
from beartype.roar import BeartypeCallHintParamViolation

from UQpy.run_model.model_execution.PythonModel import PythonModel
from UQpy.run_model import ThirdPartyModel, RunModel
Expand Down Expand Up @@ -38,7 +38,7 @@


def test_var_names():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
model = PythonModel(model_script='python_model.py', model_object_name='SumRVs', var_names=[20],
delete_files=True)
runmodel_object = RunModel(model=model)
Expand All @@ -52,7 +52,7 @@ def test_model_script():


def test_samples():
with pytest.raises(BeartypeCallHintPepParamException):
with pytest.raises(BeartypeCallHintParamViolation):
model = PythonModel(model_script='python_model.py', model_object_name='SumRVs',
delete_files=True)
runmodel_object = RunModel(model=model, samples="samples_string")
Expand Down
Loading

0 comments on commit bd510fb

Please sign in to comment.