epidemioptim/environments/models/heffernan_ode_model_16.py
def run_n_steps(self, current_state=None, n=1, labelled_states=False):
        """
        Runs the model for n steps

        Parameters
        ----------
        current_state: 1D nd.array
                       Current model state.
        n: int
           Number of steps the model should be run for.

        labelled_states: bool
                         Whether the result should be a dict with state labels or a nd array.

        Returns
        -------
        dict or 2D nd.array
            Returns a dict if labelled_states is True, where keys are state labels.
            Returns an array of size (n, n_states) of the last n model states.

        """
        if current_state is None:
            current_state = np.array(self._get_current_state())
        for f in range(16):
            # Update the number of people vaccinated with 1 or 2 doses
            self.dCV1[f] = sum([self.current_state[self._age_groups[f]]['{}'.format(s)] for s in ['CV11', 'CV21', 'CV31', 'CV41']])
            self.dCV2[f] = sum([self.current_state[self._age_groups[f]]['{}'.format(s)] for s in ['CV12', 'CV22', 'CV32', 'CV42']])
        if(self.t == self.step_list[self.step]):
            self.k = k_value(self.t)
            A_c = calculate_A_and_c(self.step, self.k, self.contact_modifiers, self.perturbations_matrices, self.transition_matrices)
            self.current_internal_params['A'], self.current_internal_params['c'] = np.array(A_c[0]), A_c[1]
            self.current_internal_params['nu'] = nu_value(self.t)
            if self.t > 369:
                # To uncomment if we want to run the initial model
                # sigma = self.compute_sigma()
                # self.current_internal_params['sigma'] = np.array(sigma)
                self.current_internal_params['sigma2'] = np.array(duplicate_data(1/42, 16))
                self.k = k_value(self.t)
                ##### TO COMMENT ####
                # if we want to run the initial model
                self.politic_decision_module()
                A_c = calculate_A_and_c(self.newstep, self.k, self.contact_modifiers, self.perturbations_matrices, self.transition_matrices)
                self.current_internal_params['A'], self.current_internal_params['c'] = np.array(A_c[0]), A_c[1]
                ##### END #####
                self.vacStep += 1
            self.step += 1

        # Use the odeint library to run the ODE model
        z = odeintw(self.internal_model, current_state, np.linspace(0, n, n + 1), args=(self._get_model_params()))
        self._set_current_state(current_state=z[-1].copy())  # save new current state
        self.t += 1
        self.current_state = self.convert_states(self.current_state)
        #print(self.nbrConf)
        # format results
        if labelled_states:
            return self._convert_to_labelled_states(np.atleast_2d(z[1:]))
        else:
            return np.atleast_2d(z[1:])

        Runs the model for n steps

        Parameters
        ----------
        current_state: 1D nd.array
                       Current model state.
        n: int
           Number of steps the model should be run for.

        labelled_states: bool
                         Whether the result should be a dict with state labels or a nd array.

        Returns
        -------
        dict or 2D nd.array
            Returns a dict if labelled_states is True, where keys are state labels.
            Returns an array of size (n, n_states) of the last n model states.

        
Runs the model for n steps
Parameters

1D nd.array
Current model state.
n: int
Number of steps the model should be run for.

bool
Whether the result should be a dict with state labels or a nd array.

Returns

dict or 2D nd.array
Returns a dict if labelled_states is True, where keys are state labels.
Returns an array of size (n, n_states) of the last n model states.
Runs the model for n steps Parameters 1D nd . array Current model state . n : int Number of steps the model should be run for . bool Whether the result should be a dict with state labels or a nd array . Returns dict or 2D nd . array Returns a dict if labelled_states is True where keys are state labels . Returns an array of size ( n n_states ) of the last n model states .
def run_n_steps(self, current_state=None, n=1, labelled_states=False):
        if current_state is None:
            current_state = np.array(self._get_current_state())
        for f in range(16):
            self.dCV1[f] = sum([self.current_state[self._age_groups[f]]['{}'.format(s)] for s in ['CV11', 'CV21', 'CV31', 'CV41']])
            self.dCV2[f] = sum([self.current_state[self._age_groups[f]]['{}'.format(s)] for s in ['CV12', 'CV22', 'CV32', 'CV42']])
        if(self.t == self.step_list[self.step]):
            self.k = k_value(self.t)
            A_c = calculate_A_and_c(self.step, self.k, self.contact_modifiers, self.perturbations_matrices, self.transition_matrices)
            self.current_internal_params['A'], self.current_internal_params['c'] = np.array(A_c[0]), A_c[1]
            self.current_internal_params['nu'] = nu_value(self.t)
            if self.t > 369:
                self.current_internal_params['sigma2'] = np.array(duplicate_data(1/42, 16))
                self.k = k_value(self.t)
                self.politic_decision_module()
                A_c = calculate_A_and_c(self.newstep, self.k, self.contact_modifiers, self.perturbations_matrices, self.transition_matrices)
                self.current_internal_params['A'], self.current_internal_params['c'] = np.array(A_c[0]), A_c[1]
                self.vacStep += 1
            self.step += 1
        z = odeintw(self.internal_model, current_state, np.linspace(0, n, n + 1), args=(self._get_model_params()))
        self._set_current_state(current_state=z[-1].copy())  
        self.t += 1
        self.current_state = self.convert_states(self.current_state)
        if labelled_states:
            return self._convert_to_labelled_states(np.atleast_2d(z[1:]))
        else:
            return np.atleast_2d(z[1:])
def run_n_steps ( self , current_state = None , n = 1 , labelled_states = False ) : if current_state is None : current_state = np . array ( self . _get_current_state ( ) ) for f in range ( 16 ) : self . dCV1 [ f ] = sum ( [ self . current_state [ self . _age_groups [ f ] ] [ '{}' . format ( s ) ] for s in [ 'CV11' , 'CV21' , 'CV31' , 'CV41' ] ] ) self . dCV2 [ f ] = sum ( [ self . current_state [ self . _age_groups [ f ] ] [ '{}' . format ( s ) ] for s in [ 'CV12' , 'CV22' , 'CV32' , 'CV42' ] ] ) if ( self . t == self . step_list [ self . step ] ) : self . k = k_value ( self . t ) A_c = calculate_A_and_c ( self . step , self . k , self . contact_modifiers , self . perturbations_matrices , self . transition_matrices ) self . current_internal_params [ 'A' ] , self . current_internal_params [ 'c' ] = np . array ( A_c [ 0 ] ) , A_c [ 1 ] self . current_internal_params [ 'nu' ] = nu_value ( self . t ) if self . t > 369 : self . current_internal_params [ 'sigma2' ] = np . array ( duplicate_data ( 1 / 42 , 16 ) ) self . k = k_value ( self . t ) self . politic_decision_module ( ) A_c = calculate_A_and_c ( self . newstep , self . k , self . contact_modifiers , self . perturbations_matrices , self . transition_matrices ) self . current_internal_params [ 'A' ] , self . current_internal_params [ 'c' ] = np . array ( A_c [ 0 ] ) , A_c [ 1 ] self . vacStep += 1 self . step += 1 z = odeintw ( self . internal_model , current_state , np . linspace ( 0 , n , n + 1 ) , args = ( self . _get_model_params ( ) ) ) self . _set_current_state ( current_state = z [ - 1 ] . copy ( ) ) self . t += 1 self . current_state = self . convert_states ( self . current_state ) if labelled_states : return self . _convert_to_labelled_states ( np . atleast_2d ( z [ 1 : ] ) ) else : return np . atleast_2d ( z [ 1 : ] )
Runs the model for n steps
Parameters
Runs the model for n steps Parameters
"""
        Runs the model for n steps

        Parameters
        ----------
        current_state: 1D nd.array
                       Current model state.
        n: int
           Number of steps the model should be run for.

        labelled_states: bool
                         Whether the result should be a dict with state labels or a nd array.

        Returns
        -------
        dict or 2D nd.array
            Returns a dict if labelled_states is True, where keys are state labels.
            Returns an array of size (n, n_states) of the last n model states.

        """ # Update the number of people vaccinated with 1 or 2 doses # To uncomment if we want to run the initial model # sigma = self.compute_sigma() # self.current_internal_params['sigma'] = np.array(sigma) ##### TO COMMENT #### # if we want to run the initial model ##### END ##### # Use the odeint library to run the ODE model # save new current state #print(self.nbrConf) # format results
self
current_state
n
labelled_states