class_docstr: Class implementing policy gradient algorithm to train portfolio
  optimization agents.
  
  Note:
      During testing, the agent is optimized through online learning.
      The parameters of the policy is updated repeatedly after a constant
      period of time. To disable it, set learning rate to 0.
  
  Attributes:
      train_env: Environment used to train the agent
      train_policy: Policy used in training.
      test_env: Environment used to test the agent.
      test_policy: Policy after test online learning.
class_docstr_tok: ["Class","implementing","policy","gradient","algorithm","to","train","portfolio","optimization","agents",".","Note",":","During","testing",",","the","agent","is","optimized","through","online","learning",".","The","parameters","of","the","policy","is","updated","repeatedly","after","a","constant","period","of","time",".","To","disable","it",",","set","learning","rate","to","0",".","Attributes",":","train_env",":","Environment","used","to","train","the","agent","train_policy",":","Policy","used","in","training",".","test_env",":","Environment","used","to","test","the","agent",".","test_policy",":","Policy","after","test","online","learning","."]
docstr: Initializes algorithm before training.
  
  Args:
    env: environment.
    policy: Policy architecture to be used.
    batch_size: Batch size to train neural network.
    lr: Policy neural network learning rate.
    optimizer: Optimizer of neural network.
docstr_tok: ["Initializes","algorithm","before","training",".","Args",":","env",":","environment",".","policy",":","Policy","architecture","to","be","used",".","batch_size",":","Batch","size","to","train","neural","network",".","lr",":","Policy","neural","network","learning","rate",".","optimizer",":","Optimizer","of","neural","network","."]
code: def _setup_train(self, env, policy, batch_size, lr, optimizer):
      """Initializes algorithm before training.
  
      Args:
        env: environment.
        policy: Policy architecture to be used.
        batch_size: Batch size to train neural network.
        lr: Policy neural network learning rate.
        optimizer: Optimizer of neural network.
      """
      # environment
      self.train_env = env
  
      # neural networks
      self.train_policy = policy(**self.policy_kwargs).to(self.device)
      self.train_optimizer = optimizer(
          self.train_policy.parameters(), lr=lr
      )
  
      # replay buffer and portfolio vector memory
      self.train_batch_size = batch_size
      self.train_buffer = ReplayBuffer(capacity=batch_size)
      self.train_pvm = PVM(
          self.train_env.episode_length, env.portfolio_size
      )
  
      # dataset and dataloader
      dataset = RLDataset(self.train_buffer)
      self.train_dataloader = DataLoader(
          dataset=dataset,
          batch_size=batch_size,
          shuffle=False,
          pin_memory=True,
      )
  
file_path: FinRL/finrl/agents/portfolio_optimization/algorithms.py
imports: from __future__ import annotations
  import copy
  import numpy
  import torch
  from torch.optim import AdamW
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from .architectures import EIIE
  from .utils import PVM
  from .utils import ReplayBuffer
  from .utils import RLDataset
label_desc: Use image node_id 2 for calling the PolicyGradient obj's underlying member method code with example usage: obj._setup_train(env, policy, batch_size, lr, optimizer) without return types