epidemioptim/environments/gym_envs/epidemic_vaccination_16.py
def step(self, action):
        """
        Traditional step function from OpenAI Gym envs. Uses the action to update the environment.

        Parameters
        ----------
        action: int
            Action is a list with 0 (no vaccination) or 1 (vaccination).

        Returns
        -------
        state: nd.array
            New environment state.
        cost_aggregated: float
            Aggregated measure of the cost.
        done: bool
            Whether the episode is terminated.
        info: dict
            Further infos. In our case, the costs, icu capacity of the region and whether constraints are violated.

        """
        if isinstance(action, np.ndarray):
            action = self.transpose_actions[action[0]]
        action = list(action)
        self.update_with_action(action)
        
        # Run model for jump_of steps
        model_state = [self.model_state]
        model_states = []
        for i in range(15):
            model_state = self.model.run_n_steps(model_state[-1], 1)
            model_states += model_state.tolist()
        self.model_state = model_state[-1]  # last internal state is the new current one
        self.t += self.jump_of

        # Update state
        self._update_previous_env_state()
        self._update_env_state()

        # Store history
        costs = [c.compute_cost(previous_state=np.atleast_2d(self.previous_env_state),
                                                state=np.atleast_2d(self.env_state),
                                                label_to_id=self.label_to_id,
                                                action=action,
                                                others=dict(jump_of=self.time_resolution)) for c in self.cost_function.costs]
        self.cumulative_costs[0] += costs[0]
        n_deaths = self.cost_function.compute_deaths(previous_state=np.atleast_2d(self.previous_env_state),
                                                     state=np.atleast_2d(self.env_state),
                                                     label_to_id=self.label_to_id,
                                                     action=action)

        self._update_env_state()
        self.history['actions'] += [action] * self.jump_of
        self.history['env_states'] += [self.env_state.copy()] * self.jump_of
        self.history['env_timesteps'] += list(range(self.t - self.jump_of, self.t))
        self.history['model_states'] += model_states
        self.history['vaccinations'] += [self.vaccination_politic] * self.jump_of
        self.history['deaths'] += [n_deaths] * self.jump_of#[n_deaths / self.jump_of] * self.jump_of

        # Compute cost_function
        self.history['costs'] += [costs[0] / self.jump_of for _ in range(self.jump_of)]

        cost_aggregated, costs, over_constraints = self.cost_function.compute_cost(previous_state=self.previous_env_state,
                                                                                   state=self.env_state,
                                                                                   label_to_id=self.label_to_id,
                                                                                   action=action,
                                                                                   others=dict(jump_of=self.jump_of))
        costs = costs.flatten()
        self.history['aggregated_costs'] += [cost_aggregated / self.jump_of] * self.jump_of
        self.history['costs'] += [costs / self.jump_of for _ in range(self.jump_of)]
        if self.t >= self.simulation_horizon:
            done = 1
        else:
            done = 0
        return self._normalize_env_state(self.env_state), cost_aggregated, done, dict(costs=costs)

        Traditional step function from OpenAI Gym envs. Uses the action to update the environment.

        Parameters
        ----------
        action: int
            Action is a list with 0 (no vaccination) or 1 (vaccination).

        Returns
        -------
        state: nd.array
            New environment state.
        cost_aggregated: float
            Aggregated measure of the cost.
        done: bool
            Whether the episode is terminated.
        info: dict
            Further infos. In our case, the costs, icu capacity of the region and whether constraints are violated.

        
Traditional step function from OpenAI Gym envs. Uses the action to update the environment.
Parameters

int
Action is a list with 0 (no vaccination) or 1 (vaccination).

Returns


Traditional step function from OpenAI Gym envs . Uses the action to update the environment . Parameters int Action is a list with 0 ( no vaccination ) or 1 ( vaccination ) . Returns
def step(self, action):
        if isinstance(action, np.ndarray):
            action = self.transpose_actions[action[0]]
        action = list(action)
        self.update_with_action(action)
        model_state = [self.model_state]
        model_states = []
        for i in range(15):
            model_state = self.model.run_n_steps(model_state[-1], 1)
            model_states += model_state.tolist()
        self.model_state = model_state[-1]  
        self.t += self.jump_of
        self._update_previous_env_state()
        self._update_env_state()
        costs = [c.compute_cost(previous_state=np.atleast_2d(self.previous_env_state),
                                                state=np.atleast_2d(self.env_state),
                                                label_to_id=self.label_to_id,
                                                action=action,
                                                others=dict(jump_of=self.time_resolution)) for c in self.cost_function.costs]
        self.cumulative_costs[0] += costs[0]
        n_deaths = self.cost_function.compute_deaths(previous_state=np.atleast_2d(self.previous_env_state),
                                                     state=np.atleast_2d(self.env_state),
                                                     label_to_id=self.label_to_id,
                                                     action=action)
        self._update_env_state()
        self.history['actions'] += [action] * self.jump_of
        self.history['env_states'] += [self.env_state.copy()] * self.jump_of
        self.history['env_timesteps'] += list(range(self.t - self.jump_of, self.t))
        self.history['model_states'] += model_states
        self.history['vaccinations'] += [self.vaccination_politic] * self.jump_of
        self.history['deaths'] += [n_deaths] * self.jump_of
        self.history['costs'] += [costs[0] / self.jump_of for _ in range(self.jump_of)]
        cost_aggregated, costs, over_constraints = self.cost_function.compute_cost(previous_state=self.previous_env_state,
                                                                                   state=self.env_state,
                                                                                   label_to_id=self.label_to_id,
                                                                                   action=action,
                                                                                   others=dict(jump_of=self.jump_of))
        costs = costs.flatten()
        self.history['aggregated_costs'] += [cost_aggregated / self.jump_of] * self.jump_of
        self.history['costs'] += [costs / self.jump_of for _ in range(self.jump_of)]
        if self.t >= self.simulation_horizon:
            done = 1
        else:
            done = 0
        return self._normalize_env_state(self.env_state), cost_aggregated, done, dict(costs=costs)
def step ( self , action ) : if isinstance ( action , np . ndarray ) : action = self . transpose_actions [ action [ 0 ] ] action = list ( action ) self . update_with_action ( action ) model_state = [ self . model_state ] model_states = [ ] for i in range ( 15 ) : model_state = self . model . run_n_steps ( model_state [ - 1 ] , 1 ) model_states += model_state . tolist ( ) self . model_state = model_state [ - 1 ] self . t += self . jump_of self . _update_previous_env_state ( ) self . _update_env_state ( ) costs = [ c . compute_cost ( previous_state = np . atleast_2d ( self . previous_env_state ) , state = np . atleast_2d ( self . env_state ) , label_to_id = self . label_to_id , action = action , others = dict ( jump_of = self . time_resolution ) ) for c in self . cost_function . costs ] self . cumulative_costs [ 0 ] += costs [ 0 ] n_deaths = self . cost_function . compute_deaths ( previous_state = np . atleast_2d ( self . previous_env_state ) , state = np . atleast_2d ( self . env_state ) , label_to_id = self . label_to_id , action = action ) self . _update_env_state ( ) self . history [ 'actions' ] += [ action ] * self . jump_of self . history [ 'env_states' ] += [ self . env_state . copy ( ) ] * self . jump_of self . history [ 'env_timesteps' ] += list ( range ( self . t - self . jump_of , self . t ) ) self . history [ 'model_states' ] += model_states self . history [ 'vaccinations' ] += [ self . vaccination_politic ] * self . jump_of self . history [ 'deaths' ] += [ n_deaths ] * self . jump_of self . history [ 'costs' ] += [ costs [ 0 ] / self . jump_of for _ in range ( self . jump_of ) ] cost_aggregated , costs , over_constraints = self . cost_function . compute_cost ( previous_state = self . previous_env_state , state = self . env_state , label_to_id = self . label_to_id , action = action , others = dict ( jump_of = self . jump_of ) ) costs = costs . flatten ( ) self . history [ 'aggregated_costs' ] += [ cost_aggregated / self . jump_of ] * self . jump_of self . history [ 'costs' ] += [ costs / self . jump_of for _ in range ( self . jump_of ) ] if self . t >= self . simulation_horizon : done = 1 else : done = 0 return self . _normalize_env_state ( self . env_state ) , cost_aggregated , done , dict ( costs = costs )
Traditional step function from OpenAI Gym envs.
Traditional step function from OpenAI Gym envs .
"""
        Traditional step function from OpenAI Gym envs. Uses the action to update the environment.

        Parameters
        ----------
        action: int
            Action is a list with 0 (no vaccination) or 1 (vaccination).

        Returns
        -------
        state: nd.array
            New environment state.
        cost_aggregated: float
            Aggregated measure of the cost.
        done: bool
            Whether the episode is terminated.
        info: dict
            Further infos. In our case, the costs, icu capacity of the region and whether constraints are violated.

        """ # Run model for jump_of steps # last internal state is the new current one # Update state # Store history #[n_deaths / self.jump_of] * self.jump_of # Compute cost_function
self
action