added posterior probability calculation function