Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaxiangYi96 committed Nov 20, 2023
1 parent 6b6c030 commit f7df45c
Show file tree
Hide file tree
Showing 20 changed files with 611 additions and 238 deletions.
Binary file modified .coverage
Binary file not shown.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
tutorials/
examples/
tests/
studies/
src/mfpml/_legacy/
# <<< UPDATE ACCORDING WITH YOUR PYTHON PROJECT

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
1.0.0
2 changes: 1 addition & 1 deletion src/mfpml/models/gpr_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import time

from typing import Any

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion src/mfpml/models/hierarchical_kriging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import time

from typing import Any

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion src/mfpml/models/rbf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any


import numpy as np
from numpy.linalg import cholesky, solve
Expand Down
145 changes: 15 additions & 130 deletions src/mfpml/problems/multifidelity_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class ContinuousNonlinearCorrelation1D(MultiFidelityFunctions):
"""_summary_
"""Continuous Nonlinear Correlation 1D
Parameters
----------
MultiFidelityFunctions : _type_
_description_
MultiFidelityFunctions : class
base class
Returns
-------
_type_
_description_
"""
num_dim: int = 1
num_obj: int = 1
Expand Down Expand Up @@ -522,17 +518,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class PhaseShiftedOscillations(MultiFidelityFunctions):
"""_summary_
"""Phase shifted oscillations
Parameters
----------
MultiFidelityFunctions : _type_
_description_
MultiFidelityFunctions : class
based class
Returns
-------
_type_
_description_
"""
num_dim: int = 1
num_obj: int = 1
Expand Down Expand Up @@ -570,22 +562,6 @@ class mf_Bohachevsky(MultiFidelityFunctions):
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/boha.html
.. [2] https://github.com/sjvrijn/mf2
.. [3] Dong, H., Song, B., Wang, P. et al. Multi-fidelity information
fusion based on prediction of kriging. Struct Multidisc Optim
51, 1267-1280 (2015) doi:10.1007/s00158-014-1213-9
Formula
-------
.. math::
f_h(x) = x_1^2 + 2x_2^2 - 0.3cos(3\pi x_1) - 0.4cos(4\pi x_2) + 0.7
.. math::
f_l(x_1, x_2) = f_h(0.7x_1, x_2) + x_1x_2 - 12
"""
num_dim: int = 2
num_obj: int = 1
Expand Down Expand Up @@ -651,28 +627,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_Booth(MultiFidelityFunctions):
"""multi-fidelity Booth function,
"""multi-fidelity Booth function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/boha.html
.. [2] https://github.com/sjvrijn/mf2
.. [3] Dong, H., Song, B., Wang, P. et al. Multi-fidelity information fusion
based on prediction of kriging. Struct Multidisc Optim 51, 1267-1280
(2015) doi:10.1007/s00158-014-1213-9
Formula
-------
.. math::
f_h(x) = (x_1 + 2x_2 - 7)^2 + (2x_1 + x_2 - 5)^2
.. math::
f_l(x_1, x_2) = f_h(0.4x_1, x_2) + 1.7x_1x_2 - x_1 + 2x_2
"""

num_dim: int = 2
Expand Down Expand Up @@ -737,38 +698,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_Borehole(MultiFidelityFunctions):
"""multi-fidelity Borehole function,
"""multi-fidelity Borehole function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/boha.html
.. [2] https://github.com/sjvrijn/mf2
.. [3] Shifeng Xiong, Peter Z. G. Qian & C. F. Jeff Wu (2013) Sequential
Design and Analysis of High-Accuracy and Low-Accuracy Computer Codes,
Technometrics, 55:1, 37-46, DOI: 10.1080/00401706.2012.72357
Formula
-------
.. math::
f_b(x, A, B) =
\dfrac{A*T_u*(H_u - H_l)}{\Bigg(\log(\frac{r}{r_w}) *
(B + \dfrac{2L*T_u}{\log(\frac{r}{r_w}) * r_w^2 * K_w} +
\dfrac{T_u}{T_l}\Bigg)}
.. math::
f_h(x) = f_b(x, 2\pi, 1)
.. math::
f_l(x) = f_b(x, 5, 1.5)
"""

num_dim: int = 8
Expand Down Expand Up @@ -848,18 +784,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_CurrinExp(MultiFidelityFunctions):
"""multi-fidelity CurrinExp function,
"""multi-fidelity CurrinExp function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/currinexp.html
"""

num_dim: int = 2
Expand Down Expand Up @@ -944,24 +875,12 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_Himmelblau(MultiFidelityFunctions):
"""multi-fidelity Himmelblau function,
"""multi-fidelity Himmelblau function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/himmel.html
Formula
-------
.. math::
f_h(x) = (x_1^2 + x_2 - 11)^2 + (x_1 + x_2^2 - 7)^2
.. math::
f_l(x_1, x_2) = f_h(0.5x_1, 0.8x_2) + x2^3 -(x1+1)^2
"""

num_dim: int = 2
Expand Down Expand Up @@ -1027,31 +946,13 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_Park91A(MultiFidelityFunctions):
"""multi-fidelity Park91A function,
"""multi-fidelity Park91A function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/park91a.html
Formula
-------
.. math::
f_h(x_1, x_2, x_3, x_4) = \dfrac{x_1}{2} \Bigg(\sqrt{1 + (x_2 + x_3^2) *
\dfrac{x_4}{x_1^2}} - 1\Bigg) +
(x_1 + 3x_4)\exp(1 + \sin(x_3))
.. math::
f_l(x_1, x_2, x_3, x_4) = (1+\sin(x_1) / 10)f_h(x_1, x_2, x_3, x_4) +
-2x_1 + x_2^2 + x_3^2 + 0.5
"""

num_dim: int = 4
Expand Down Expand Up @@ -1090,7 +991,7 @@ def lf(x: np.ndarray) -> np.ndarray:
x1 = x[:, 0]
x2 = x[:, 1]
x3 = x[:, 2]
x4 = x[:, 3]
# x4 = x[:, 3]

# calculate the terms
term1 = (1 + np.sin(x1) / 10).reshape((-1, 1))
Expand Down Expand Up @@ -1125,28 +1026,12 @@ def hf(x: np.ndarray) -> np.ndarray:


class mf_Park91B(MultiFidelityFunctions):
"""multi-fidelity Park91B function,
""" multi-fidelity Park91B function,
Parameters
----------
MultiFidelityFunctions : class
base class
Citation
--------
.. [1] https://www.sfu.ca/~ssurjano/park91b.html
Formula
-------
.. math::
f_h(x_1, x_2, x_3, x_4) = \dfrac{2}{3}\exp(x_1 + x_2) - x_4\sin(x_3) + x_3
.. math::
f_l(x_1, x_2, x_3, x_4) = 1.2f_h(x_1, x_2, x_3, x_4) - 1
"""

num_dim: int = 4
Expand All @@ -1166,8 +1051,8 @@ class mf_Park91B(MultiFidelityFunctions):
"x3": [0.0, 1.0],
"x4": [0.0, 1.0],
}
optimum: float = None
optimum_scheme: list = None
optimum: float = None # type: ignore
optimum_scheme: list = None # type : ignore
low_fidelity: bool = True

def __init__(self, num_dim: int = 4) -> None:
Expand Down
40 changes: 40 additions & 0 deletions tests/design_of_experiment/test_mf_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,43 @@ def test_lhs_unnested() -> None:
)
assert results_hf == pytest.approx(samples["hf"])
assert results_lf == pytest.approx(samples["lf"])


def test_1d_plot() -> None:
space = DesignSpace(
names=["x1"], low_bound=[0.0], high_bound=[1.0]
)
design_space = space.design_space
mf_sampler = MFLatinHyperCube(
design_space=design_space, seed=12, nested=False
)
mf_sampler.get_samples(num_lf_samples=4, num_hf_samples=2)
mf_sampler.plot_samples()
assert True


def test_2d_plot() -> None:
space = DesignSpace(
names=["x1", "x2"], low_bound=[0.0, 0.0], high_bound=[1.0, 1.0]
)
design_space = space.design_space
mf_sampler = MFLatinHyperCube(
design_space=design_space, seed=12, nested=False
)
mf_sampler.get_samples(num_lf_samples=4, num_hf_samples=2)
mf_sampler.plot_samples()
assert True


def test_3d_plot() -> None:
space = DesignSpace(
names=["x1", "x2", "x3"], low_bound=[0.0, 0.0, 0.0], high_bound=[1.0, 1.0, 1.0]
)
design_space = space.design_space
mf_sampler = MFLatinHyperCube(
design_space=design_space, seed=12, nested=False
)
mf_sampler.get_samples(num_lf_samples=4, num_hf_samples=2)

with pytest.raises(Exception):
mf_sampler.plot_samples()
28 changes: 28 additions & 0 deletions tests/design_of_experiment/test_sf_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,31 @@ def test_plot_samples_not_implemented():

with pytest.raises(NotImplementedError):
sampler.plot_samples()


def test_plotting_2d():
# Test plotting
design_space = OrderedDict({"x1": [0, 1], "x2": [0, 1]})
sampler = LatinHyperCube(design_space=design_space, seed=12)
sampler.get_samples(num_samples=10)
sampler.plot_samples()
assert True


def test_plotting_1d():
# Test plotting
design_space = OrderedDict({"x1": [0, 1]})
sampler = LatinHyperCube(design_space=design_space, seed=12)
sampler.get_samples(num_samples=10)
sampler.plot_samples()
assert True


def test_plotting_3d():
# Test plotting
design_space = OrderedDict({"x1": [0, 1], "x2": [0, 1], "x3": [0, 1]})
sampler = LatinHyperCube(design_space=design_space, seed=12)
sampler.get_samples(num_samples=10)

with pytest.raises(Exception):
sampler.plot_samples()
4 changes: 0 additions & 4 deletions tests/design_of_experiment/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ def test_inconsistent_lengths() -> None:

with pytest.raises(AssertionError):
design_space = DesignSpace(names, low_bound, high_bound)


if __name__ == "__main__": # pragma: no cover
pytest.main()
4 changes: 0 additions & 4 deletions tests/problems/test_mf_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ def test_forrester_1b() -> None:

assert results["lf"] == pytest.approx(sample_y["lf"])
assert results["hf"] == pytest.approx(sample_y["hf"])


if __name__ == "__main__": # pragma: no cover
pytest.main()
4 changes: 0 additions & 4 deletions tests/problems/test_sf_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ def test_brainin_function_values() -> None:
results = np.array([[21.59234798], [10.03613571], [154.75696146]])

assert results == pytest.approx(sample_y)


if __name__ == "__main__": # pragma: no cover
pytest.main()
Loading

0 comments on commit f7df45c

Please sign in to comment.