def update_propability_mass(self):
        """Create a total flux matrix, and propogate self.pv one time-step."""

        J = self.get_total_flux_matrix()

        if self.update_method == 'exact':
            self.pv = util.exact_update_method(J,
                                               self.pv,
                                               dt=self.simulation.dt)

        elif self.update_method == 'approx':

            if self.approx_order == None:
                self.pv = util.approx_update_method_tol(J,
                                                        self.pv,
                                                        tol=self.tol,
                                                        dt=self.simulation.dt,
                                                        norm=self.norm)

            else:
                self.pv = util.approx_update_method_order(
                    J,
                    self.pv,
                    approx_order=self.approx_order,
                    dt=self.simulation.dt)

        else:
            raise Exception('Unrecognized population update method: "%s"' %
                            self.update_method)  # pragma: no cover
Exemple #2
0
    def update_propability_mass(self):
        """Create a total flux matrix, and propogate self.pv one time-step."""

        #         import scipy.linalg as spla
        #         import matplotlib.pyplot as plt
        #
        #         if self.simulation.t > .09:
        #
        #             for key, val in self.total_input_dict.items():
        #                 print key, val
        #
        #             evs = spla.eigvals(J*self.simulation.dt)
        #             evs_re = np.real(evs)
        #             evs_im = np.imag(evs)
        #             plt.plot(evs_re, evs_im, '.')
        #             plt.show()

        if self.update_method == 'exact':
            J = self.get_total_flux_matrix()
            self.pv = util.exact_update_method(J,
                                               self.pv,
                                               dt=self.simulation.dt)

        elif self.update_method == 'approx':
            J = self.get_total_flux_matrix()
            if self.approx_order == None:
                self.pv = util.approx_update_method_tol(J,
                                                        self.pv,
                                                        tol=self.tol,
                                                        dt=self.simulation.dt,
                                                        norm=self.norm)

            else:
                self.pv = util.approx_update_method_order(
                    J,
                    self.pv,
                    approx_order=self.approx_order,
                    dt=self.simulation.dt)

        elif self.update_method == 'gmres':
            self.update_propability_mass_backward_euler(
                lambda J, x0: spsla.gmres(J, x0, x0=x0, tol=self.tol)[0])

        else:
            raise Exception('Unrecognized population update method: "%s"' %
                            self.update_method)  # pragma: no cover

        # Checking stability of
        if len(np.where(self.pv < 0)[0]) != 0 or np.abs(
                np.abs(self.pv).sum() - 1) > 1e-15:
            self.pv[np.where(self.pv < 0)] = 0
            self.pv /= self.pv.sum()
            logger.critical('Normalizing Probability Mass')
    def update_propability_mass(self):
        """Create a total flux matrix, and propogate self.pv one time-step."""
        
        J = self.get_total_flux_matrix()
        
        if self.update_method == 'exact':
            self.pv = util.exact_update_method(J, self.pv, dt=self.simulation.dt)
            
        elif self.update_method == 'approx':

            if self.approx_order == None:
                self.pv = util.approx_update_method_tol(J, self.pv, tol=self.tol, dt=self.simulation.dt, norm=self.norm)

            else:
                self.pv = util.approx_update_method_order(J, self.pv, approx_order=self.approx_order, dt=self.simulation.dt)
        
        else:
            raise Exception('Unrecognized population update method: "%s"' % self.update_method)  # pragma: no cover
    def update_propability_mass(self):
        """Create a total flux matrix, and propogate self.pv one time-step."""
        
        
        
#         import scipy.linalg as spla
#         import matplotlib.pyplot as plt
#         
#         if self.simulation.t > .09:
#         
#             for key, val in self.total_input_dict.items():
#                 print key, val
#         
#             evs = spla.eigvals(J*self.simulation.dt)
#             evs_re = np.real(evs)
#             evs_im = np.imag(evs)
#             plt.plot(evs_re, evs_im, '.')
#             plt.show()
        
        if self.update_method == 'exact':
            J = self.get_total_flux_matrix()
            self.pv = util.exact_update_method(J, self.pv, dt=self.simulation.dt)
            
        elif self.update_method == 'approx':
            J = self.get_total_flux_matrix()
            if self.approx_order == None:
                self.pv = util.approx_update_method_tol(J, self.pv, tol=self.tol, dt=self.simulation.dt, norm=self.norm)

            else:
                self.pv = util.approx_update_method_order(J, self.pv, approx_order=self.approx_order, dt=self.simulation.dt)
        
        elif self.update_method == 'gmres':
            self.update_propability_mass_backward_euler(lambda J, x0: spsla.gmres(J, x0, x0=x0, tol=self.tol)[0])
        
        else:
            raise Exception('Unrecognized population update method: "%s"' % self.update_method)  # pragma: no cover
        
        # Checking stability of  
        if len(np.where(self.pv<0)[0]) != 0 or np.abs(np.abs(self.pv).sum() - 1) > 1e-15:
            self.pv[np.where(self.pv<0)] = 0
            self.pv /= self.pv.sum()
            logger.critical('Normalizing Probability Mass')
    def update_propability_mass(self):
        """Create a total flux matrix, and propogate self.pv one time-step."""
        
        J = self.get_total_flux_matrix()
        
        if self.update_method == 'exact':
            self.pv = util.exact_update_method(J, self.pv, dt=self.simulation.dt)
            
        elif self.update_method == 'approx':

            if self.approx_order == None:
                self.pv = util.approx_update_method_tol(J, self.pv, tol=self.tol, dt=self.simulation.dt, norm=self.norm)

            else:
                self.pv = util.approx_update_method_order(J, self.pv, approx_order=self.approx_order, dt=self.simulation.dt)
        
        else:
            raise Exception('Unrecognized population update method: "%s"' % self.update_method)  # pragma: no cover
        
        # Checking stability of  
        if len(np.where(self.pv<0)[0]) != 0 or np.abs(np.abs(self.pv).sum() - 1) > 1e-15:
            self.pv[np.where(self.pv<0)] = 0
            self.pv /= self.pv.sum()
            logger.critical('Normalizing Probability Mass')