Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #216

Merged
merged 14 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions docs/code/dimension_reduction/grassmann/plot_grassmann_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from UQpy.dimension_reduction.grassmann_manifold.projections.SVDProjection import SVDProjection
from UQpy.dimension_reduction import GrassmannOperations
from UQpy.utilities import GrassmannPoint
from UQpy.utilities.kernels import Kernel, ProjectionKernel
from UQpy.utilities.kernels import ProjectionKernel
import sys

# %% md
Expand Down Expand Up @@ -73,10 +73,10 @@
# %%
projection_kernel = ProjectionKernel()

projection_kernel.calculate_kernel_matrix(points=manifold_projection.u)
projection_kernel.calculate_kernel_matrix(x=manifold_projection.u, s=manifold_projection.u)
kernel_psi = projection_kernel.kernel_matrix

projection_kernel.calculate_kernel_matrix(points=manifold_projection.v)
projection_kernel.calculate_kernel_matrix(x=manifold_projection.v, s=manifold_projection.v)
kernel_phi = projection_kernel.kernel_matrix

fig, (ax1, ax2) = plt.subplots(1, 2)
Expand All @@ -92,9 +92,9 @@

# %%

projection_kernel.calculate_kernel_matrix(points=[manifold_projection.u[0],
manifold_projection.u[1],
manifold_projection.u[2]])
projection_kernel.\
calculate_kernel_matrix(x=[manifold_projection.u[0], manifold_projection.u[1], manifold_projection.u[2]],
s=[manifold_projection.u[0], manifold_projection.u[1], manifold_projection.u[2]])
kernel_01 = projection_kernel.kernel_matrix

fig = plt.figure()
Expand All @@ -111,17 +111,18 @@

class UserKernel(GrassmannianKernel):

def kernel_entry(self, xi: GrassmannPoint, xj: GrassmannPoint):
r = np.dot(xi.data.T, xj.data)
def element_wise_operation(self, xi_j) -> float:
xi, xj = xi_j
r = np.dot(xi.T, xj)
det = np.linalg.det(r)
return det * det


user_kernel = UserKernel()
user_kernel.calculate_kernel_matrix(points=manifold_projection.u)
user_kernel.calculate_kernel_matrix(x=manifold_projection.u, s=manifold_projection.u)
kernel_user_psi = user_kernel.kernel_matrix

user_kernel.calculate_kernel_matrix(points=manifold_projection.v)
user_kernel.calculate_kernel_matrix(x=manifold_projection.v, s=manifold_projection.v)
kernel_user_phi = user_kernel.kernel_matrix

fig, (ax1, ax2) = plt.subplots(1, 2)
Expand Down
3 changes: 2 additions & 1 deletion docs/code/surrogates/gpr/plot_gpr_custom2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from UQpy.surrogates import GaussianProcessRegression, Matern
from UQpy.surrogates import GaussianProcessRegression

# %% md
#
# Create a distribution object.

# %%
from UQpy.utilities import Matern

marginals = [Uniform(loc=0., scale=1.), Uniform(loc=0., scale=1.)]

Expand Down
9 changes: 5 additions & 4 deletions docs/code/surrogates/gpr/plot_gpr_no_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

# %%

import numpy as np
import matplotlib.pyplot as plt
import warnings

import matplotlib.pyplot as plt
import numpy as np

from UQpy.surrogates.gaussian_process.regression_models.LinearRegression import LinearRegression
from UQpy.utilities import RBF

warnings.filterwarnings('ignore')
from UQpy.utilities.MinimizeOptimizer import MinimizeOptimizer
from UQpy.utilities.FminCobyla import FminCobyla
from UQpy.surrogates import GaussianProcessRegression, NonNegative, RBF
from UQpy.surrogates import GaussianProcessRegression


# %% md
Expand Down
5 changes: 4 additions & 1 deletion docs/code/surrogates/gpr/plot_gpr_noisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import numpy as np
import matplotlib.pyplot as plt
import warnings

from UQpy.utilities import RBF

warnings.filterwarnings('ignore')
from UQpy.utilities.MinimizeOptimizer import MinimizeOptimizer
from UQpy.surrogates.gaussian_process.regression_models.LinearRegression import LinearRegression
from UQpy.surrogates import GaussianProcessRegression, RBF
from UQpy.surrogates import GaussianProcessRegression


# %% md
Expand Down
3 changes: 2 additions & 1 deletion docs/code/surrogates/gpr/plot_gpr_sine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
from UQpy.distributions import Gamma
import numpy as np
import matplotlib.pyplot as plt
from UQpy.surrogates import GaussianProcessRegression, RBF
from UQpy.surrogates import GaussianProcessRegression

# %% md
#
# Create a distribution object.

# %%
from UQpy.utilities import RBF

marginals = [Gamma(a=2., loc=1., scale=3.)]

Expand Down
5 changes: 3 additions & 2 deletions docs/code/surrogates/pce/plot_pce_camel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

.. math:: f(x) = \Big(4-2.1x_1^2 + \frac{x_1^4}{3} \Big)x_1^2 + x_1x_2 + (-4 + 4x_2^2)x_2^2


**Description:** Dimensions: 2

**Input Domain:** This function is evaluated on the hypercube :math:`x_1 \in [-3, 3], x_2 \in [-2, 2]`.

**Global minimum:** :math:`f(x^*)=-1.0316,` at :math:`x^* = (0.0898, -0.7126)` and
:math:`(-0.0898, 0.7126)`.
**Global minimum:** :math:`f(x^*)=-1.0316,` at :math:`x^* = (0.0898, -0.7126)` and :math:`(-0.0898, 0.7126)`.

**Reference:** Molga, M., & Smutnicki, C. Test functions for optimization needs (2005). Retrieved June 2013, from http://www.zsd.ict.pwr.wroc.pl/files/docs/functions.pdf.

"""

# %% md
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
sphinx_autodoc_typehints
sphinx_rtd_theme
sphinx_gallery
sphinxcontrib_bibtex
sphinxcontrib_bibtex
Sphinx==6.1.3
2 changes: 1 addition & 1 deletion docs/source/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Surrogates
Another module that has extensively restructured in v4 is the surrogates. Apart from the :class:`.SROM` method which
was retained as an independent algorithm, the previous Kriging functionality was removed. It is now replaced with
:class:`.GaussianProcessRegression`. The functionality of the Gaussian is constructed using object composition,
and the specific implementation of :class:`.Regression` and :class:`.Kernel` abstract base classes. An additional
and the specific implementation of :class:`.Regression` and :class:`Kernel` abstract base classes. An additional
functionality of constrained surrogates is added by implementing the :class:`.ConstraintsGPR` abstract class. The
functionality of :class:`.PolynomialChaosExpansion` was rewritten from scratch to address some performance issues of v3.
The Strategy Design pattern was used here as well, with three abstract base classes :class:`.Polynomials`,
Expand Down
32 changes: 24 additions & 8 deletions docs/source/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,19 @@ @article{saltelli_2002
keywords = {Sensitivity analysis, Sensitivity measures, Sensitivity indices, Importance measures},
}

@article{PTMCMC1,
title = {Parallel Tempering: Theory, Applications, and New Perspectives},
author = {David J. Earl, Michael W. Deem},
year = {2005},
doi = {https://doi.org/10.48550/arXiv.physics/0508111}
}
@Article{PTMCMC1,
author ="Earl, David J. and Deem, Michael W.",
title ="Parallel tempering: Theory{,} applications{,} and new perspectives",
journal ="Phys. Chem. Chem. Phys.",
year ="2005",
volume ="7",
issue ="23",
pages ="3910-3916",
publisher ="The Royal Society of Chemistry",
doi ="10.1039/B509983H",
url ="http://dx.doi.org/10.1039/B509983H",
abstract ="We review the history of the parallel tempering simulation method. From its origins in data analysis{,} the parallel tempering method has become a standard workhorse of physicochemical simulations. We discuss the theory behind the method and its various generalizations. We mention a selected set of the many applications that have become possible with the introduction of parallel tempering{,} and we suggest several promising avenues for future research."}


@inproceedings{PTMCMC2,
title = {Using Thermodynamic Integration to Calculate the Posterior Probability in Bayesian Model Selection Problems},
Expand All @@ -844,13 +851,22 @@ @inproceedings{PTMCMC2
author = {Paul M. Goggans and Ying Chi}
}


@article{STMCMC_ChingChen,
author = {Jianye Ching and Yi-Chu Chen },
title = {Transitional Markov Chain Monte Carlo Method for Bayesian Model Updating, Model Class Selection, and Model Averaging},
author = {Jianye Ching, Yi-Chu Chen},
journal = {Journal of Engineering Mechanics},
volume = {133},
number = {7},
pages = {816-832},
year = {2007},
doi = {https://doi.org/10.1061/(ASCE)0733-9399(2007)133:7(816)}
doi = {10.1061/(ASCE)0733-9399(2007)133:7(816)},
URL = {https://ascelibrary.org/doi/abs/10.1061/%28ASCE%290733-9399%282007%29133%3A7%28816%29},
eprint = {https://ascelibrary.org/doi/pdf/10.1061/%28ASCE%290733-9399%282007%29133%3A7%28816%29}
}



@article{Kle2D,
title = {Simulation of multi-dimensional random fields by Karhunen–Loève expansion},
journal = {Computer Methods in Applied Mechanics and Engineering},
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)

# The full version, including alpha/beta/rc tags
release = "v4.0.0"
release = "v4.1.0"

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -173,15 +173,15 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
language = None
language = "en"
pygments_style = None

html_theme = "sphinx_rtd_theme"

html_theme_options = {
"logo_only": True,
"style_nav_header_background": "#F0F0F0",
"vcs_pageview_mode": "view",
# "vcs_pageview_mode": "view",
}

github_url = "https://github.com/SURGroup/UQpy"
Expand Down
4 changes: 2 additions & 2 deletions docs/source/sensitivity/sobol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Attributes
.. autoattribute:: UQpy.sensitivity.SobolSensitivity.second_order_confidence_interval
.. autoattribute:: UQpy.sensitivity.SobolSensitivity.total_order_confidence_interval
.. autoattribute:: UQpy.sensitivity.SobolSensitivity.n_samples
.. autoattribute:: UQpy.sensitivity.Sobol.n_variables
.. autoattribute:: UQpy.sensitivity.Sobol.is_multi_output
.. autoattribute:: UQpy.sensitivity.SobolSensitivity.n_variables
.. autoattribute:: UQpy.sensitivity.SobolSensitivity.is_multi_output


Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/source/stochastic_process/karhunen_loeve_1d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Examples

.. toctree::

Karhunen Loeve Examples <../auto_examples/stochastic_processes/karhunen_loeve/index>
Karhunen Loeve Examples <../auto_examples/stochastic_processes/karhunen_loeve_1d/index>
5 changes: 2 additions & 3 deletions docs/source/stochastic_process/karhunen_loeve_2d.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Karhunen Loève Expansion for Multi-Dimensional Fields
----------------------------
-----------------------------------------------------

The Karhunen Loève Expansion expands the stochastic field as follows:

Expand All @@ -9,7 +9,7 @@ where :math:`\eta_{nk}(\theta)` are uncorrelated standardized normal random vari
at :cite:`Kle2D`

KarhunenLoeve2D Class
^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^

The :class:`.KarhunenLoeve2D` class is imported using the following command:

Expand All @@ -23,7 +23,6 @@ Methods
Attributes
""""""""""
.. autoattribute:: UQpy.stochastic_process.KarhunenLoeveExpansion2D.samples
.. autoattribute:: UQpy.stochastic_process.KarhunenLoeveExpansion2D.xi

Examples
""""""""""
Expand Down
9 changes: 3 additions & 6 deletions docs/source/surrogates/gpr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,13 @@ User-Defined Kernel
""""""""""""""""""""""""""""

Adding a new kernel to the :class:`.GaussianProcessRegression` class is straightforward. This is done by creating a new class
that extends the :class:`UQpy.surrogates.gaussian_process.kernels.baseclass.Kernel` abstract base class.
that extends the :class:`.Kernel` abstract base class.
This new class must have a method ``c(self, x, s, params)`` that takes as input the new points, training points and hyperparameters.
Notice that the input ``params`` include lengthscales and process standard deviation, not noise standard deviation (even for noisy data).

The :class:`UQpy.surrogates.gaussian_process.kernels.baseclass.Kernel` class is imported using the following command:
The :class:`.Kernel` class is imported using the following command:

>>> from UQpy.surrogates.gaussian_process.kernels.baseclass.Kernel import Kernel

.. autoclass:: UQpy.surrogates.gaussian_process.Kernel
:members:
>>> from UQpy.utilities.kernels.baseclass.Kernel import Kernel

The method should return covariance matrix, i.e. a 2-D array with first dimension
being the number of new points and second dimension being the number of training points.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/utilities/kernels/euclidean_kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Methods
~~~~~~~~~

.. autoclass:: UQpy.utilities.kernels.GaussianKernel
:members: kernel_entry, optimize_parameters
:members: optimize_parameters

Attributes
~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/source/utilities/kernels/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The :class:`UQpy.utilities.kernels.baseclass.Kernel` class is imported using the
>>> from UQpy.utilities.kernels.baseclass.Kernel import Kernel

.. autoclass:: UQpy.utilities.kernels.baseclass.Kernel
:members: kernel_entry, optimize_parameters, calculate_kernel_matrix
:members: calculate_kernel_matrix

Types of Kernels
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions src/UQpy/dimension_reduction/diffusion_maps/DiffusionMaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Annotated, Union
from beartype.vale import Is
from UQpy.utilities.ValidationTypes import Numpy2DFloatArray, NumpyFloatArray
from UQpy.utilities.kernels.baseclass import Kernel
from UQpy.utilities.kernels.baseclass.Kernel import Kernel


class DiffusionMaps:
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(
if kernel_matrix is not None:
self.kernel_matrix = kernel_matrix
elif data is not None and kernel is not None:
kernel.calculate_kernel_matrix(points=data)
kernel.calculate_kernel_matrix(x=data, s=data)
self.kernel_matrix = kernel.kernel_matrix
else:
raise ValueError("Either `kernel_matrix` or both `data` and `kernel` must be provided")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABC, abstractmethod

from UQpy.utilities.kernels.baseclass.Kernel import Kernel


class GrassmannProjection(ABC):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, pdf_intermediate=None, log_pdf_intermediate=None, args_pdf_in
least two inputs :code:`x` (ndarray, point(s) at which to evaluate the function), and :code:`temper_param` (float,
tempering parameter). Eit her `pdf_intermediate` or `log_pdf_intermediate` must be provided
(`log_pdf_intermediate` is preferred). Within the code, the `log_pdf_intermediate` is evaluated as:
:code:`log_pdf_intermediate(x, temper_param, *args_pdf_intermediate)`
:code:`log_pdf_intermediate(x, temper_param, *args_pdf_intermediate)`
where `args_pdf_intermediate` are additional positional arguments that are provided to the class via its
`args_pdf_intermediate` input
:param log_pdf_intermediate: see `pdf_intermediate`
Expand Down
Loading