INNER CODE UNIT · Python
get_trajectory_from_environment
GoogleCloudPlatform/vertex-ai-samples · community-content/tf_agents_bandits_movie_recommendation_with_kfp_and_vertex_sdk/mlops_pipeline_tf_agents_bandits_movie_recommendation/src/logger/main.py:99
def get_trajectory_from_environment(
environment: tf_py_environment.TFPyEnvironment,
observation: List[List[float]],
predicted_action: int) -> trajectories.Trajectory:
"""Gets trajectory data from `environment` based on observation and action.
Aligns `environment` observation to `observation` so that its feedback align
with `observation`. The `trajectories.Trajectory` object contains time step
information before and after applying `predicted_action` and feedback in the
form of a reward.
In production, this function can be replaced to actually pull feedback from
some real-world environment.
Args:
environment: A TF-Agents environment that holds observations, apply actions
and returns rewards.
observation: A single, batched observation.