# Optimising an imperfect, high-dimensional simulation with experimental data

**URL:** <https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234>\
**Category:** Modelling & Simulations\
**Created:** [October 25, 2022, 6:31am UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234 "2022-10-25T06:31:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@duncan](https://discourse.julialang.org/u/duncan)\
**Post date:** [October 25, 2022, 6:31am UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/1 "2022-10-25T06:31:32Z")

</div>

I have used data from CFD simulations to create a Gaussian process surrogate of a mixing tank. The GP can estimate the reaction rate of the tank given a subset of the operating conditions, e.g. reagent concentration and impeller speed. However, my problem is that the underlying process is complex, involving the physicochemical interaction of three stages of matter. Therefore, the CFD simulations only approximate the actual behaviour, meaning the simulated dataset is somewhat idealistic.

I also have access to experimental reaction rate data of a similarly designed tank, although the data is likely very noisy. So my question is, what is the recommended approach for combining this experimental data with an imperfect simulator? I am currently considering pretraining a neural network with data from my simulator and finetuning the weights with the experimental data, but I would love any suggestions.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 25, 2022, 1:51pm UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/2 "2022-10-25T13:51:45Z")

</div>

Have you considered a Bayesian model with the existing neural network as predictor and some kind of simple model as a corrector, then learn the parameters of the corrector and you’d also get measures of uncertainty which might be useful rather than just a point estimate from the neural net.

---

<div class="post-metadata">

**Author:** ![duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@duncan](https://discourse.julialang.org/u/duncan)\
**Post date:** [October 25, 2022, 2:30pm UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/3 "2022-10-25T14:30:08Z")

</div>

Thanks for the response! Uncertainty quantification would be nice to have, especially considering my GP simulator already quantifies its uncertainty.

So is the corrector essentially a Bayesian model of the residuals between my simulator and the experimental data? If that’s the case, would my corrected model be the sum of the GP simulator and the Bayesian corrector?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 25, 2022, 3:29pm UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/4 "2022-10-25T15:29:12Z")

</div>

There is a wide literature on scientific machine learning trying to grapple with the best way to combine models and data. The answer depends on the circumstance, and even then it’s often still an open question what the best solution is.

However, in your case I would suggest looking into something like neural ODEs (or neural PDEs in your case). The goal is to keep as much of your trusted CFD model as possible, and only put a neural network into a small piece, e.g. for the unknown physicochemical interaction (presumably some local equation of state) — then you train the NN by minimizing error against experimental data end-to-end against the output of your NN-augmented CFD model.

@ChrisRackauckas does quite a bit of this sort of thing, and you might look into some of his papers on the topic as well as his [DiffEqFlux.jl package](https://diffeqflux.sciml.ai/stable/).

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 25, 2022, 3:50pm UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/5 "2022-10-25T15:50:16Z")

</div>

> [@duncan](#):
>
> o is the corrector essentially a Bayesian model of the residuals between my simulator and the experimental data? If that’s the case, would my corrected model be the sum of the GP simulator and the Bayesian corrector

Yes that’s what I was thinking of though it’s hard to make specific suggestions without knowing more details in particular I was thinking that the space in which you are fitting is the space of not some cfd output but some summary such as the overall reaction rate.

---

<div class="post-metadata">

**Author:** ![duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@duncan](https://discourse.julialang.org/u/duncan)\
**Post date:** [October 25, 2022, 11:49pm UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/6 "2022-10-25T23:49:30Z")

</div>

Thanks for the suggestion! Neural PDEs sound like an excellent option for my use case. Although, I guess the challenge will be embedding the NN into my current CFD code. I’m using OpenFOAM for my simulation, and I don’t know how this integrates with the [DiffEqFlux.jl package](https://diffeqflux.sciml.ai/stable/).

For now, I’ll try @dlakelan’s suggestion since it is relatively straightforward to implement; however, I’m very keen to explore the development of an NN-augmented CFD model.

I appreciate the help!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 26, 2022, 12:00am UTC](https://discourse.julialang.org/t/optimising-an-imperfect-high-dimensional-simulation-with-experimental-data/89234/7 "2022-10-26T00:00:15Z")

</div>

> [@duncan](#):
>
> I’m using OpenFOAM for my simulation, and I don’t know how this integrates with the [DiffEqFlux.jl package](https://diffeqflux.sciml.ai/stable/).

Ouch, backpropagating sensitivities through someone else’s huge C++ CFD code is not for the faint of heart.
