treetime/distribution.py
def calc_fwhm(distribution, is_neg_log=True):
        """
        Assess the width of the probability distribution. This returns
        full-width-half-max
        """

        if isinstance(distribution, interp1d):

            if is_neg_log:
                ymin = distribution.y.min()
                log_prob = distribution.y-ymin
            else:
                log_prob = -np.log(distribution.y)
                log_prob -= log_prob.min()

            xvals = distribution.x

        elif isinstance(distribution, Distribution):
            # Distribution always stores neg log-prob with the peak value subtracted
            xvals = distribution._func.x
            log_prob = distribution._func.y
        else:
            raise TypeError("Error in computing the FWHM for the distribution. "
                " The input should be either Distribution or interpolation object");

        L = xvals.shape[0]
        # 0.69... is log(2), there is always one value for which this is true since
        # the minimum is subtracted
        tmp = np.where(log_prob < 0.693147)[0]
        x_l, x_u = tmp[0], tmp[-1]
        if L < 2:
            print ("Not enough points to compute FWHM: returning zero")
            return min(TINY_NUMBER, distribution.xmax - distribution.xmin)
        else:
            # need to guard against out-of-bounds errors
            return max(TINY_NUMBER, xvals[min(x_u+1,L-1)] - xvals[max(0,x_l-1)])
def calc_fwhm(distribution, is_neg_log=True):
        if isinstance(distribution, interp1d):

            if is_neg_log:
                ymin = distribution.y.min()
                log_prob = distribution.y-ymin
            else:
                log_prob = -np.log(distribution.y)
                log_prob -= log_prob.min()

            xvals = distribution.x

        elif isinstance(distribution, Distribution):
            # Distribution always stores neg log-prob with the peak value subtracted
            xvals = distribution._func.x
            log_prob = distribution._func.y
        else:
            raise TypeError("Error in computing the FWHM for the distribution. "
                " The input should be either Distribution or interpolation object");

        L = xvals.shape[0]
        # 0.69... is log(2), there is always one value for which this is true since
        # the minimum is subtracted
        tmp = np.where(log_prob < 0.693147)[0]
        x_l, x_u = tmp[0], tmp[-1]
        if L < 2:
            print ("Not enough points to compute FWHM: returning zero")
            return min(TINY_NUMBER, distribution.xmax - distribution.xmin)
        else:
            # need to guard against out-of-bounds errors
            return max(TINY_NUMBER, xvals[min(x_u+1,L-1)] - xvals[max(0,x_l-1)])
def calc_fwhm ( distribution , is_neg_log = True ) : if isinstance ( distribution , interp1d ) : if is_neg_log : ymin = distribution . y . min ( ) log_prob = distribution . y - ymin else : log_prob = - np . log ( distribution . y ) log_prob -= log_prob . min ( ) xvals = distribution . x elif isinstance ( distribution , Distribution ) : # Distribution always stores neg log-prob with the peak value subtracted xvals = distribution . _func . x log_prob = distribution . _func . y else : raise TypeError ( "Error in computing the FWHM for the distribution. " " The input should be either Distribution or interpolation object" ) L = xvals . shape [ 0 ] # 0.69... is log(2), there is always one value for which this is true since # the minimum is subtracted tmp = np . where ( log_prob < 0.693147 ) [ 0 ] x_l , x_u = tmp [ 0 ] , tmp [ - 1 ] if L < 2 : print ( "Not enough points to compute FWHM: returning zero" ) return min ( TINY_NUMBER , distribution . xmax - distribution . xmin ) else : # need to guard against out-of-bounds errors return max ( TINY_NUMBER , xvals [ min ( x_u + 1 , L - 1 ) ] - xvals [ max ( 0 , x_l - 1 ) ] )
Assess the width of the probability distribution. This returns
        full-width-half-max
Assess the width of the probability distribution . This returns full - width - half - max