'Construct a new probability distribution from the given
dictionary, which maps values to probabilities (or to log
probabilities, if ``log`` is true).  If ``normalize`` is
true, then the probability values are scaled by a constant
factor such that they sum to 1.
If called without arguments, the resulting probability
distribution assigns zero probability to all values.'

def __init__(self, prob_dict=None, log=False, normalize=False):

    self._prob_dict = (prob_dict.copy() if (prob_dict is not None) else {})
    self._log = log
    if normalize:
        if (len(prob_dict) == 0):
            raise ValueError((u'A    DictionaryProbDist    must    have    at    least    one    sample    ' + u'before    it    can    be    normalized.'))
        if log:
            value_sum = sum_logs(list(self._prob_dict.values()))
            if (value_sum <= _NINF):
                logp = math.log((1.0 / len(prob_dict)), 2)
                for x in prob_dict:
                    self._prob_dict[x] = logp
            else:
                for (x, p) in self._prob_dict.items():
                    self._prob_dict[x] -= value_sum
        else:
            value_sum = sum(self._prob_dict.values())
            if (value_sum == 0):
                p = (1.0 / len(prob_dict))
                for x in prob_dict:
                    self._prob_dict[x] = p
            else:
                norm_factor = (1.0 / value_sum)
                for (x, p) in self._prob_dict.items():
                    self._prob_dict[x] *= norm_factor
