Skip to article frontmatterSkip to article content

5. Multiple sensors and correlations

Authors
Affiliations
TNO
TNO
TNO

Imports

import numpy as np

# Problem definition
from probeye.definition.inverse_problem import InverseProblem
from probeye.definition.forward_model import ForwardModelBase
from probeye.definition.distribution import Normal
from probeye.definition.sensor import Sensor
from probeye.definition.likelihood_model import GaussianLikelihoodModel
from probeye.definition.correlation_model import ExpModel

# Inference
from probeye.inference.emcee.solver import EmceeSolver

# Postprocessing
from probeye.postprocessing.sampling_plots import create_posterior_plot

Problem setup

# Fixed parameters
I = 1e9  # mm^4
L = 10_000  # mm
Q = 100  # kN

# Measurements
x_sensors = [2500, 5000]  # mm  (always from lower to higher, bug in inv_cov_vec_1D in tripy)
d_sensors = [35, 50]  # mm
sigma_model = 10  # mm
pearson = 0.5
l_corr = -np.abs(x_sensors[1] - x_sensors[0]) / np.log(pearson)  # mm (assuming exponential correlation)

# Prior
E_mean = 60  # GPa
E_std = 20  # GPa

Define forward model

def beam_deflection(E, x):  # x is sensor position
    return Q * x * (3 * L ** 2 - 4 * x ** 2) / (48 * E * I)
## Write your code where the three dots are

class BeamModel(ForwardModelBase):
    def interface(self):
        self.parameters = ...
        self.input_sensors = ...
        self.output_sensors = ...

    def response(self, inp: dict) -> dict:
        E = ...
        x = ...
        return {"y": [beam_deflection(..., float(x[0])), beam_deflection(..., float(x[1]))]}  # float() needed, probably a bug in probeye

Define inverse problem

## Write your code where the three dots are

# Instantiate the inverse problem
problem = InverseProblem(...)

# Add latent parameters
problem.add_parameter(...)

# Add fixed parameters
problem.add_parameter(...)
problem.add_parameter(...)  # Correlation length parameter

# Add measurement data
problem.add_experiment(...)
                 
# Add forward model
problem.add_forward_model(...)

# Add likelihood model
likelihood_model = GaussianLikelihoodModel(...)  # Include correlation model
problem.add_likelihood_model(likelihood_model)

Solve with MCMC

emcee_solver = EmceeSolver(problem, show_progress=True)
inference_data = emcee_solver.run(n_steps=2000, n_initial_steps=2000)

Plot

post_plot_array = create_posterior_plot(
    inference_data,
    emcee_solver.problem,
    kind="kde",
    title="Kernel density estimate of the posterior distribution",
)