Solver.py 文件源码

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

项目:exact_binary_dynamics 作者: laurencee9 项目源码 文件源码
def get_probabilities_Q_possible(self, possible_configs):
        """
        Get the probability Q(l;n) for each configuration in the possible_configs dictionnary.
        The implementation is based on the recursive equation of the paper.

        Input
        ----------------------
        possible_configs: Dictionnary where keys are the config as a string (i.e. "0101011011") and value are sets of the parent configurations.

        Return 
        ----------------------
        Dictionnary of probabilities where the key is the configuration as a string (e.g. "10101110") and the value is Q(l;n)

        """
        #the master dictionnary
        dict_config = {}
        prob_tot = 1.0
        #order by size to simplify the calculation
        possible_config_ordered_by_size = self.regroup_config_by_size(possible_configs)

        N = len(self.G.nodes())

        #Initial configuration
        initial_config = [0]*N
        if self.symbolic_:
            dict_config[self.list_to_string(initial_config)] = "<prod>"+";".join(["G("+str(node)+","+str(0)+")" for node in self.G.nodes()])+"</prod>"
        else:
            dict_config[self.list_to_string(initial_config)] = np.float128(np.product([(1.0-self.G.nodes[node]["rf"].resp_func(0)) for node in self.G.nodes()]))
            prob_tot -= dict_config[self.list_to_string(initial_config)]

        for size in range(1,N+1):
            if size in possible_config_ordered_by_size:
                for config_str in possible_config_ordered_by_size[size]:

                    Q_ln = self.solve_specific_configuration(config_str, dict_config, possible_configs)
                    dict_config[config_str] = Q_ln
                    prob_tot -= Q_ln

        dict_config["1"*N] = prob_tot
        return dict_config
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号