code: def update(
      Q, target_Q, opt, samples, gamma=0.99, target_type="double_dqn"
  ):
      """Update a Q-function with given samples and a target Q-function."""
      dtype = chainer.get_dtype()
      xp = Q.xp
      obs = xp.asarray([sample[0] for sample in samples], dtype=dtype)
      action = xp.asarray(
          [sample[1] for sample in samples], dtype=np.int32
      )
      reward = xp.asarray(
          [sample[2] for sample in samples], dtype=dtype
      )
      done = xp.asarray([sample[3] for sample in samples], dtype=dtype)
      obs_next = xp.asarray(
          [sample[4] for sample in samples], dtype=dtype
      )
      # Predicted values: Q(s,a)
      y = F.select_item(Q(obs), action)
      # Target values: r + gamma * max_b Q(s',b)
      with chainer.no_backprop_mode():
          if target_type == "dqn":
              next_q = F.max(target_Q(obs_next), axis=1)
          elif target_type == "double_dqn":
              next_q = F.select_item(
                  target_Q(obs_next), F.argmax(Q(obs_next), axis=1)
              )
          else:
              raise ValueError(
                  "Unsupported target_type: {}".format(target_type)
              )
          target = reward + gamma * (1 - done) * next_q
      loss = mean_clipped_loss(y, target)
      Q.cleargrads()
      loss.backward()
      opt.update()
  
imports: from __future__ import division
  import argparse
  import collections
  import copy
  import random
  import warnings
  import gym
  import numpy
  import chainer
  from chainer import functions
  from chainer import links
  from chainer import optimizers
label_desc: Use image node_id 3 for calling a global function with example usage: update(Q, target_Q, opt, samples, gamma, target_type) without return types