コード例 #1
0
    def getBDFromOde(self, A=None):
        '''
        Returns a list of:class:`Transition` from this object by unrolling
        the odes.  All the elements are of TransitionType.B or
        TransitionType.D
        '''
        if A is None:
            if not ode_utils._noneOrEmptyList(self._odeList):
                eqnList = [t.getEquation() for t in self._odeList]
                A = sympy.Matrix(checkEquation(eqnList, *self._getListOfVariablesDict(), subsDerived=False))
            else:
                raise Exception("Object was not initialized using a set of ode")
            # A = super(SimulateOdeModel, self).getOde()

        bdList, termList = _ode_composition.getUnmatchedExpressionVector(A, True)

        if len(bdList) > 0:
            M = self._generateTransitionMatrix(A)

            # # reduce the original set of ode to only birth and death process remaining
            # M1 = M - M.transpose()
            # diffA = sympy.zeros(self._numState,1)
            # for i in range(self._numState):
            #     a = sympy.simplify(sum(M1[i,:]))
            #     diffA[i] = sympy.simplify(a + A[i])

            A1 = _ode_composition.pureTransitionToOde(M)
            diffA = sympy.simplify(A - A1)

            # get our birth and death process
            bdListUnroll = list()
            states = [str(i) for i in self.getStateList()]

            for i, a in enumerate(diffA):
                for b in bdList:
                    if _ode_composition._hasExpression(a, b):
                        if sympy.Integer(-1) in _ode_composition.getLeafs(b):
                            bdListUnroll.append(Transition(origState=states[i],
                                                equation=str(b*-1),
                                                transitionType=TransitionType.D))
                        else:
                            bdListUnroll.append(Transition(origState=states[i],
                                                equation=str(b),
                                                transitionType=TransitionType.B))
                        a -= b
            
            return bdListUnroll
        else:
            return []
コード例 #2
0
    def _generateTransitionMatrix(self, A=None): #, transitionExpressionList=None):
        '''
        Finds the transition matrix from the set of ode.  It is 
        important to note that although some of the functions used
        in this method appear to be the same as _getReactantMatrix
        and _getStateChangeMatrix, they are different in the sense
        that the functions called here is focused on the terms of 
        the equation rather than the states.
        '''
        if A is None:
            if not ode_utils._noneOrEmptyList(self._odeList):
                eqnList = [t.getEquation() for t in self._odeList]
                A = sympy.Matrix(checkEquation(eqnList, *self._getListOfVariablesDict(), subsDerived=False))
            else:
                raise Exception("Object was not initialized using a set of ode")

        bdList, termList = _ode_composition.getUnmatchedExpressionVector(A, True)
        fx = _ode_composition.stripBDFromOde(A, bdList)
        states = [s for s in self._iterStateList()]
        M, remainTermList = _ode_composition.odeToPureTransition(fx, states, True)
        return M