def Normalize(self, fraction=1.0):
        """Normalizes this PMF so the sum of all probs is fraction.

        Args:
            fraction: what the total should be after normalization

        Returns: the total probability before normalizing
        """
        if self.log:
            raise ValueError("Pmf is under a log transform")

        total = self.Total()
        if total == 0.0:
            raise ValueError('total probability is zero.')
            logging.warning('Normalize: total probability is zero.')
            return total

        factor = float(fraction) / total
        for x in self.d:
            self.d[x] *= factor

        return total
def Normalize ( self , fraction = 1.0 ) : if self . log : raise ValueError ( "Pmf is under a log transform" ) total = self . Total ( ) if total == 0.0 : raise ValueError ( 'total probability is zero.' ) logging . warning ( 'Normalize: total probability is zero.' ) return total factor = float ( fraction ) / total for x in self . d : self . d [ x ] *= factor return total
Normalizes this PMF so the sum of all probs is fraction.

        Args:
            fraction: what the total should be after normalization

        Returns: the total probability before normalizing