class_docstr: Base class for modules.
  
  Args:
      device (string): Device name
          (<span style="color:#00C000"><b>default</b></span>: inherit value of parent module).
      l2_regularization (float >= 0.0): Scalar controlling L2 regularization
          (<span style="color:#00C000"><b>default</b></span>: inherit value of parent module).
      name (string): <span style="color:#0000C0"><b>internal use</b></span>.
code: def variable(
      self,
      *,
      name,
      spec,
      initializer,
      is_trainable,
      is_saved,
      initialization_scale=None,
  ):
      assert self.is_initialized is False
      # name
      if not isinstance(name, str):
          raise TensorforceError.type(
              name="variable", argument="name", dtype=type(name)
          )
      name = name.replace("/", "_")
      # spec
      if not isinstance(spec, TensorSpec):
          raise TensorforceError.type(
              name="variable", argument="spec", dtype=type(spec)
          )
      if spec.is_underspecified():
          raise TensorforceError.value(
              name="variable",
              argument="spec",
              value=spec,
              hint="underspecified",
          )
      # initializer
      initializer_names = (
          "constant",
          "normal",
          "normal-relu",
          "ones",
          "orthogonal",
          "orthogonal-relu",
          "zeros",
      )
      if (
          not isinstance(
              initializer, (spec.py_type(), np.ndarray, tf.Tensor)
          )
          and initializer not in initializer_names
      ):
          raise TensorforceError.value(
              name="variable", argument="initializer", value=initializer
          )
      elif (
          isinstance(initializer, np.ndarray)
          and initializer.dtype != spec.np_type()
      ):
          raise TensorforceError.type(
              name="variable",
              argument="initializer",
              dtype=initializer.dtype,
          )
      elif (
          isinstance(initializer, tf.Tensor)
          and tf_util.dtype(x=initializer) != spec.tf_type()
      ):
          raise TensorforceError.type(
              name="variable",
              argument="initializer",
              dtype=tf_util.dtype(x=initializer),
          )
      # initialization_scale
      if initialization_scale is not None:
          if isinstance(
              initializer, (spec.py_type(), np.ndarray, tf.Tensor)
          ) or initializer not in (
              "constant",
              "orthogonal",
              "orthogonal-relu",
          ):
              raise TensorforceError.invalid(
                  name="variable",
                  argument="initialization_scale",
                  condition="initializer not orthogonal",
              )
          elif not isinstance(initialization_scale, spec.py_type()):
              raise TensorforceError.type(
                  name="variable",
                  argument="initialization_scale",
                  dtype=type(initialization_scale),
                  hint="!= float",
              )
      # is_trainable
      if not isinstance(is_trainable, bool):
          raise TensorforceError.type(
              name="variable",
              argument="is_trainable",
              dtype=type(is_trainable),
          )
      elif is_trainable and spec.type != "float":
          raise TensorforceError.value(
              name="variable",
              argument="is_trainable",
              value=is_trainable,
              condition="spec.type != float",
          )
      # is_saved
      if not isinstance(is_saved, bool):
          raise TensorforceError.type(
              name="variable", argument="is_saved", dtype=type(is_saved)
          )
  
      # Variable initializer
      if isinstance(initializer, spec.py_type()):
          initializer = tf_util.constant(
              value=initializer, dtype=spec.type, shape=spec.shape
          )
      elif isinstance(initializer, np.ndarray):
          if initializer.shape != spec.shape:
              raise TensorforceError.mismatch(
                  name="Module.variable",
                  value1="shape",
                  value2="initializer",
              )
          initializer = tf_util.constant(
              value=initializer, dtype=spec.type
          )
      elif isinstance(initializer, tf.Tensor):
          if tf_util.shape(x=initializer) != spec.shape:
              raise TensorforceError.mismatch(
                  name="Module.variable",
                  value1="shape",
                  value2="initializer",
              )
          initializer = initializer
      elif not isinstance(initializer, str):
          raise TensorforceError(
              "Invalid variable initializer: {}".format(initializer)
          )
      elif initializer.startswith("normal"):
          if spec.type != "float":
              raise TensorforceError(
                  message="Invalid variable initializer value for non-float variable: {}.".format(
                      initializer
                  )
              )
          if initializer.endswith("-relu"):
              stddev = min(
                  0.1, np.sqrt(2.0 / util.product(xs=spec.shape[:-1]))
              )
          else:
              stddev = min(
                  0.1,
                  np.sqrt(
                      2.0
                      / (
                          util.product(xs=spec.shape[:-1])
                          + spec.shape[-1]
                      )
                  ),
              )
          initializer = tf.random.normal(
              shape=spec.shape, stddev=stddev, dtype=spec.tf_type()
          )
      elif initializer.startswith("orthogonal"):
          if spec.type != "float":
              raise TensorforceError(
                  message="Invalid variable initializer value for non-float variable: {}.".format(
                      initializer
                  )
              )
          if spec.rank < 2:
              raise TensorforceError(
                  message="Invalid variable initializer value for 0/1-rank variable: {}.".format(
                      initializer
                  )
              )
          normal = np.random.normal(
              size=(util.product(xs=spec.shape[:-1]), spec.shape[-1])
          )
          u, _, v = np.linalg.svd(a=normal, full_matrices=False)
          orthogonal = u if u.shape[1] == spec.shape[-1] else v
          if initializer.endswith("-relu"):
              orthogonal = orthogonal * np.sqrt(2.0)
          if (
              initialization_scale is not None
              and initialization_scale != 1.0
          ):
              if initialization_scale <= 0.0:
                  raise TensorforceError.value(
                      name="variable",
                      argument="initialization_scale",
                      value=initialization_scale,
                      hint="<= 0.0",
                  )
              orthogonal = orthogonal * initialization_scale
          initializer = tf_util.constant(
              value=orthogonal.reshape(spec.shape), dtype=spec.type
          )
      elif initializer == "zeros":
          initializer = tf_util.zeros(shape=spec.shape, dtype=spec.type)
      elif initializer == "ones":
          initializer = tf_util.ones(shape=spec.shape, dtype=spec.type)
      elif initializer == "constant":
          initializer = tf.fill(
              dims=spec.shape,
              value=tf_util.constant(
                  value=initialization_scale, dtype=spec.type
              ),
          )
  
      # Variable
      variable = tf.Variable(
          initial_value=initializer,
          trainable=is_trainable,
          validate_shape=True,
          name=name,
          dtype=spec.tf_type(),
          shape=spec.shape,
      )
      variable.is_saved = is_saved
  
      return variable
  
imports: import functools
  import json
  import os
  import re
  import numpy
  import tensorflow
  from tensorforce import TensorforceError, util
  import tensorforce.core
  from tensorforce.core import SignatureDict, TensorSpec, tf_util, VariableDict
label_desc: Use image node_id 20 for calling the Module obj's underlying member method code with example usage: obj.variable() and returns: variable