8. MonteCarlo

59
Biomedical Optics II 生生生生生生 II Monte Carlo Modeling of Photon Transport 2011/09/28

description

monte carlo

Transcript of 8. MonteCarlo

Page 1: 8. MonteCarlo

Biomedical Optics II生物医学光学 II

Monte Carlo Modeling of Photon Transport

2011/09/28

Page 2: 8. MonteCarlo

2

Radiative Transfer in Living Tissue

College of Engineering, Peking University 生物医学光学 II

How to solve the problem?

Maxwell’s equations?

Modeling based on scattering

and absorption

Monte Carlo simulation

Radiative transfer

equation

Page 3: 8. MonteCarlo

3

Monte Carlo

College of Engineering, Peking University 生物医学光学 II

Page 4: 8. MonteCarlo

4College of Engineering, Peking University 生物医学光学 II

Page 5: 8. MonteCarlo

5College of Engineering, Peking University 生物医学光学 II

Page 6: 8. MonteCarlo

6

The simulations treat photons as neutral particles rather than as a wave phenomenon.

It is assumed that the photons are multiply scattered by tissues. Sometimes, phase and polarization are assumed to be randomized and can be ignored.

Monte Carlo Simulations

College of Engineering, Peking University 生物医学光学 II

Page 7: 8. MonteCarlo

7

Photon transport in biological tissue can be numerically simulated by the Monte Carlo method.

The trajectory of a photon is modeled as a persistent random walk, with the direction of each step depending on that of the previous step.

By contrast, the directions of all of the steps in a simple random walk are independent.

By tracking a sufficient number of photons, we can estimate physical quantities such as diffuse reflectance.

Introduction

College of Engineering, Peking University 生物医学光学 II

Page 8: 8. MonteCarlo

8

The medium is random Use “dice” to build it⇒

A system with known probability distributions (scattering and absorption)

Monte Carlo

College of Engineering, Peking University 生物医学光学 II

Page 9: 8. MonteCarlo

9

From Lux and Koblinger: In all applications of the Monte Carlo method, a

stochastic model is constructed in which the expected value of a certain random variable (or of a combination of several variables) is equivalent to the value of a physical quantity to be determined.

This expected value is then estimated by the average of multiple independent samples representing the random variable introduced above.

For the construction of the series of independent samples, random numbers following the distribution of the variable to be estimated are used.

Definition of Monte Carlo Method

College of Engineering, Peking University 生物医学光学 II

Page 10: 8. MonteCarlo

10

The photon propagation is random and determined by tissue optical properties:

1. Distance to next scattering event? Apply "dice" with properties set by the mean free-path-length (determined by the scattering and absorption coefficients) to set the path length before a scattering or an absorption event occur.

2. Direction after scattering? Apply "dice" with phase function + anisotropy of scattering to set the scattering angles.

College of Engineering, Peking University 生物医学光学 II

Page 11: 8. MonteCarlo

11

Main advantage

No limitation concerning boundary conditions or spatial localisation of inhomogeneities in the tissue >> Flexiblility

Main disadvantage

Problem of getting good statistics, particularly if the point of interest is located far away from the point of entry of the light and the scattering and absorption coefficients are high >> long CPU time

College of Engineering, Peking University 生物医学光学 II

Page 12: 8. MonteCarlo

12

It is important to realize that the Monte Carlo method estimates ensemble-averaged quantities.

An ensemble of biological tissues is modeled for the average characteristics of photon transport; the ensemble consists of all instances of the tissues that are microscopically different but macroscopically identical.

Rules are defined for photon propagation from the probability distributions of, for example, the angles of scattering and the step sizes.

The statistical nature requires tracking a large number of photons, which is computationally time-consuming.

Multiple physical quantities can be simultaneously estimated, however.

Ensemble Averaging

College of Engineering, Peking University 生物医学光学 II

Page 13: 8. MonteCarlo

13

In this chapter, photons are treated as waves at each scattering site but as classical particles elsewhere.

Coherence, polarization, and nonlinearity are neglected.

Structural anisotropy--not to be confused with scattering angular anisotropy--in tissue components, such as muscle fibers or collagens, is neglected as well.

Simplifications

College of Engineering, Peking University 生物医学光学 II

Page 14: 8. MonteCarlo

14

Determine the spatial interval between two successive interaction events

Determine the scattering angle Determine the survival of the photon

Three Major Sampling Procedures

College of Engineering, Peking University 生物医学光学 II

Page 15: 8. MonteCarlo

15

The mean free path for an absorption or

scattering event

Step size (function of µa and µs)

The scattering angle Deflection angle, θ (function of anisotropy,

g)

Azimuthal angle, ψ

Random number generators will be used

for the selection of step size, deflection

angle and azimuthal angle for sampling

from known probability density functions

The variables that govern Monte Carlo

College of Engineering, Peking University 生物医学光学 II

Page 16: 8. MonteCarlo

16

Consider an experiment in which a laser beam strikes a target such as a cylindrical cuvette containing a dilute solution of scattering particles. The scattering pattern p() is measured by a detector that is moved in a circle around the target while always facing the target. Hence the detector collects light scattered at various deflection angles in a horizontal plane parallel to the table top on which the apparatus sits. The proper definition of anisotropy is the expectation value for cos():

It is common to express the definition of anisotropy in an equivalent way:

College of Engineering, Peking University 生物医学光学 II

Page 17: 8. MonteCarlo

17

• The Monte Carlo method as its name implies (“throwing the dice”) relies on the random sampling of a probability density function based on a computer generated random number

• Need to understand definitions for probability density functions and probability distributions

Basis for the Monte Carlo method

College of Engineering, Peking University 生物医学光学 II

Page 18: 8. MonteCarlo

Scattering and Absorption Probability

18College of Engineering, Peking University 生物医学光学 II

Beer-Lambert lawI0 I(d)

d

t)coefficien absorption or scattering represents ( ,)( 0

deIdI

The probability of the photon passing through the medium without scattering or absorption is:

de

Within any infinitesimal interval ds, the probability of being scattered or absorbed is: ds

Page 19: 8. MonteCarlo

19

Henyey-Greenstein Phase Function

College of Engineering, Peking University 生物医学光学 II

Which is approximately used by Henyey-Greenstein function

Henyey and Greenstein (1941) devised an expression which mimics the angular dependence of light scattering by small particles, which they used to describe scattering of light by interstellar dust clouds. The Henyey-Greenstein scattering function has proven to be useful in approximating the angular scattering dependence of single scattering events in biological tissues.

Page 20: 8. MonteCarlo

20College of Engineering, Peking University 生物医学光学 II

Homework 1: reproduce this plot with Matlab.

Page 21: 8. MonteCarlo

21

The problem to be solved begins with an infinitely narrow photon beam, also referred to as a pencil beam, that is perpendicularly incident on a multi-layered scattering medium (Figure 3.1); various physical quantities are computed as responses.

The pencil beam can be represented by an impulse (Dirac delta) function of space, direction, and time; thus, the responses are termed impulse responses or Green’s functions.

Although never infinitely wide in reality, a layer can be so treated if it is much wider than the photon distribution.

Definition of Problem

College of Engineering, Peking University 生物医学光学 II

Page 22: 8. MonteCarlo

22

Each layer is described by the following parameters: thickness , refractive index , absorption coefficient , scattering coefficient ,scattering anisotropy .

The top and the bottom ambient media are each described by a refractive index.

Optical Properties

College of Engineering, Peking University 生物医学光学 II

Page 23: 8. MonteCarlo

23

Coordinates

Global Cartesian coordinate system for photon tracking: ),,( zyx Global cylindrical coordinate system for photon recording: ),',( zr Local moving spherical coordinate system for photon scattering: (1, , )

College of Engineering, Peking University 生物医学光学 II

Page 24: 8. MonteCarlo

24

Consider a random variable x needed for a Monte Carlo simulation. Then there is a probability density function p(x) of x , which defines x over the interval such that: a ≤ x ≤ b

How to sample random variables

College of Engineering, Peking University 生物医学光学 II

( ) 1b

ap x

Page 25: 8. MonteCarlo

25

The probability that x will fall in the interval [a, x1] is given by the distribution function F(x1), defined as:

where x1 is a random variable.

Sample random variables

College of Engineering, Peking University 生物医学光学 II

1

1( ) ( )x

aF x p x dx

Page 26: 8. MonteCarlo

26

By using a computer random number generator, one can obtain a random number ξ in the range [0, 1]. The probability density function for this random number is 1 in the range [0, 1].

The corresponding probability distribution is

where p(x)=1, a<x<b.

Sample random variables

College of Engineering, Peking University 生物医学光学 II

1

1 1( ) ( ) [0,1]a

F p d

Page 27: 8. MonteCarlo

27

This means that the random number picked gives the integrated value of p(x), that is :

College of Engineering, Peking University 生物医学光学 II

1

1 1( ) ( )x

aF x p x dx

Page 28: 8. MonteCarlo

28

For generality, we replace the variables, ξ1 and x1 by the continuous variables, ξ and x:

This is the basic equation for sampling x from p(x) based using a randomly generated number, ξ over the interval [0,1]

College of Engineering, Peking University 生物医学光学 II

( )x

ap x dx

Page 29: 8. MonteCarlo

29

Generation of Random Numbers

College of Engineering, Peking University 生物医学光学 II

)(xp

1,0in number random uniform a is ),(

by calculaed becan sampling then the

DF)function(Cdensity Cumulative

1

P

P

dxxpa

a

dxxp )()(P

Page 30: 8. MonteCarlo

30

Selecting the step size, s

• The step size of the photon is calculated based on sampling the probability for the photon’s mean free path

• If step size too small, MC is inefficient, but if step size is too large, poor approximation of real photon travel

• Choose step size from probability density functionCollege of Engineering, Peking University 生物医学光学 II

Page 31: 8. MonteCarlo

31

The total attenuation coefficient

Recall that the probability of interaction of a photon with a medium per unit path length is:

P[s1,s1+ds1]=μtds1

College of Engineering, Peking University 生物医学光学 II

Page 32: 8. MonteCarlo

32

The total attenuation coefficient

The probability of interaction of a photon with a medium per unit path length is related to the gradient of transmission:

College of Engineering, Peking University 生物医学光学 II

11

1

( )

( )t

dT sds

T s

Page 33: 8. MonteCarlo

33

The total attenuation coefficient

The probability distribution function (from Beer’s law) is defined as:

College of Engineering, Peking University 生物医学光学 II

1 1 1

1 1 1

( ) ( ) exp( )

( ) 1 ( ) 1 exp( )t

t

P s s T s s

P s s T s s

Page 34: 8. MonteCarlo

34

Final expression

Solving for “s” yields:

College of Engineering, Peking University 生物医学光学 II

ln

t

s

Page 35: 8. MonteCarlo

35

Sampling the Step Size

tt

t

t

ss

sµsP

ln1ln

or

:size step Sampled

)exp(1

:method ondistributi Inverse

)exp(1

:size step of function ondistributi Cumulative

College of Engineering, Peking University 生物医学光学 II

Page 36: 8. MonteCarlo

36College of Engineering, Peking University 生物医学光学 II

Page 37: 8. MonteCarlo

37College of Engineering, Peking University 生物医学光学 II

Page 38: 8. MonteCarlo

38College of Engineering, Peking University 生物医学光学 II

Page 39: 8. MonteCarlo

39College of Engineering, Peking University 生物医学光学 II

Page 40: 8. MonteCarlo

Sampling the Scattering Angle

2

2 3/2

222

Henyey-Greenstein phase function:

1(cos ) , 0,

2(1 2 cos )

Sampled scattering angle:

1 11 if 0

cos 2 1 2

2 1 if 0

gp

g g

gg g

g g g

g

Page 41: 8. MonteCarlo

41

Sampling the Azimuthal Scattering Angle

[0,2

1

22

p

College of Engineering, Peking University 生物医学光学 II

Page 42: 8. MonteCarlo

42

Moving the Photon Packet

iz

iy

ix

szz

syy

sxx

College of Engineering, Peking University 生物医学光学 II

Page 43: 8. MonteCarlo

Absorption

WWW

μ W

t

a

Page 44: 8. MonteCarlo

44

Update of Photon Propagation Direction

exists. solution eAlternativ

.',',' in , angles azimuthal andpolar has along ' npropagatio photon ringPostscatte

.',','get tofor about ,, Rotate(2)

.,, scoordinate teintermediaget tofor about ,, Rotate(1)

,',',' scoordinate local to,, scoordinate global from transformTo

., angles azimuthal andpolar has npropagatio photon ring Prescatte:Note

.cossgn sinsin cossin then,1 If

.coscossin1

,cos1

)sincos( sin

,cos 1

)sincos( sin

0****

***0

00

2

2

2

zyxzk

zyxyzyx

zyxzzyx

zyxzyx

k

θμ μ,θ μ,θ μµ

µµμ

µµ

µµµμ

µµ

µµµµ

z'z

'y

'xz

zz'z

y

z

xzy'y

x

z

yzx'x

College of Engineering, Peking University 生物医学光学 II

Page 45: 8. MonteCarlo

45

Please go to Jianan Qu’s ppt: 13b.pdf and 13c.pdf.

College of Engineering, Peking University 生物医学光学 II

Page 46: 8. MonteCarlo

46

int main ()

{

albedo = mu_s / (mu_s + mu_a);

rs = (n-1.0)*(n-1.0)/(n+1.0)/(n+1.0); /* specular reflection */

crit_angle = sqrt(1.0-1.0/n/n); /* cos of critical angle */

bins_per_mfp = 1e4/microns_per_bin/(mu_a+mu_s);

for (i = 1; i <= photons; i++){

launch ();

while (weight > 0) {

move ();

absorb ();

scatter ();

}

}

print_results();

return 0;

}

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 47: 8. MonteCarlo

47

void launch() /* Start the photon */

{

x = 0.0; y = 0.0; z = 0.0;

u = 0.0; v = 0.0; w = 1.0;

weight = 1.0 - rs;

}

void bounce () /* Interact with top surface */

{

double t, temp, temp1,rf;

w = -w;

z = -z;

if (w <= crit_angle) return; /* total internal reflection */

t = sqrt(1.0-n*n*(1.0-w*w)); /* cos of exit angle */

temp1 = (w - n*t)/(w + n*t);

temp = (t - n*w)/(t + n*w);

rf = (temp1*temp1+temp*temp)/2.0; /* Fresnel reflection */

rd += (1.0-rf) * weight;

weight -= (1.0-rf) * weight;

}

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 48: 8. MonteCarlo

48

void move() /* move to next scattering or absorption event */

{

double d = -log((rand()+1.0)/(RAND_MAX+1.0));

x += d * u;

y += d * v;

z += d * w;

if ( z<=0 ) bounce();

}

void absorb () /* Absorb light in the medium */

{

int bin=z*bins_per_mfp;

if (bin >= BINS) bin = BINS-1;

heat[bin] += (1.0-albedo)*weight;

weight *= albedo;

if (weight < 0.001){ /* Roulette */

bit -= weight;

if (rand() > 0.1*RAND_MAX) weight = 0; else weight /= 0.1;

bit += weight;

}

}

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 49: 8. MonteCarlo

49

void scatter() /* Scatter photon and establish new direction */

{

double x1, x2, x3, t, mu;

for(;;) { /*new direction*/

x1=2.0*rand()/RAND_MAX - 1.0;

x2=2.0*rand()/RAND_MAX - 1.0;

if ((x3=x1*x1+x2*x2)<=1) break;

}

if (g==0) { /* isotropic */

u = 2.0 * x3 -1.0;

v = x1 * sqrt((1-u*u)/x3);

w = x2 * sqrt((1-u*u)/x3);

return;

}

接下

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 50: 8. MonteCarlo

50

mu = (1-g*g)/(1-g+2.0*g*rand()/RAND_MAX);

mu = (1 + g*g-mu*mu)/2.0/g;

if ( fabs(w) < 0.9 ) {

t = mu * u + sqrt((1-mu*mu)/(1-w*w)/x3) * (x1*u*w-x2*v);

v = mu * v + sqrt((1-mu*mu)/(1-w*w)/x3) * (x1*v*w+x2*u);

w = mu * w - sqrt((1-mu*mu)*(1-w*w)/x3) * x1;

} else {

t = mu * u + sqrt((1-mu*mu)/(1-v*v)/x3) * (x1*u*v + x2*w);

w = mu * w + sqrt((1-mu*mu)/(1-v*v)/x3) * (x1*v*w - x2*u);

v = mu * v - sqrt((1-mu*mu)*(1-v*v)/x3) * x1;

}

u = t;

}

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 51: 8. MonteCarlo

51

void print_results() /* Print the results */

{

int i;

printf("%s\n%s\n\nScattering = %8.3f/cm\nAbsorption = %8.3f/cm\n",t1,t2,mu_s,mu_a);

printf("Anisotropy = %8.3f\nRefr Index = %8.3f\nPhotons = %8ld",g,n,photons);

printf("\n\nSpecular Refl = %10.5f\nBackscattered Refl = %10.5f",rs,rd/(bit+photons));

printf("\n\n Depth Heat\n[microns] [W/cm^3]\n");

for (i=0;i<BINS-1;i++){

printf("%6.0f %12.5f\n",i*microns_per_bin, heat[i]/microns_per_bin*1e4/(bit+photons));

}

printf(" extra %12.5f\n",heat[BINS-1]/(bit+photons));

}

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 52: 8. MonteCarlo

52

char t1[80] = "Small Monte Carlo by Scott Prahl (http://omlc.ogi.edu)";

char t2[80] = "1 W/cm^2 Uniform Illumination of Semi-Infinite Medium";

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define BINS 101

double mu_a = 5; /* Absorption Coefficient in 1/cm */

double mu_s = 95; /* Scattering Coefficient in 1/cm */

double g = 0.25; /* Scattering Anisotropy -1<=g<=1 */

double n = 1.5; /* Index of refraction of medium */

double microns_per_bin = 20;/* Thickness of one bin layer */

long i, photons = 100000;

double x,y,z,u,v,w,weight;

double rs, rd, bit, albedo, crit_angle, bins_per_mfp, heat[BINS];

Monte Carlo Program

College of Engineering, Peking University 生物医学光学 II

Page 53: 8. MonteCarlo

53

Monte Carlo can simulate photon transport in biological tissue

Three steps: move, absorb, scatterWeight defines its alive or deadThe trajectory of a photon is modeled as a

persistent random walk. The directions are independent.

Summary

College of Engineering, Peking University 生物医学光学 II

Page 54: 8. MonteCarlo

54

http://omlc.ogi.edu/classroom/ece532/class4/index.html

Tiny_mc.c, Small_mc.c, mc321.c:http://omlc.ogi.edu/software/mc/

MCML download:http://labs.seas.wustl.edu/bme/Wang/mc.html

Further readings

College of Engineering, Peking University 生物医学光学 II

Page 55: 8. MonteCarlo

55

1. Plot the Henyey Greenstein Function with different g.

2. Write a program (in C or MATLAB) to describe a simple random walk in x-y plane. The direction is uniformly random in 360 degrees, and the walking step size follows the same way of a photon transportation in a medium with μ=100 /cm. Plot your result and hand in your program. (up to 20 steps)

3. Rewrite the tiny_mc.c program to Matlab.

Homework

College of Engineering, Peking University 生物医学光学 II

Page 56: 8. MonteCarlo

56

Experiment: Monte Carlo Simulation

College of Engineering, Peking University Biomedical Optics II

Fiber

λ = 633 nm

Page 57: 8. MonteCarlo

57

Experiment: Monte Carlo Simulation

College of Engineering, Peking University Biomedical Optics II

Fiber

λ = 633 nm

Page 58: 8. MonteCarlo

58

Experiment: Monte Carlo Simulation

College of Engineering, Peking University Biomedical Optics II

Fiber

λ = 633 nm

Page 59: 8. MonteCarlo

59

Using g = 0.9, and the measured scattering coefficient as well as other parameters, apply Monte Carlo simulation (next experiment), then compare your simulated result with your measured data.

Experiment report

College of Engineering, Peking University Biomedical Optics II