Variance-based sensitivity analysis for parameter reconstruction
- Driver:
- Download script:
An important question in the context of parameter reconstruction is how to set up an experimental measurement in order to retrieve enough meaningful information for the accurate reconstruction of the parameters that are of interest. As a specific example the MGH17 problem from the NIST statistical reference datasets is considered. It consists of fitting a vectorial model \(\mathbf{f}(\mathbf{b}) \in \mathbb{R}^{33}\) with
to a measurement vector with 33 entries.
If a specific measurement \(f_k(\mathbf{b})\) depends sensitively on a parameter \(b_j\), it enables a more accurate reconstruction of \(b_j\) than a measurement that hardly depends on the parameter. A way to quantify this sensitivity is the variance-based sensitivity analysis, also referred to as Sobol’ method. The first-order Sobol’ coefficients \(S_{jk}\) with \(j=1\dots,5\) and \(k=1\dots,33\) measure the variance of \(f_k(\mathbf{b})\) when changing a specific parameter \(b_j\), averaged over the value of all other parameters.
In out blog entry on sensitivity analysis we show that the relative variance
is a measure of how well a parameter \(b_j\) can be reconstructed from the measurement channel \(k\) on average (independent of a specific vector of measurements). The variance of a uniformly distributed parameter \(b_j \in [b_j^{\rm lower}, b_j^{\rm upper}]\) is given as \((b_j^{\rm upper} - b_j^{\rm lower})^2/12\).
The model variance \({\rm Var}[f_k]\) and the Sobol’ indices \(S_{jk}\) can be determined using Monte Carlo sampling. If the numerical model of the measurement is expensive, it is numerically more efficient to train a surrogate model of \(\mathbf{f}(\mathbf{b})\) and do the Monte Carlo sampling on the trained model instead. Here, we train a Gaussian process by iteratively sampling the model at positions of the largest uncertainty of the Gaussian process prediction.
1import sys,os
2import numpy as np
3import time
4import torch
5import matplotlib.pyplot as plt
6
7
8jcm_optimizer_path = r"<JCM_OPTIMIZER_PATH>"
9sys.path.insert(0, os.path.join(jcm_optimizer_path, "interface", "python"))
10from jcmoptimizer import Server, Client, Study, Observation
11server = Server()
12client = Client(server.host)
13
14# Definition of the search domain
15design_space = [
16 {'name': 'b1', 'type': 'continuous', 'domain': (0,10)},
17 {'name': 'b2', 'type': 'continuous', 'domain': (0.1,4)},
18 {'name': 'b3', 'type': 'continuous', 'domain': (-4,-0.1)},
19 {'name': 'b4', 'type': 'continuous', 'domain': (0.05,1)},
20 {'name': 'b5', 'type': 'continuous', 'domain': (0.05,1)}
21]
22
23# Creation of the study object with study_id 'sensitivity_analysis'
24study = client.create_study(
25 design_space=design_space,
26 driver="ActiveLearning",
27 name="Variance-based sensitivity analysis for parameter reconstruction",
28 study_id="sensitivity_analysis"
29)
30#The vectorial model function of the MGH17 problem
31def model(x: torch.Tensor) -> torch.Tensor:
32 s = torch.arange(33)
33 return x[0] + x[1]*torch.exp(-s*x[3]) + x[2]*torch.exp(-s*x[4])
34
35study.configure(
36 max_iter = 100,
37 surrogates = [
38 #A multi-output Gaussian process that learns the dependence of
39 #the model on the design parameters.
40 dict(type="GP", name="model_vector", output_dim=33,
41 correlate_outputs=False)
42 ],
43 variables = [
44 #The mean of the model vector.
45 dict(type="LinearCombination", name="model_average",
46 inputs=["model_vector"])
47 ],
48 objectives = [
49 #The objective is to sample the model at positions of maximal
50 #uncertainty of the model average.
51 dict(type="Explorer", variable="model_average",
52 penalize_boundaries=True, min_uncertainty=1e-3)
53 ],
54)
55
56# Evaluation of the black-box function for specified design parameters
57def evaluate(study: Study, b1: float, b2: float, b3: float, b4: float, b5: float) -> Observation:
58
59 time.sleep(2) # make objective expensive
60 observation = study.new_observation()
61 #tensor of design values to reconstruct
62 x = torch.tensor([b1, b2, b3, b4, b5])
63 observation.add(model(x).tolist())
64
65 return observation
66
67# Run the minimization
68study.set_evaluator(evaluate)
69study.run()
70sobol_indices = study.driver.get_sobol_indices(
71 object_type="surrogate",
72 name="model_vector",
73 max_uncertainty=0.001
74)
75variances = torch.tensor(sobol_indices["variance"])
76sobol_values = torch.tensor(sobol_indices["first_order"])
77
78
79fig = plt.figure(figsize=(10,5))
80fig, (ax1,ax2) = plt.subplots(nrows=2, sharex=True,
81 figsize=(10,5))
82
83for idx, info in enumerate(design_space):
84 ax1.plot(sobol_values[idx], ".-", label=info['name'])
85
86 #variance of uniform distribution of the parameter
87 var_p = (info['domain'][1]-info['domain'][0])**2/12
88 scaled_var = variances*sobol_values[idx]/var_p
89 ax2.plot(scaled_var, ".-", label=info['name'])
90
91ax1.set_ylabel("First-order Sobol' index")
92ax1.legend()
93ax1.grid()
94
95ax2.set_xlabel("Model vector index")
96ax2.set_ylabel("Scaled variance")
97ax2.grid()
98plt.savefig("variance_sobol.svg", transparent=True)
99
Sensitivity analysis for parameter reconstruction
The upper graph shows the first-order Sobol’ coefficients for each parameter \(b_j\) and each channel \(k.\) Clearly, the largest variance of \(\mathbf{f}(\mathbf{b})\) stems from variations of \(b_1\). Note that, due to the symmetric definition of \(b_2, b_3\) and \(b_4, b_5\), respectively, some lines are on top of each other.
The lower graph shows the relative variance \(c_{jk}\) for each parameter \(b_j\) and each channel \(k\) reflecting the amount of information for the reconstruction of each parameter. Regarding the sum of information over \(k\), the parameters \(b_1, b_4\) and \(b_5\) can be reconstructed most accurately. The parameters \(b_2\) and \(b_3\) are harder to reconstruct. Most information is given by small channel numbers.
These results agree well with the certified reconstruction uncertainties \(\Delta_1=2.07 \cdot 10^{-3}\), \(\Delta_2=0.220\), \(\Delta_3=0.222\), \(\Delta_4=4.49\cdot 10^{-3}\), \(\Delta_5=8.95 \cdot 10^{-3}\) for a specific MGH17 measurement vector.