lib.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:simple-markov 作者: Mandragorian 项目源码 文件源码
def __init__(self, distribution, label):
        """
        Creates a new state that contains a distribution of transitions
        to other states with a specified label.

        :param distribution: an iterable of state - transition probability pairs
        :param label: the label of the state
        """
        self.prob = {
            d[0]: Fraction(d[1]) for d in distribution \
            if 0 < Fraction(d[1]) <= 1
        }
        self.cum_prob = list(accumulate(v for v in self.prob.values()))
        if self.cum_prob[-1] != 1:
            raise ValueError("Transitions from state " + str(label) +
                    " do not form a probability distribution")
        self.label = label
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号