Skip to content
Snippets Groups Projects
Commit bd6ad3f2 authored by kohlhaasrebecca's avatar kohlhaasrebecca
Browse files

Small fixes, start on ModelComp without MetaModel

parent 586f86e7
No related branches found
No related tags found
1 merge request!29Preparation for release 1.1.0: fixes and test for pages
Showing
with 176 additions and 3307 deletions
docs/logo/BVRLogoV03.png

35.5 KiB

docs/logo/BVRLogoV03_longtext.png

100 KiB

docs/logo/BVRLogoV03_shorttext.png

79.3 KiB

......@@ -22,7 +22,12 @@ import scipy.io as io
import pandas as pd
import joblib
import sys
<<<<<<< HEAD
sys.path.append("../../src/bayesvalidrox/")
=======
#sys.path.append("../../src/bayesvalidrox/")
sys.path.append("../../src/")
>>>>>>> 99013313 (Small fixes, start on ModelComp without MetaModel)
from bayesvalidrox.pylink.pylink import PyLinkForwardModel
from bayesvalidrox.surrogate_models.inputs import Input
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This is a simple linear model.
The code for this numerical experiments is available at
https://github.com/MichaelSinsbeck/paper_sequential-design-model-selection.
Author: Farid Mohammadi, M.Sc.
E-Mail: farid.mohammadi@iws.uni-stuttgart.de
Department of Hydromechanics and Modelling of Hydrosystems (LH2)
Institute for Modelling Hydraulic and Environmental Systems (IWS),
University of Stuttgart, www.iws.uni-stuttgart.de/lh2/
Pfaffenwaldring 61
70569 Stuttgart
Created on Fri Oct 8 2021
"""
import numpy as np
def L2_model(xx):
"""
Linear model y = a*x+b
Models adapted from Anneli Guthke's paper:
ch€oniger, A., T. W€ohling, L. Samaniego,and W. Nowak (2014), Model
selection on solid ground: Rigorous comparison ofnine ways to evaluate
Bayesian modelevidence,Water Resour. Res.,50,9484–9513,
doi:10.1002/2014WR016062
Parameters
----------
xx : array
Parameters a and b.
Returns
-------
2D-array
The first row contains the measurement locations.
The second row contains the model outputs.
"""
n_output = 15
meas_loc = np.linspace(0.25, 4.75, n_output)
# L2_model
L2_model = xx[:, 0] * meas_loc + xx[:, 1]
# Output
output = {
'x_values': meas_loc,
'Z': L2_model
}
return output
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This is a nonlinear cosine model.
The code for this numerical experiments is available at
https://github.com/MichaelSinsbeck/paper_sequential-design-model-selection.
Author: Farid Mohammadi, M.Sc.
E-Mail: farid.mohammadi@iws.uni-stuttgart.de
Department of Hydromechanics and Modelling of Hydrosystems (LH2)
Institute for Modelling Hydraulic and Environmental Systems (IWS),
University of Stuttgart, www.iws.uni-stuttgart.de/lh2/
Pfaffenwaldring 61
70569 Stuttgart
Created on Fri Oct 8 2021
"""
import numpy as np
def NL2_model(xx):
"""
Nonlinear model y = exp(a*x) + b
Models adapted from Anneli Guthke's paper:
ch€oniger, A., T. W€ohling, L. Samaniego,and W. Nowak (2014), Model
selection on solid ground: Rigorous comparison ofnine ways to evaluate
Bayesian modelevidence,Water Resour. Res.,50,9484–9513,
doi:10.1002/2014WR016062
Parameters
----------
xx : array
Parameters a and b.
Returns
-------
2D-array
The first row contains the measurement locations.
The second row contains the model outputs.
"""
n_output = 15
meas_loc = np.linspace(0.25, 4.75, n_output)
# NL2_model
NL2_model = np.exp(xx[:, 0] * meas_loc) + xx[:, 1]
# Output
output = {
'x_values': meas_loc,
'Z': NL2_model
}
return output
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This is a nonlinear cosine model.
The code for this numerical experiments is available at
https://github.com/MichaelSinsbeck/paper_sequential-design-model-selection.
Author: Farid Mohammadi, M.Sc.
E-Mail: farid.mohammadi@iws.uni-stuttgart.de
Department of Hydromechanics and Modelling of Hydrosystems (LH2)
Institute for Modelling Hydraulic and Environmental Systems (IWS),
University of Stuttgart, www.iws.uni-stuttgart.de/lh2/
Pfaffenwaldring 61
70569 Stuttgart
Created on Fri Oct 8 2021
"""
import numpy as np
def NL4_model(xx):
"""
Nonlinear model y = a*cos(b*x+c)+d
Models adapted from Anneli Guthke's paper:
ch€oniger, A., T. W€ohling, L. Samaniego,and W. Nowak (2014), Model
selection on solid ground: Rigorous comparison ofnine ways to evaluate
Bayesian modelevidence,Water Resour. Res.,50,9484–9513,
doi:10.1002/2014WR016062
Parameters
----------
xx : array
Parameters a and b.
Returns
-------
2D-array
The first row contains the measurement locations.
The second row contains the model outputs.
"""
n_output = 15
meas_loc = np.linspace(0.25, 4.75, n_output)
# NL4_model
NL4_model = xx[:, 0] * np.cos(xx[:, 1] * meas_loc + xx[:, 2]) + xx[:, 3]
# Output
output = {
'x_values': meas_loc,
'Z': NL4_model
}
return output
# -*- coding: utf-8 -*-
__version__ = "0.0.5"
from .pylink.pylink import PyLinkForwardModel
from .surrogate_models.surrogate_models import MetaModel
from .surrogate_models.meta_model_engine import MetaModelEngine
from .surrogate_models.inputs import Input
from .post_processing.post_processing import PostProcessing
from .bayes_inference.bayes_inference import BayesInference
from .bayes_inference.bayes_model_comparison import BayesModelComparison
from .bayes_inference.discrepancy import Discrepancy
__all__ = [
"__version__",
"PyLinkForwardModel",
"Input",
"Discrepancy",
"MetaModel",
"MetaModelEngine",
"PostProcessing",
"BayesInference",
"BayesModelComparison"
]
File deleted
# -*- coding: utf-8 -*-
from .bayes_inference import BayesInference
from .mcmc import MCMC
__all__ = [
"BayesInference",
"MCMC"
]
File deleted
File deleted
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import scipy.stats as stats
from bayesvalidrox.surrogate_models.exp_designs import ExpDesigns
class Discrepancy:
"""
Discrepancy class for Bayesian inference method.
We define the reference or reality to be equal to what we can model and a
descripancy term \\( \\epsilon \\). We consider the followin format:
$$\\textbf{y}_{\\text{reality}} = \\mathcal{M}(\\theta) + \\epsilon,$$
where \\( \\epsilon \\in R^{N_{out}} \\) represents the the effects of
measurement error and model inaccuracy. For simplicity, it can be defined
as an additive Gaussian disrepancy with zeromean and given covariance
matrix \\( \\Sigma \\):
$$\\epsilon \\sim \\mathcal{N}(\\epsilon|0, \\Sigma). $$
In the context of model inversion or calibration, an observation point
\\( \\textbf{y}_i \\in \\mathcal{y} \\) is a realization of a Gaussian
distribution with mean value of \\(\\mathcal{M}(\\theta) \\) and covariance
matrix of \\( \\Sigma \\).
$$ p(\\textbf{y}|\\theta) = \\mathcal{N}(\\textbf{y}|\\mathcal{M}
(\\theta))$$
The following options are available:
* Option A: With known redidual covariance matrix \\(\\Sigma\\) for
independent measurements.
* Option B: With unknown redidual covariance matrix \\(\\Sigma\\),
paramethrized as \\(\\Sigma(\\theta_{\\epsilon})=\\sigma^2 \\textbf{I}_
{N_{out}}\\) with unknown residual variances \\(\\sigma^2\\).
This term will be jointly infer with the uncertain input parameters. For
the inversion, you need to define a prior marginal via `Input` class. Note
that \\(\\sigma^2\\) is only a single scalar multiplier for the diagonal
entries of the covariance matrix \\(\\Sigma\\).
Attributes
----------
InputDisc : obj
Input object. When the \\(\\sigma^2\\) is expected to be inferred
jointly with the parameters (`Option B`).If multiple output groups are
defined by `Model.Output.names`, each model output needs to have.
a prior marginal using the `Input` class. The default is `''`.
disc_type : str
Type of the noise definition. `'Gaussian'` is only supported so far.
parameters : dict or pandas.DataFrame
Known residual variance \\(\\sigma^2\\), i.e. diagonal entry of the
covariance matrix of the multivariate normal likelihood in case of
`Option A`.
"""
def __init__(self, InputDisc='', disc_type='Gaussian', parameters=None):
self.InputDisc = InputDisc
self.disc_type = disc_type
self.parameters = parameters
# -------------------------------------------------------------------------
def get_sample(self, n_samples):
"""
Generate samples for the \\(\\sigma^2\\), i.e. the diagonal entries of
the variance-covariance matrix in the multivariate normal distribution.
Parameters
----------
n_samples : int
Number of samples (parameter sets).
Returns
-------
sigma2_prior: array of shape (n_samples, n_params)
\\(\\sigma^2\\) samples.
"""
self.n_samples = n_samples
ExpDesign = ExpDesigns(self.InputDisc)
self.sigma2_prior = ExpDesign.generate_ED(
n_samples, sampling_method='random', max_pce_deg=1
)
# Store BoundTuples
self.ExpDesign = ExpDesign
# Naive approach: Fit a gaussian kernel to the provided data
self.ExpDesign.JDist = stats.gaussian_kde(ExpDesign.raw_data)
# Save the names of sigmas
if len(self.InputDisc.Marginals) != 0:
self.name = []
for Marginalidx in range(len(self.InputDisc.Marginals)):
self.name.append(self.InputDisc.Marginals[Marginalidx].name)
return self.sigma2_prior
This diff is collapsed.
figure.titlesize : 30
axes.titlesize : 30
axes.labelsize : 30
axes.linewidth : 3
axes.grid : True
lines.linewidth : 3
lines.markersize : 10
xtick.labelsize : 30
ytick.labelsize : 30
legend.fontsize : 30
font.family : serif
font.serif : Arial
font.size : 30
text.usetex : True
grid.linestyle : -
figure.figsize : 24, 16
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment