Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A. Falling object problem

This notebook provides the full implementation of the falling object problem discussed in 5. Computational UQ: the need for sampling, which the reader is referred to for more details, particularly on the influence of priors. We demonstrate performing Bayesian inference with CUQIpy on a simple physical model of a falling object with air resistance. We estimate the gravitational acceleration g and the air resistance coefficient C from noisy measurements of the object’s fall distance over time. Our considered problem is a simplified version of that described in Allmaras et al. (2013).

1. Import necessary packages

2. Define forward model and synthetic measurement

<Figure size 400x300 with 1 Axes>

3. Define priors

We have three alternatives here:

1. Uniform Prior:

p(x)=Uniform(g,C∣g∈[8,12], C∈[0.01,0.25])p(\mathbf{x}) = \text{Uniform}(g, C \mid g \in [8, 12], \, C \in [0.01, 0.25])

2. Truncated Normal Prior:

p(x)=Ntrunc(μ,Σ, a,b)p(\mathbf{x}) = \mathcal{N}_{\text{trunc}}\left(\boldsymbol{\mu}, \boldsymbol{\Sigma}, \, \mathbf{a}, \mathbf{b}\right)

where μ=[11.0,0.1]T\boldsymbol{\mu} = [11.0, 0.1]^T, Σ=diag([0.22,0.22])\boldsymbol{\Sigma} = \text{diag}([0.2^2, 0.2^2]), a=[8.0,0.01]T\mathbf{a} = [8.0, 0.01]^T, and b=[12.0,0.25]T\mathbf{b} = [12.0, 0.25]^T.

3. Truncated Normal Prior:

p(x)=Ntrunc(μ,Σ, a,b)p(\mathbf{x}) = \mathcal{N}_{\text{trunc}}\left(\boldsymbol{\mu}, \boldsymbol{\Sigma}, \, \mathbf{a}, \mathbf{b}\right)

where μ=[11.0,0.1]T\boldsymbol{\mu} = [11.0, 0.1]^T, Σ=diag([22,22])\boldsymbol{\Sigma} = \text{diag}([2^2, 2^2]), a=[8.0,0.01]T\mathbf{a} = [8.0, 0.01]^T, and b=[12.0,0.25]T\mathbf{b} = [12.0, 0.25]^T.

Here, we choose to demonstrate the uniform prior, but the reader can try other prior alternatives by commenting out the uniform prior code and uncommenting the desired prior below.

4. Define likelihood and posterior

5. Sample from posterior

Warmup:   0%|          | 0/10000 [00:00<?, ?it/s, acc rate: 21.05%] /var/folders/6l/nx63qk9s1l7gst1rbgdfb5vc0000gp/T/ipykernel_31607/3367461526.py:10: RuntimeWarning: invalid value encountered in sqrt
  v_inf = np.sqrt(g / C)
Warmup: 100%|██████████| 10000/10000 [00:06<00:00, 1571.88it/s, acc rate: 24.50%]
Sample: 100%|██████████| 20000/20000 [00:14<00:00, 1375.13it/s, acc rate: 23.73%]
array([[<Axes: title={'center': 'x0'}>, <Axes: title={'center': 'x0'}>], [<Axes: title={'center': 'x1'}>, <Axes: title={'center': 'x1'}>]], dtype=object)
<Figure size 1200x400 with 4 Axes>

6. Compute MAP

MAP estimate: [9.86909618 0.10778037]

7. Plots of samples and density

<Figure size 400x300 with 1 Axes>
<Figure size 400x300 with 1 Axes>
References
  1. Allmaras, M., Bangerth, W., Linhart, J. M., Polanco, J., Wang, F., Wang, K., Webster, J., & Zedler, S. (2013). Estimating parameters in physical models through Bayesian inversion: A complete example. SIAM Review, 55(1), 149–167.