CLatticeModel.py 文件源码

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

项目:MarkovModels 作者: pmontalb 项目源码 文件源码
def create_markov_operator(self, base_operator, dt, method="CrankNicolson"):
        """ Let u be the Markov operator and L be the base generator. The model dynamic
            is given by
                            u ' = L \cdot u
            Following the Method Of Line (MOL) discretization,
            let u(n) = u(t_n) where t_n is the discretized time domain.

            The following schemes can be used:
            - Explicit Euler --> u(n + 1) = (I + L * dt) \cdot u(n)
            - Implicit Euler --> (I - L * dt) \cdot u(n + 1) = u(n)
            - Crank Nicolson --> (I - L * dt / 2) \cdot u(n + 1) = (I + L * dt / 2) \cdot u(n)
        :param base_operator:
        :param dt:
        :param method:
        :return:
        """
        if method == "ExplicitEuler":
            u = np.eye(self.d) + dt * base_operator
        elif method == "ImplicitEuler":
            u = linalg.solve(np.eye(self.d) - dt * base_operator, np.eye(self.d))
        elif method == "CrankNicolson":
            u = linalg.solve(np.eye(self.d) - .5 * dt * base_operator,
                             np.eye(self.d) + .5 * dt * base_operator)
        else:
            raise NotImplementedError("Unsupported SDE resolution method")
        return u
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号