;-------------------------------------------------------------------- ; make binary cross entropy metric for cloud ; ; using the cloud phase which is defined as ; 0 = clear ; 1 = water ; 2 = ice ; ; ref: https://ml-cheatsheet.readthedocs.io/en/latest/loss_functions.html ;------------------------------------------------------------------------ pro make_bce_metric, phase_true, prob_cloud, bce missing = -999.0 ;--- make input binary (0/1) masks p = prob_cloud t = phase_true ;--- logs cant handle <= 0 or >= 1 idx = where(p ne missing and p le 0.00,cc) & if (cc gt 0) then p[idx] = 0.00001 idx = where(p ne missing and p ge 1.00,cc) & if (cc gt 0) then p[idx] = 0.99999 idx = where(phase_true eq 0,cc) & if (cc gt 0) then t[idx] = 0.00001 idx = where(phase_true gt 0,cc) & if (cc gt 0) then t[idx] = 0.99999 idx = where(p ge 0.0 and p le 1.0 and t ge 0.0 and t le 1.0,cc) if (cc gt 0) then begin ; f_p = 1.0 / (1.0 + exp(-1.0*p)) f_p = p bce_vector = -1.0*t*alog(f_p) - (1.0-t)*alog(1.0-f_p) bce = mean(bce_vector) endif else begin bce = missing endelse end