class_docstr: An adapter to convert an existing model to have a vector-valued support.
  
  This adapter makes it convenient to use the Inference Gym models with
  inference algorithms which cannot handle structured events. It does so by
  reshaping individual event Tensors and concatenating them into a single
  vector.
  
  The resultant vector-valued model has updated properties and sample
  transformations which reflect the transformation above. By default, the sample
  transformations will still return structured values. This behavior can be
  altered via the `flatten_sample_transformations` argument.
  
  There are only two restrictions on the models that can be handled by this
  class:
  
  1. The individual Tensors in an event must all have the same dtype.
  2. The `default_event_space_bijector` must apply to a single tensor at time.
  
  The second restriction will be lifted soon.
  
  #### Example
  
  ```
  base_model = gym.targets.SyntheticItemResponseTheory()
  vec_model = gym.targets.VectorModel(base_model)
  
  base_model.dtype
  # ==> {
  #         'mean_student_ability': tf.float32,
  #         'centered_student_ability': tf.float32,
  #         'question_difficulty': tf.float32,
  #     }
  
  vec_model.dtype
  # ==> tf.float32
  
  base_model.event_shape
  # ==> {
  #         'mean_student_ability': [],
  #         'centered_student_ability': [400],
  #         'question_difficulty': [100],
  #     }
  
  vec_model.event_shape
  # ==> [501]
  ```
class_docstr_tok: ["An","adapter","to","convert","an","existing","model","to","have","a","vector-valued","support",".","This","adapter","makes","it","convenient","to","use","the","Inference","Gym","models","with","inference","algorithms","which","can","not","handle","structured","events",".","It","does","so","by","reshaping","individual","event","Tensors","and","concatenating","them","into","a","single","vector",".","The","resultant","vector-valued","model","has","updated","properties","and","sample","transformations","which","reflect","the","transformation","above",".","By","default",",","the","sample","transformations","will","still","return","structured","values",".","This","behavior","can","be","altered","via","the","`","flatten_sample_transformations","`","argument",".","There","are","only","two","restrictions","on","the","models","that","can","be","handled","by","this","class",":","1",".","The","individual","Tensors","in","an","event","must","all","have","the","same","dtype",".","2",".","The","`","default_event_space_bijector","`","must","apply","to","a","single","tensor","at","time",".","The","second","restriction","will","be","lifted","soon",".","#","#","#","#","Example","``","`","base_model","=","gym.targets.SyntheticItemResponseTheory","(",")","vec_model","=","gym.targets.VectorModel","(","base_model",")","base_model.dtype","#","==",">","{","#","'mean_student_ability","'",":","tf.float32",",","#","'centered_student_ability","'",":","tf.float32",",","#","'question_difficulty","'",":","tf.float32",",","#","}","vec_model.dtype","#","==",">","tf.float32","base_model.event_shape","#","==",">","{","#","'mean_student_ability","'",":","[","]",",","#","'centered_student_ability","'",":","[","400","]",",","#","'question_difficulty","'",":","[","100","]",",","#","}","vec_model.event_shape","#","==",">","[","501","]","``","`"]
docstr: Constructs the adapter.
  
  Args:
    model: An Inference Gym model.
    flatten_sample_transformations: Python bool. Whether to flatten and
      concatenate the outputs of sample transformations.
  
  Raises:
    TypeError: If `model` has more than one unique Tensor dtype.
    TypeError: If `flatten_sample_transformations` is `True` and there is a
      sample transformation that has more than one unique Tensor dtype.
docstr_tok: ["Constructs","the","adapter",".","Args",":","model",":","An","Inference","Gym","model",".","flatten_sample_transformations",":","Python","bool",".","Whether","to","flatten","and","concatenate","the","outputs","of","sample","transformations",".","Raises",":","TypeError",":","If","`","model","`","has","more","than","one","unique","Tensor","dtype",".","TypeError",":","If","`","flatten_sample_transformations","`","is","`","True","`","and","there","is","a","sample","transformation","that","has","more","than","one","unique","Tensor","dtype","."]
code: def __init__(self, model, flatten_sample_transformations=False):
      """Constructs the adapter.
  
      Args:
        model: An Inference Gym model.
        flatten_sample_transformations: Python bool. Whether to flatten and
          concatenate the outputs of sample transformations.
  
      Raises:
        TypeError: If `model` has more than one unique Tensor dtype.
        TypeError: If `flatten_sample_transformations` is `True` and there is a
          sample transformation that has more than one unique Tensor dtype.
      """
      self._model = model
  
      super(VectorModel, self).__init__(
          default_event_space_bijector=_make_vector_event_space_bijector(
              self._model
          ),
          event_shape=_get_vector_event_shape(self._model),
          dtype=_get_unique_dtype(
              self._model.dtype,
              "Model must have only one Tensor dtype, saw: {}".format,
          ),
          name="vector_" + self._model.name,
          pretty_name=str(self._model),
          sample_transformations=_make_vector_sample_transformations(
              self._model, flatten_sample_transformations
          ),
      )
  
file_path: probability/spinoffs/inference_gym/inference_gym/targets/vector_model.py
imports: import collections
  import functools
  import tensorflow.compat.v2
  import tensorflow_probability
  from tensorflow_probability.python.internal import prefer_static
  from inference_gym.targets import model
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 to create a new VectorModel object from inherited base classes: model_lib with example: obj = VectorModel(model, flatten_sample_transformations)