250 likes | 362 Views
South China University of Technology. Stochastic Process. Xiaobao Yang Department of Physics. www.compphys.cn. Generation of random number. circumference ratio. Generation Non-uniform random number. The possibilities of events A and B is 2:1.
E N D
South China University of Technology Stochastic Process Xiaobao Yang Department of Physics www.compphys.cn
Generation Non-uniform random number The possibilities of events A and B is 2:1. The possibilities of events A1, A2 … An is R1, R2 … Rn . The possibilities of events A1, A2 … An is f(1), f(2) … f(n) .
Non-uniform cases uniform distribution x=rand(1000,1); y=-log(x); hist(y)
Non-uniform cases (0, Py(max)) If Py(y1) < P test, we remove y1 from the sequence; otherwise it is kept. for ii=1:length(y) if exp(-y(ii))>rand x=[x y(ii)]; end end y=rand(1000,1)*6; x=[];
帕斯卡 惠更斯
Simulation of gambling The big bet induces chaos.
SixGL.m Simulation of HK Six Marks There are Events 1~12. You win 10 when you hit it. for ii=2:N banker=floor(rand*12)+1; tmp=floor(rand(10,1)*12)+1; buyers(:,ii)=buyers(:,ii-1)-1+10*(tmp==banker); end
Gambling.m Events of Big/Small/Tie. banker=floor(rand(1,3)*5)+1; tmp=floor(rand(10,1)*2)+2; if re==1 buyers(:,ii)=buyers(:,ii-1)-1; end if re==2 buyers(:,ii)=buyers(:,ii-1)+(tmp==2)*2-1; end if re==3 buyers(:,ii)=buyers(:,ii-1)+(tmp==3)*2-1; end if length(unique(banker))==1 re=1; end if length(unique(banker))~=1&sum(banker)<=10 re=2; end if length(unique(banker))~=1&sum(banker)>10 re=3; end
Summary • Select a proper distribution • Construct the Stochastic Process • Store the data for histogram.
The existence of god of gamblers? 1 1 1 0 0 1 0 0 1 0 …. When you bet N times, the possibility of all win is 2^(-N). Don't get crush on him and he is just a legend.
Random walks • Concept of random walk. x0=0 • Informative quantity:
1-D random walks • clear • N=300; • M=100; • re=zeros(M,N); • for ii=1:N-1 • for jj=1:M • re(jj,ii+1)=re(jj,ii)+sign(rand-0.5); • end • end • plot(sum(re.^2,1)/M) rw1d.m
Random walks • Questions: To make it more realistic: • What is the relation of <r2> vs. t for a random walk in 2-D, 3-D systems? • How about allow the steps to be a random length in [-1,1]?
2-D random walks • clear • N=300; • M=100; • re=zeros(M*2,N); • for ii=1:N-1 • for jj=1:M • if rand <0.5 • re(jj*2-1,ii+1)=re(jj*2-1,ii)+sign(rand-0.5); • re(jj*2,ii+1)=re(jj*2,ii); • else • re(jj*2,ii+1)=re(jj*2,ii)+sign(rand-0.5); • re(jj*2-1,ii+1)=re(jj*2-1,ii); • end • end • end • plot(sum(re.^2,1)/M) rw2d.m
Random walk in hexagonal lattice O (0.00,0.00) A (0.00,1.00) B (-0.87 1.50) C ( 0.87 1.50) T=
Self-Avoiding Walks A typical polymer in solution may be described by SAW. Keep all possible SAW configurations equivalent. To generate 4th steps if a new possible way is chosen when “self-avoiding” • There are 3 possible ways. (only has 2/3 the probability as in b) • There are only 2 possible ways . How to correct the problem? • Discard the whole RW when restriction condition occurred. CPU time ! • “enumeration” instead of “simulation”.
saw.m jj=1:sx(1) newtmp=[x(jj,1:2:end)' x(jj,2:2:end)']; % find all the used sites in the same link! tmp=x(jj,end-1:end)+[0 1]; if length(intersect(tmp,newtmp,'rows'))==0; allx=[allx x(jj,:) tmp]; end
Self-Avoiding Walks Log-log scale Average of 106 walks Average of 1000 walks ν=1/2: simple random walk ν=3/4: 2D SAW ν~3/5: 3D SAW
Walker with memory 可以且仅可以记忆它上一步走过的方向并避免重复, 比如当从(0,0)走到(0,1)时,下一步只有3个可能的位移[(0,2), (1,1), (-1,1)], 避免了从(0,1)走回(0,0)位置。 while (re(jj*2-1,ii+1)==re(jj*2-1,ii-1)&re(jj*2,ii+1)==re(jj*2,ii-1)) if rand <0.5 re(jj*2-1,ii+1)=re(jj*2-1,ii)+sign(rand-0.5); re(jj*2,ii+1)=re(jj*2,ii); else re(jj*2,ii+1)=re(jj*2,ii)+sign(rand-0.5); re(jj*2-1,ii+1)=re(jj*2-1,ii); end walkwith.m
Homework Random walk in triangular or hexagonal lattice. Sending to 17273799@qq.com when ready For lecture notes, refer to http://www.compphys.cn/~xbyang/