class_docstr: A base distribution and normalizing flow for applying transformations.
  
  Normalizing flows are effective for any application requiring
  a probabilistic model that can both sample from a distribution and
  compute marginal likelihoods, e.g. generative modeling,
  unsupervised learning, or probabilistic inference. For a thorough review
  of normalizing flows, see [1]_.
  
  A distribution implements two main operations:
      1. Sampling from the transformed distribution
      2. Calculating log probabilities
  
  A normalizing flow implements three main operations:
      1. Forward transformation
      2. Inverse transformation
      3. Calculating the Jacobian
  
  Deep Normalizing Flow models require normalizing flow layers where
  input and output dimensions are the same, the transformation is invertible,
  and the determinant of the Jacobian is efficient to compute and
  differentiable. The determinant of the Jacobian of the transformation
  gives a factor that preserves the probability volume to 1 when transforming
  between probability densities of different random variables.
  
  References
  ----------
  .. [1] Papamakarios, George et al. "Normalizing Flows for Probabilistic Modeling and Inference." (2019). https://arxiv.org/abs/1912.02762.
class_docstr_tok: ["A","base","distribution","and","normalizing","flow","for","applying","transformations",".","Normalizing","flows","are","effective","for","any","application","requiring","a","probabilistic","model","that","can","both","sample","from","a","distribution","and","compute","marginal","likelihoods",",","e.g",".","generative","modeling",",","unsupervised","learning",",","or","probabilistic","inference",".","For","a","thorough","review","of","normalizing","flows",",","see","[","1","]","_",".","A","distribution","implements","two","main","operations",":","1",".","Sampling","from","the","transformed","distribution","2",".","Calculating","log","probabilities","A","normalizing","flow","implements","three","main","operations",":","1",".","Forward","transformation","2",".","Inverse","transformation","3",".","Calculating","the","Jacobian","Deep","Normalizing","Flow","models","require","normalizing","flow","layers","where","input","and","output","dimensions","are","the","same",",","the","transformation","is","invertible",",","and","the","determinant","of","the","Jacobian","is","efficient","to","compute","and","differentiable",".","The","determinant","of","the","Jacobian","of","the","transformation","gives","a","factor","that","preserves","the","probability","volume","to","1","when","transforming","between","probability","densities","of","different","random","variables",".","References","--","--","--","--","--","..","[","1","]","Papamakarios",",","George","et","al",".","``","Normalizing","Flows","for","Probabilistic","Modeling","and","Inference",".","''","(","2019",")",".","https",":","\/\/arxiv.org\/abs\/1912.02762","."]
docstr: Creates a new NormalizingFlowModel.
  
  In addition to the following arguments, this class also accepts all the keyword arguments from KerasModel.
  
  Parameters
  ----------
  model: NormalizingFlow
      An instance of NormalizingFlow.
  
  Examples
  --------
  >> import tensorflow_probability as tfp
  >> tfd = tfp.distributions
  >> tfb = tfp.bijectors
  >> flow_layers = [
  ..    tfb.RealNVP(
  ..        num_masked=2,
  ..        shift_and_log_scale_fn=tfb.real_nvp_default_template(
  ..            hidden_layers=[8, 8]))
  ..]
  >> base_distribution = tfd.MultivariateNormalDiag(loc=[0., 0., 0.])
  >> nf = NormalizingFlow(base_distribution, flow_layers)
  >> nfm = NormalizingFlowModel(nf)
  >> dataset = NumpyDataset(
  ..    X=np.random.rand(5, 3).astype(np.float32),
  ..    y=np.random.rand(5,),
  ..    ids=np.arange(5))
  >> nfm.fit(dataset)
docstr_tok: ["Creates","a","new","NormalizingFlowModel",".","In","addition","to","the","following","arguments",",","this","class","also","accepts","all","the","keyword","arguments","from","KerasModel",".","Parameters","--","--","--","--","--","model",":","NormalizingFlow","An","instance","of","NormalizingFlow",".","Examples","--","--","--","--",">",">","import","tensorflow_probability","as","tfp",">",">","tfd","=","tfp.distributions",">",">","tfb","=","tfp.bijectors",">",">","flow_layers","=","[","..","tfb.RealNVP","(","..","num_masked=2",",","..","shift_and_log_scale_fn=tfb.real_nvp_default_template","(","..","hidden_layers=","[","8",",","8","]",")",")","..","]",">",">","base_distribution","=","tfd.MultivariateNormalDiag","(","loc=","[","0.",",","0.",",","0",".","]",")",">",">","nf","=","NormalizingFlow","(","base_distribution",",","flow_layers",")",">",">","nfm","=","NormalizingFlowModel","(","nf",")",">",">","dataset","=","NumpyDataset","(","..","X=np.random.rand","(","5",",","3",")",".astype","(","np.float32",")",",","..","y=np.random.rand","(","5",",",")",",","..","ids=np.arange","(","5",")",")",">",">","nfm.fit","(","dataset",")"]
code: def __init__(self, model: NormalizingFlow, **kwargs) -> None:
      """Creates a new NormalizingFlowModel.
  
      In addition to the following arguments, this class also accepts all the keyword arguments from KerasModel.
  
      Parameters
      ----------
      model: NormalizingFlow
          An instance of NormalizingFlow.
  
      Examples
      --------
      >> import tensorflow_probability as tfp
      >> tfd = tfp.distributions
      >> tfb = tfp.bijectors
      >> flow_layers = [
      ..    tfb.RealNVP(
      ..        num_masked=2,
      ..        shift_and_log_scale_fn=tfb.real_nvp_default_template(
      ..            hidden_layers=[8, 8]))
      ..]
      >> base_distribution = tfd.MultivariateNormalDiag(loc=[0., 0., 0.])
      >> nf = NormalizingFlow(base_distribution, flow_layers)
      >> nfm = NormalizingFlowModel(nf)
      >> dataset = NumpyDataset(
      ..    X=np.random.rand(5, 3).astype(np.float32),
      ..    y=np.random.rand(5,),
      ..    ids=np.arange(5))
      >> nfm.fit(dataset)
  
      """
  
      try:
          import tensorflow_probability as tfp
  
          _ = tfp.distributions
          _ = tfp.bijectors
      except ModuleNotFoundError:
          raise ImportError(
              "This class requires tensorflow-probability to be installed."
          )
  
      self.nll_loss_fn = lambda input, labels, weights: self.create_nll(
          input
      )
  
      super(NormalizingFlowModel, self).__init__(
          model=model, loss=self.nll_loss_fn, **kwargs
      )
  
      self.flow = self.model.flow
  
imports: import logging
  from typing import List, Optional, Sequence, Callable
  import tensorflow
  from deepchem.models.keras_model import KerasModel
  from deepchem.utils.typing import OneOrMany
  from deepchem.utils.data_utils import load_from_disk, save_to_disk
label_desc: Use image node_id 1 to create a new NormalizingFlowModel object from inherited base classes: KerasModel with example: obj = NormalizingFlowModel(model)