generation.py 文件源码

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

项目:revex 作者: lucaswiman 项目源码 文件源码
def __init__(self, dfa):  # type: (DFA) -> None
        """
        Class for maintaining state path weights inside a dfa.

        This is a renormalized version of l_{p,n} in section 2 of the Bernardi
        & Giménez paper, computed using matrix powers. See:
        https://en.wikipedia.org/wiki/Adjacency_matrix#Matrix_powers

        Note that ``path_weights[state, n]`` is the proportion of paths of
        length n from state to _some_ final/accepting state.

        `dfa` MUST have consecutive integer states, with 0 as the start state,
        though this is not validated.
        """
        self.longest_path_length = 0

        self.graph = dfa.as_multidigraph
        self.sink = len(dfa.nodes())

        for state in dfa.nodes():
            if dfa.node[state]['accepting']:
                self.graph.add_edge(state, self.sink)

        self.matrix = nx.to_numpy_matrix(self.graph, nodelist=self.graph.nodes())
        vect = np.zeros(self.matrix.shape[0])
        vect[-1] = 1.0  # Grabs the neighborhood of the sink node (last column).
        self.vects = [self.normalize_vector(self.matrix.dot(vect)).T]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号