class_docstr: The Two-Piece Normal distribution.
  
  The Two-Piece Normal generalizes the Normal distribution with an additional
  shape parameter. Under the general formulation proposed by [Fernández and
  Steel (1998)][2], it is parameterized by location `loc`, scale `scale`, and
  shape `skewness`. If `skewness` is above one, the distribution becomes right-
  skewed (or positively skewed). If `skewness` is greater than zero and less
  than one, the distribution becomes left-skewed (or negatively skewed). The
  Normal distribution is retrieved when `skewness` is equal to one.
  
  This distribution is also called the Fernández-Steel Skew Normal distribution
  [(Castillo et al., 2011)][1], the Skew Normal Type 2 distribution [(Rigby et
  al., 2019, Section 18.3.5, p380)][3], and the [Split Normal distribution][4].
  The Fernández and Steel's formulation is mathematically equivalent to the main
  parameterization discussed in the last reference.
  
  #### Mathematical details
  
  The probability density function (pdf) is,
  
  ```none
  pdf(x; loc, scale, skewness) =
      k * normal_pdf(y * skewness; 0, 1) when x < loc, and
      k * normal_pdf(y / skewness; 0, 1) when x >= loc
  where
      k = (2 * skewness) / ((1 + skewness**2) * scale)
      y = (x - loc) / scale
  ```
  
  where `loc` is the location, `scale` is the scale, `skewness` is the shape
  parameter, and `normal_pdf(x; 0, 1)` is the pdf of the Normal distribution
  with zero mean and unit variance.
  
  The cumulative distribution function (cdf) is,
  
  ```none
  cdf(x; loc, scale, skewness) =
      k0 * normal_cdf(y * skewness; 0, 1) when x < loc, and
      k1 + k2 * normal_cdf(y / skewness; 0, 1) when x >= loc
  where
      k0 = 2 / (1 + skewness**2)
      k1 = (1 - skewness**2) / (1 + skewness**2)
      k2 = (2 * skewness**2) / (1 + skewness**2)
      y = (x - loc) / scale
  ```
  
  where `normal_cdf(x; 0, 1)` is the cdf of the Normal distribution with zero
  mean and unit variance.
  
  The quantile function (inverse cdf) is,
  
  ```none
  quantile(p; loc, scale, skewness) =
      loc + s0 * normal_quantile(x0) when p <= 1 / (1 + skewness**2), and
      loc + s1 * normal_quantile(x1) when p > 1 / (1 + skewness**2)
  where
      s0 = scale / skewness
      s1 = scale * skewness
      x0 = (p * (1 + skewness**2)) / 2
      x1 = (p * (1 + skewness**2) - 1 + skewness**2) / (2 * skewness**2)
      y = (x - loc) / scale
  ```
  
  where `normal_quantile(x; 0, 1)` is the quantile function of the Normal
  distribution with zero mean and unit variance.
  
  The mean and variance are, respectively,
  
  ```none
  mean(loc, scale, skewness) = loc + scale * E(Y)
  variance(loc, scale, skewness) = scale**2 * (
      skewness**2 + 1 / skewness**2 - 1 - E(Y)**2)
  where
      E(Y) = sqrt(2) / sqrt(pi) * (skewness - 1 / skewness)
  ```
  
  The Two-Piece Normal distribution is a member of the [location-scale family](
  https://en.wikipedia.org/wiki/Location-scale_family): it can be constructed
  as,
  
  ```none
  Z ~ Normal(loc=0, scale=1)
  W ~ Bernoulli(probs=1 / (1 + skewness**2))
  Y = (1 - W) * |Z| * skewness - W * |Z| / skewness
  X = loc + scale * Y
  ```
  
  #### Examples
  
  Example of initialization of one distribution.
  
  ```python
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  # Define a single scalar Two-Piece Normal distribution.
  dist = tfd.TwoPieceNormal(loc=3., scale=10., skewness=0.75)
  
  # Evaluate the cdf at 1, returning a scalar.
  dist.cdf(1.)
  ```
  
  Example of initialization of a batch of distributions. Arguments are
  broadcast when possible.
  
  ```python
  # Define a batch of three scalar valued Two-Piece Normals.
  # They have mean 3, scale 10, but different skewnesses.
  dist = tfd.TwoPieceNormal(loc=3., scale=10., skewness=[0.75, 1., 1.33])
  
  # Get 2 samples, returning a 2 x 3 tensor.
  value = dist.sample(2)
  
  # Evaluate the pdf of the distributions on the same points, value,
  # returning a 2 x 3 tensor.
  dist.prob(value)
  ```
  
  #### References
  
  [1]: Nabor O. Castillo et al. On the Fernández-Steel distribution: Inference
       and application. _Computational Statistics & Data Analysis_, 55(11),
       2951-2961, 2011.
  
  [2]: Carmen Fernández and Mark F. J. Steel. On Bayesian modeling of fat tails
       and skewness. _Journal of the American Statistical Association_, 93(441),
       359-371, 1998.
  
  [3]: Robert A. Rigby et al. _Distributions for modeling location, scale, and
       shape: Using GAMLSS in R_. Chapman and Hall/CRC, 2019.
  
  [4]: https://en.wikipedia.org/wiki/Split_normal_distribution
class_docstr_tok: ["The","Two-Piece","Normal","distribution",".","The","Two-Piece","Normal","generalizes","the","Normal","distribution","with","an","additional","shape","parameter",".","Under","the","general","formulation","proposed","by","[","Fern\u00e1ndez","and","Steel","(","1998",")","]","[","2","]",",","it","is","parameterized","by","location","`","loc","`",",","scale","`","scale","`",",","and","shape","`","skewness","`",".","If","`","skewness","`","is","above","one",",","the","distribution","becomes","right-","skewed","(","or","positively","skewed",")",".","If","`","skewness","`","is","greater","than","zero","and","less","than","one",",","the","distribution","becomes","left-skewed","(","or","negatively","skewed",")",".","The","Normal","distribution","is","retrieved","when","`","skewness","`","is","equal","to","one",".","This","distribution","is","also","called","the","Fern\u00e1ndez-Steel","Skew","Normal","distribution","[","(","Castillo","et","al.",",","2011",")","]","[","1","]",",","the","Skew","Normal","Type","2","distribution","[","(","Rigby","et","al.",",","2019",",","Section","18.3.5",",","p380",")","]","[","3","]",",","and","the","[","Split","Normal","distribution","]","[","4","]",".","The","Fern\u00e1ndez","and","Steel","'s","formulation","is","mathematically","equivalent","to","the","main","parameterization","discussed","in","the","last","reference",".","#","#","#","#","Mathematical","details","The","probability","density","function","(","pdf",")","is",",","``","`","none","pdf","(","x",";","loc",",","scale",",","skewness",")","=","k","*","normal_pdf","(","y","*","skewness",";","0",",","1",")","when","x","<","loc",",","and","k","*","normal_pdf","(","y","\/","skewness",";","0",",","1",")","when","x",">","=","loc","where","k","=","(","2","*","skewness",")","\/","(","(","1","+","skewness","*","*","2",")","*","scale",")","y","=","(","x","-","loc",")","\/","scale","``","`","where","`","loc","`","is","the","location",",","`","scale","`","is","the","scale",",","`","skewness","`","is","the","shape","parameter",",","and","`","normal_pdf","(","x",";","0",",","1",")","`","is","the","pdf","of","the","Normal","distribution","with","zero","mean","and","unit","variance",".","The","cumulative","distribution","function","(","cdf",")","is",",","``","`","none","cdf","(","x",";","loc",",","scale",",","skewness",")","=","k0","*","normal_cdf","(","y","*","skewness",";","0",",","1",")","when","x","<","loc",",","and","k1","+","k2","*","normal_cdf","(","y","\/","skewness",";","0",",","1",")","when","x",">","=","loc","where","k0","=","2","\/","(","1","+","skewness","*","*","2",")","k1","=","(","1","-","skewness","*","*","2",")","\/","(","1","+","skewness","*","*","2",")","k2","=","(","2","*","skewness","*","*","2",")","\/","(","1","+","skewness","*","*","2",")","y","=","(","x","-","loc",")","\/","scale","``","`","where","`","normal_cdf","(","x",";","0",",","1",")","`","is","the","cdf","of","the","Normal","distribution","with","zero","mean","and","unit","variance",".","The","quantile","function","(","inverse","cdf",")","is",",","``","`","none","quantile","(","p",";","loc",",","scale",",","skewness",")","=","loc","+","s0","*","normal_quantile","(","x0",")","when","p","<","=","1","\/","(","1","+","skewness","*","*","2",")",",","and","loc","+","s1","*","normal_quantile","(","x1",")","when","p",">","1","\/","(","1","+","skewness","*","*","2",")","where","s0","=","scale","\/","skewness","s1","=","scale","*","skewness","x0","=","(","p","*","(","1","+","skewness","*","*","2",")",")","\/","2","x1","=","(","p","*","(","1","+","skewness","*","*","2",")","-","1","+","skewness","*","*","2",")","\/","(","2","*","skewness","*","*","2",")","y","=","(","x","-","loc",")","\/","scale","``","`","where","`","normal_quantile","(","x",";","0",",","1",")","`","is","the","quantile","function","of","the","Normal","distribution","with","zero","mean","and","unit","variance",".","The","mean","and","variance","are",",","respectively",",","``","`","none","mean","(","loc",",","scale",",","skewness",")","=","loc","+","scale","*","E","(","Y",")","variance","(","loc",",","scale",",","skewness",")","=","scale","*","*","2","*","(","skewness","*","*","2","+","1","\/","skewness","*","*","2","-","1","-","E","(","Y",")","*","*","2",")","where","E","(","Y",")","=","sqrt","(","2",")","\/","sqrt","(","pi",")","*","(","skewness","-","1","\/","skewness",")","``","`","The","Two-Piece","Normal","distribution","is","a","member","of","the","[","location-scale","family","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Location-scale_family",")",":","it","can","be","constructed","as",",","``","`","none","Z","~","Normal","(","loc=0",",","scale=1",")","W","~","Bernoulli","(","probs=1","\/","(","1","+","skewness","*","*","2",")",")","Y","=","(","1","-","W",")","*","|Z|","*","skewness","-","W","*","|Z|","\/","skewness","X","=","loc","+","scale","*","Y","``","`","#","#","#","#","Examples","Example","of","initialization","of","one","distribution",".","``","`","python","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","#","Define","a","single","scalar","Two-Piece","Normal","distribution",".","dist","=","tfd.TwoPieceNormal","(","loc=3.",",","scale=10.",",","skewness=0.75",")","#","Evaluate","the","cdf","at","1",",","returning","a","scalar",".","dist.cdf","(","1",".",")","``","`","Example","of","initialization","of","a","batch","of","distributions",".","Arguments","are","broadcast","when","possible",".","``","`","python","#","Define","a","batch","of","three","scalar","valued","Two-Piece","Normals",".","#","They","have","mean","3",",","scale","10",",","but","different","skewnesses",".","dist","=","tfd.TwoPieceNormal","(","loc=3.",",","scale=10.",",","skewness=","[","0.75",",","1.",",","1.33","]",")","#","Get","2","samples",",","returning","a","2","x","3","tensor",".","value","=","dist.sample","(","2",")","#","Evaluate","the","pdf","of","the","distributions","on","the","same","points",",","value",",","#","returning","a","2","x","3","tensor",".","dist.prob","(","value",")","``","`","#","#","#","#","References","[","1","]",":","Nabor","O.","Castillo","et","al",".","On","the","Fern\u00e1ndez-Steel","distribution",":","Inference","and","application",".","_Computational","Statistics","&","Data","Analysis_",",","55","(","11",")",",","2951-2961",",","2011",".","[","2","]",":","Carmen","Fern\u00e1ndez","and","Mark","F.","J",".","Steel",".","On","Bayesian","modeling","of","fat","tails","and","skewness",".","_Journal","of","the","American","Statistical","Association_",",","93","(","441",")",",","359-371",",","1998",".","[","3","]",":","Robert","A.","Rigby","et","al",".","_Distributions","for","modeling","location",",","scale",",","and","shape",":","Using","GAMLSS","in","R_",".","Chapman","and","Hall\/CRC",",","2019",".","[","4","]",":","https",":","\/\/en.wikipedia.org\/wiki\/Split_normal_distribution"]
code: def _variance(self):
      scale = tf.convert_to_tensor(self.scale)
      skewness = tf.convert_to_tensor(self.skewness)
  
      one = tf.constant(1.0, dtype=self.dtype)
      two = tf.constant(2.0, dtype=self.dtype)
      pi = tf.constant(np.pi, dtype=self.dtype)
  
      m = tf.math.sqrt(two / pi) * (
          skewness - tf.math.reciprocal(skewness)
      )
      squared_skewness = tf.math.square(skewness)
      v = (
          squared_skewness
          + tf.math.reciprocal(squared_skewness)
          - one
          - tf.math.square(m)
      )
      variance = tf.square(scale) * v
  
      batch_shape = self._batch_shape_tensor(
          scale=scale, skewness=skewness
      )
  
      return tf.broadcast_to(variance, shape=batch_shape)
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import special_math
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.math import special
  from tensorflow_probability.python.math.numeric import log1psquare
label_desc: Use image node_id 14 for calling the TwoPieceNormal obj's underlying member method code with example usage: obj._variance() and returns: tf