MarkovNetwork.py 文件源码

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

项目:MarkovNetwork 作者: rhiever 项目源码 文件源码
def activate_network(self, num_activations=1):
        """Activates the Markov Network

        Parameters
        ----------
        num_activations: int (default: 1)
            The number of times the Markov Network should be activated

        Returns
        -------
        None

        """
        original_input_values = np.copy(self.states[:self.num_input_states])
        for _ in range(num_activations):
            for markov_gate, mg_input_ids, mg_output_ids in zip(self.markov_gates, self.markov_gate_input_ids, self.markov_gate_output_ids):
                # Determine the input values for this Markov Gate
                mg_input_values = self.states[mg_input_ids]
                mg_input_index = int(''.join([str(int(val)) for val in mg_input_values]), base=2)

                # Determine the corresponding output values for this Markov Gate
                roll = np.random.uniform()
                mg_output_index = np.where(markov_gate[mg_input_index, :] >= roll)[0][0]
                mg_output_values = np.array(list(np.binary_repr(mg_output_index, width=len(mg_output_ids))), dtype=np.uint8)
                self.states[mg_output_ids] = np.bitwise_or(self.states[mg_output_ids], mg_output_values)

            self.states[:self.num_input_states] = original_input_values
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号