|
PRO ANALYZE_GC, gc=gc, almg=almg, ngauss=ngauss, outfilename=outfilename |
|
;; gc= 2, 3, 5, 13, 15, 92 |
|
;; almg= if set, only fit Al Mg |
|
;; ngauss= # of Gaussians |
|
IF ~keyword_set(ngauss) THEN ngauss= 3 |
|
;;Read |
|
read_gc, id, abu, pop , gc=gc;;abu = [Mg, Al, Si, Ca, Ti] |
|
IF keyword_set(almg) THEN abu= abu[0:1,*] |
|
|
|
;;Prepare for XD |
|
ydata= abu |
|
ycovar= abu*0. ;;errors are uncorrelated, so only need to specify diagonal |
|
IF gc EQ 2 THEN BEGIN |
|
ycovar[0,*]= 0.08^2. |
|
ycovar[1,*]= 0.11^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.09^2. |
|
ycovar[3,*]= 0.06^2. |
|
ycovar[4,*]= 0.13^2. |
|
ENDIF |
|
ENDIF ELSE IF gc EQ 3 THEN BEGIN |
|
ycovar[0,*]= 0.04^2. |
|
ycovar[1,*]= 0.11^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.09^2. |
|
ycovar[3,*]= 0.06^2. |
|
ycovar[4,*]= 0.16^2. |
|
ENDIF |
|
ENDIF ELSE IF gc EQ 5 THEN BEGIN |
|
ycovar[0,*]= 0.05^2. |
|
ycovar[1,*]= 0.08^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.08^2. |
|
ycovar[3,*]= 0.06^2. |
|
ycovar[4,*]= 0.13^2. |
|
ENDIF |
|
ENDIF ELSE IF gc EQ 13 THEN BEGIN |
|
ycovar[0,*]= 0.06^2. |
|
ycovar[1,*]= 0.13^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.08^2. |
|
ycovar[3,*]= 0.07^2. |
|
ycovar[4,*]= 0.16^2. |
|
ENDIF |
|
ENDIF ELSE IF gc EQ 15 THEN BEGIN |
|
ycovar[0,*]= 0.09^2. |
|
ycovar[1,*]= 0.17^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.13^2. |
|
ycovar[3,*]= 0.19^2. |
|
ycovar[4,*]= 0.28^2. |
|
ENDIF |
|
ENDIF ELSE IF gc EQ 92 THEN BEGIN |
|
ycovar[0,*]= 0.09^2. |
|
ycovar[1,*]= 0.13^2. |
|
IF ~keyword_set(almg) THEN BEGIN |
|
ycovar[2,*]= 0.12^2. |
|
ycovar[3,*]= 0.22^2. |
|
ycovar[4,*]= 0.20^2. |
|
ENDIF |
|
ENDIF |
|
;;find bad values and give them large errors to make them essentially |
|
;;unobserved |
|
indx= where(ydata gt 9998.0,cnt) |
|
if cnt gt 0 then begin |
|
ydata[indx]= 0. |
|
ycovar[indx]= 100.^2. |
|
endif |
|
IF keyword_set(almg) THEN dx= 2 ELSE dx= 5;;number of abundances |
|
|
|
;;Initialize XD |
|
fit_amp= dblarr(ngauss) |
|
fit_mean= dblarr(dx,ngauss) |
|
fit_covar= dblarr(dx,dx,ngauss) |
|
datamean= MEAN(ydata,dimension=2) |
|
datastd= STDDEV(ydata,dimension=2) |
|
FOR ii=0L, ngauss-1 DO BEGIN |
|
fit_amp[ii]= 1./double(ngauss) |
|
fit_mean[*,ii]= randomn(seed,dx)*datastd+datamean |
|
ENDFOR |
|
FOR ii= 0L, dx-1 DO fit_covar[ii,ii,*]= 4.*datastd[ii]^2. |
|
|
|
;;Run XD |
|
projected_gauss_mixtures_c, ngauss, ydata, ycovar, $ |
|
fit_amp, fit_mean, fit_covar, /quiet |
|
;;print results |
|
print, FORMAT='("Amplitudes of the ",I0," components fit with XD")', ngauss |
|
print, fit_amp |
|
print, FORMAT='("Means of the ",I0," components: Mg, Al, Si, Ca, Ti")', ngauss |
|
print, fit_mean |
|
|
|
;;Calculate membership probabilities |
|
calc_membership_prob, logpost, ydata, ycovar, fit_mean, fit_covar, fit_amp |
|
;;logpost is a [ngauss,ndata] array of ln of relative probabilities |
|
maxp= max(logpost,xdpop,dimension=1) |
|
xdpop= xdpop MOD ngauss ;;xdpop has index of highest probability cluster for each star |
|
|
|
;;check that we get similar cluster assignments as Szabolcs |
|
FOR ii=0L, ngauss-1 DO BEGIN |
|
print, FORMAT= '("Cluster ",I0,": old assignments and probability of assignment:")', ii+1 |
|
indx= where(xdpop eq ii,cnt) |
|
if cnt gt 0 then begin |
|
print, pop[indx] |
|
print, exp(maxp[indx]) |
|
endif |
|
ENDFOR |
|
|
|
out= {id:0L,oldpop:0L,xdpop:0L,logp:0D} |
|
out= REPLICATE(out,n_elements(id)) |
|
out.id= id |
|
out.oldpop= pop |
|
out.xdpop= xdpop |
|
out.logp= maxp |
|
mwrfits, out, outfilename, /create |
|
END |