Subject: bayesian filter pro bayesredfun,ap,sp,dtype,mf ;dtype=apriori distribution type, 0=constant, 1=exponential, 2=gaussian ;mf=parameter of distribution, i.e. for dtype=2, mf is the sigma ;ap is measured extinction ;sp is uncertainty of ap ;pav is the prior probability at extinctions of dmags dmags=dindgen(10000)/1000. pav=dblarr(10000) if (dtype eq 0) then pav(*)=.1 if (dtype eq 1) then begin ;read,'enter 1/e fold in magnitudes',mf pav=exp(-dmags/mf) pav=pav/total(.001*pav) endif; if (dtype eq 2) then begin ;read,'enter 1 sigma in magnitudes',mf pav=2./(((2*3.14)^.5)*mf)*exp(-((dmags/(1.41*mf))^2.)) endif; !psym=-3 !linetype=0 dav=dblarr(1000) dav=(exp(-(dmags-ap)^2./(2.*sp^2.))*pav)/(total(.001*pav*exp(-(dmags-ap)^2./(2.* sp^2.)))) res=max(dav,kk) ap=kk*.001 sp=(total(.001*dav*dmags^2.)-(total(.001*dav*dmags))^2.)^.5 ;the best extinction, ap, is at the peak of the new distribution, dav ;the new uncertainty, sp, is the second moment of the new distribution, dav ; calculated by the standard formula, sigma_a=((mean(a^2)-(mean(a))^2.)^0.5 end