docstr: Reward at each step is a linear function of present state and action.
  However, we can only observe aggregated reward at the last step
  
  This model will fail to learn when ground-truth reward is a function of
  multiple steps' states and actions.
docstr_tok: ["Reward","at","each","step","is","a","linear","function","of","present","state","and","action",".","However",",","we","can","only","observe","aggregated","reward","at","the","last","step","This","model","will","fail","to","learn","when","ground-truth","reward","is","a","function","of","multiple","steps","'","states","and","actions","."]
code: def _test_linear_reward_parametric_reward(
      self, ground_truth_reward_from_multiple_steps=False
  ):
      """
      Reward at each step is a linear function of present state and action.
      However, we can only observe aggregated reward at the last step
  
      This model will fail to learn when ground-truth reward is a function of
      multiple steps' states and actions.
      """
      state_dim = 10
      action_dim = 2
      seq_len = 5
      batch_size = 512
      num_batches = 5000
      sizes = [256, 128]
      activations = ["relu", "relu"]
      last_layer_activation = "linear"
      reward_net = SyntheticRewardNet(
          SingleStepSyntheticRewardNet(
              state_dim=state_dim,
              action_dim=action_dim,
              sizes=sizes,
              activations=activations,
              last_layer_activation=last_layer_activation,
          )
      )
      optimizer = Optimizer__Union(Adam=classes["Adam"]())
      trainer = RewardNetTrainer(reward_net, optimizer)
      trainer.set_reporter(
          RewardNetworkReporter(
              trainer.loss_type,
              str(reward_net),
          )
      )
      if ground_truth_reward_from_multiple_steps:
          weight, data = create_sequence_data(
              state_dim, action_dim, seq_len, batch_size, num_batches
          )
      else:
          weight, data = create_data(
              state_dim, action_dim, seq_len, batch_size, num_batches
          )
      avg_eval_loss = train_and_eval(trainer, data)
      return avg_eval_loss
  
imports: import logging
  import unittest
  import pytorch_lightning
  import torch
  from reagent.core import parameters, types
  from reagent.models.synthetic_reward import NGramConvolutionalNetwork, NGramFullyConnectedNetwork, SequenceSyntheticRewardNet, SingleStepSyntheticRewardNet, SyntheticRewardNet, TransformerSyntheticRewardNet
  from reagent.optimizer.union import classes, Optimizer__Union
  from reagent.reporting.reward_network_reporter import RewardNetworkReporter
  from reagent.training import RewardNetTrainer
  from reagent.training.reward_network_trainer import LossFunction
  from torch.utils.data import DataLoader
label_desc: Use image node_id 4 for calling the TestSyntheticRewardTraining obj's underlying member method code with example usage: obj._test_linear_reward_parametric_reward(ground_truth_reward_from_multiple_steps) and returns: avg_eval_loss