Inverse problem in chemical engineering -...

26
Inverse problem in chemical engineering Consider the reversible chemical reactions A B, with reaction rates k 1 and k 2 , respectively. Concentrations C A and C B satisfy dC A dt = -k 1 C A + k 2 C B dC B dt = k 1 C A - k 2 C B , with initial data C A (0) = C A,0 , C B (0) = C b,0 . 0-0

Transcript of Inverse problem in chemical engineering -...

Page 1: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Inverse problem in chemical engineering

Consider the reversible chemical reactions

A À B,

with reaction rates k1 and k2, respectively.

Concentrations CA and CB satisfy

dCA

dt= −k1CA + k2CB

dCB

dt= k1CA − k2CB ,

with initial dataCA(0) = CA,0, CB(0) = Cb,0.

0-0

Page 2: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Inverse problem

Assume that we know the initial concentrations.

Data: For 0 < t1 < t2 · · · < tn, measure CA(tj), 1 ≤ j ≤ n.

Estimate k1 and k2.

Noisy observations:

bj = CA(tj) + ej , ej ∼ N (0, σ2).

0-1

Page 3: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

analytic solution

Define

x(t) =[

CA(t)CB(t)

], M =

[ −k1 k2

k1 −k2

].

Dynamic systemdxdt

= Mx, x(0) = x0.

Solution can be written asx = eMtx0.

0-2

Page 4: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Eigenvalue decomposition:

det(M − λI) =

∣∣∣∣−k1 − λ k2

k1 −k2 − λ

∣∣∣∣ = 0,

orλ2 + (k1 + k2)λ = 0.

Eigenvalues are

λ1 = 0, λ2 = −(k1 + k2) = −1τ

.

0-3

Page 5: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Corresponding eigenvectors:

Mv = 0 ⇔{ −k1v1 + k2v2 = 0

k1v1 − k2v2 = 0 ⇔ v2 =k1

k2v1.

Similarly,

Mv = −1τv ⇔

{ −k1v1 + k2v2 = −(k1 + k2)v1

k1v1 − k2v2 = −(k1 + k2)v2⇔ v2 = −v1.

0-4

Page 6: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Solution: denoting δ = k1/k2,

x(t) = α

[1δ

]+ β

[1

−1

]e−t/τ .

Initial values: {α + β = CA,0

δα− β = CB,0,

leading to

α =1

1 + δ(CA,0 + CB,0), β =

δ

1 + δ(CA,0 + CB,0)− CB,0.

0-5

Page 7: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Data

bj =1

1 + δ(CA,0 + CB,0) +

1 + δ(CA,0 + CB,0)− CB,0

)e−tj/τ + ej .

Does it matter when we measure?

Yes: observe that as t →∞,

CA(t) → 11 + δ

(CA,0 + CB,0),

i.e., at large times, the data depends only on the ratio

δ =k1

k2.

0-6

Page 8: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Transient data and steady state data

0 1 2 3 40

0.5

1

1.5

2

2.5

3

3.5

0 1 2 3 40

0.5

1

1.5

2

2.5

3

3.5

CA,0 = 2, CB,0 = 1, k1 = 2, k2 = 0.5, σ = 0.2

τ = 0.4 ⇒ e−t/τ < 0.01, as t > 1.8.

0-7

Page 9: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Likelihood density

bj = A(tj ,k) + ej ,

where

A(tj ,k) =1

1 + δ(CA,0 + CB,0) +

1 + δ(CA,0 + CB,0)− CB,0

)e−tj/τ ,

andτ =

1k1 + k2

δ =k1

k2.

Likelihood density is

π(b | k) ∝ exp

− 1

2σ2

n∑

j=1

(bj −A(tj ,k))2

.

0-8

Page 10: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Posterior density

Flat prior over an interval: assume that we believe that

0 < k1 ≤ K1, 0 < k2 ≤ K2,

with some reasonable upper bounds. Write

πprior(k) ∝ χ[0,K1](k1)χ[0,K2](k2).

Posterior density by Bayes’ formula,

π(k | b) ∝ πprior(k)π(b | k).

Contour plots of the posterior density?

0-9

Page 11: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Posterior densities

Different measurement intervals: K1 = 6, K2 = 2,

0.1τ ≤ t ≤ 4.1τ (left) , 5τ ≤ t ≤ 9τ (right)

0-10

Page 12: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Random walk Metropolis-Hastings

Start with the transient measurements.

White noise proposal,

kprop = k + δw, w ∼ N (0, I).

Choose first δ = 0.1, different initial points

k0 = (1, 2) or k0 = (5, 0.1).

Relative acceptance rates are of the order 45%.

0-11

Page 13: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

nsample = 10000;k = [1;2]; % Initial pointnacc = 0;step = 0.1; % Step size of the random walkSample = zeros(2,nsample); Sample(:,1) = k; logpdf =logpdf_func(k,A0,B0,Aj,tj,sigma); nacc = 0; for j = 2:nsample

k_prop = k + step*randn(2,1);logpdf_prop = logpdf_func(k_prop,A0,B0,Aj,tj,sigma);if logpdf_prop - logpdf > log(rand);

% Accept the proposalk = k_prop;logpdf = logpdf_prop;nacc = nacc + 1;

endSample(:,j) = k;

end

0-12

Page 14: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

function logpdf = logpdf_func(k,A0,B0,Aj,t,sigma);

tau = 1/(k(1) + k(2));delta = k(1)/k(2);alpha = (A0 + B0)/(1 + delta);beta = delta*alpha - B0;A = alpha + beta*exp(-1/tau*t);logpdf = -1/(2*sigma^2)*norm(A - Aj);

0-13

Page 15: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Scatter plots

1 2 3 4 50

0.5

1

1.5

2

2.5

1 2 3 4 5 60

0.5

1

1.5

2

0-14

Page 16: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

First component

0 2000 4000 6000 8000 100001

2

3

4

5

0 2000 4000 6000 8000 100001

2

3

4

5

6

Initial value k1 = 1 (left) and k1 = 5 (right).

0-15

Page 17: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Second component

0 2000 4000 6000 8000 100000

0.5

1

1.5

2

2.5

0 2000 4000 6000 8000 100000

0.5

1

1.5

2

Initial value k2 = 2 (left) and k2 = 0.2 (right).

0-16

Page 18: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Burn-in: first component

0 100 200 300 400 5001

1.5

2

2.5

3

0 100 200 300 400 5002

2.5

3

3.5

4

4.5

5

5.5

Initial value k1 = 1 (left) and k1 = 5 (right).

0-17

Page 19: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Burn-in: Second component

0 100 200 300 400 5000

0.5

1

1.5

2

2.5

0 100 200 300 400 5000

0.5

1

1.5

2

Initial value k2 = 2 (left) and k2 = 0.2 (right).

0-18

Page 20: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Steady state measurement

Use the same step size.

Initial point (k1, k2) = (1, 2).

0-19

Page 21: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Scatter plots

0 5 10 15 200

1

2

3

4

0-20

Page 22: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Fuzzy worms

0 2000 4000 6000 8000 100000

5

10

15

20

0 2000 4000 6000 8000 100000

0.5

1

1.5

2

2.5

3

3.5

4

0-21

Page 23: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Steady state measurement, again

Increase the step size 0.1 → 1.

Initial point (k1, k2) = (1, 2).

Acceptance remains high, about 55%

0-22

Page 24: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Scatter plots

0 10 20 30 40 50 60 700

5

10

15

20

0-23

Page 25: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

Fuzzy worms

0 2000 4000 6000 8000 100000

10

20

30

40

50

60

70

0 2000 4000 6000 8000 100000

5

10

15

20

0-24

Page 26: Inverse problem in chemical engineering - math.tkk.fimath.tkk.fi/opetus/inv2007/ChemEngExample.pdfInverse problem in chemical engineering Consider the reversible chemical reactions

What did we learn?

• Statistical approach helps in experiment design

• To identify the burn-in, try multiple starts

• If the sample histories are “walking”, try longer steps: maybe you arejust explring too slowly the distribution

• If the samples continue to walk, maybe you are exploring an improperdensity. You need more information: better prior, new observations,different measurement setting?

0-25