partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | _get_indices | Generates starting points for the Halton sequence procedure.
The k'th element of the sequence is generated starting from a positive integer
which must be distinct for each `k`. It is conventional to choose the starting
point as `k` itself (or `k+1` if k is zero based). This function generates
the starting inte... | tensorflow_probability/python/mcmc/sample_halton_sequence.py | def _get_indices(num_results, sequence_indices, dtype, name=None):
"""Generates starting points for the Halton sequence procedure.
The k'th element of the sequence is generated starting from a positive integer
which must be distinct for each `k`. It is conventional to choose the starting
point as `k` itself (o... | def _get_indices(num_results, sequence_indices, dtype, name=None):
"""Generates starting points for the Halton sequence procedure.
The k'th element of the sequence is generated starting from a positive integer
which must be distinct for each `k`. It is conventional to choose the starting
point as `k` itself (o... | [
"Generates",
"starting",
"points",
"for",
"the",
"Halton",
"sequence",
"procedure",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/sample_halton_sequence.py#L304-L342 | [
"def",
"_get_indices",
"(",
"num_results",
",",
"sequence_indices",
",",
"dtype",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"name",
",",
"'_get_indices'",
",",
"[",
"num_results",
",",
"sequence_ind... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _base_expansion_size | Computes the number of terms in the place value expansion.
Let num = a0 + a1 b + a2 b^2 + ... ak b^k be the place value expansion of
`num` in base b (ak <> 0). This function computes and returns `k+1` for each
base `b` specified in `bases`.
This can be inferred from the base `b` logarithm of `num` as follows:... | tensorflow_probability/python/mcmc/sample_halton_sequence.py | def _base_expansion_size(num, bases):
"""Computes the number of terms in the place value expansion.
Let num = a0 + a1 b + a2 b^2 + ... ak b^k be the place value expansion of
`num` in base b (ak <> 0). This function computes and returns `k+1` for each
base `b` specified in `bases`.
This can be inferred from ... | def _base_expansion_size(num, bases):
"""Computes the number of terms in the place value expansion.
Let num = a0 + a1 b + a2 b^2 + ... ak b^k be the place value expansion of
`num` in base b (ak <> 0). This function computes and returns `k+1` for each
base `b` specified in `bases`.
This can be inferred from ... | [
"Computes",
"the",
"number",
"of",
"terms",
"in",
"the",
"place",
"value",
"expansion",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/sample_halton_sequence.py#L345-L365 | [
"def",
"_base_expansion_size",
"(",
"num",
",",
"bases",
")",
":",
"return",
"tf",
".",
"floor",
"(",
"tf",
".",
"math",
".",
"log",
"(",
"num",
")",
"/",
"tf",
".",
"math",
".",
"log",
"(",
"bases",
")",
")",
"+",
"1"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _primes_less_than | Returns sorted array of primes such that `2 <= prime < n`. | tensorflow_probability/python/mcmc/sample_halton_sequence.py | def _primes_less_than(n):
# Based on
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
"""Returns sorted array of primes such that `2 <= prime < n`."""
small_primes = np.array((2, 3, 5))
if n <= 6:
return small_primes[small_primes < n]
sieve =... | def _primes_less_than(n):
# Based on
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
"""Returns sorted array of primes such that `2 <= prime < n`."""
small_primes = np.array((2, 3, 5))
if n <= 6:
return small_primes[small_primes < n]
sieve =... | [
"Returns",
"sorted",
"array",
"of",
"primes",
"such",
"that",
"2",
"<",
"=",
"prime",
"<",
"n",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/sample_halton_sequence.py#L368-L384 | [
"def",
"_primes_less_than",
"(",
"n",
")",
":",
"# Based on",
"# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188",
"small_primes",
"=",
"np",
".",
"array",
"(",
"(",
"2",
",",
"3",
",",
"5",
")",
")",
"if",
"n... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _machine_eps | Returns the machine epsilon for the supplied dtype. | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _machine_eps(dtype):
"""Returns the machine epsilon for the supplied dtype."""
if isinstance(dtype, tf.DType):
dtype = dtype.as_numpy_dtype()
return np.finfo(dtype).eps | def _machine_eps(dtype):
"""Returns the machine epsilon for the supplied dtype."""
if isinstance(dtype, tf.DType):
dtype = dtype.as_numpy_dtype()
return np.finfo(dtype).eps | [
"Returns",
"the",
"machine",
"epsilon",
"for",
"the",
"supplied",
"dtype",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L45-L49 | [
"def",
"_machine_eps",
"(",
"dtype",
")",
":",
"if",
"isinstance",
"(",
"dtype",
",",
"tf",
".",
"DType",
")",
":",
"dtype",
"=",
"dtype",
".",
"as_numpy_dtype",
"(",
")",
"return",
"np",
".",
"finfo",
"(",
"dtype",
")",
".",
"eps"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | hager_zhang | The Hager Zhang line search algorithm.
Performs an inexact line search based on the algorithm of
[Hager and Zhang (2006)][2].
The univariate objective function `value_and_gradients_function` is typically
generated by projecting a multivariate objective function along a search
direction. Suppose the multivari... | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def hager_zhang(value_and_gradients_function,
initial_step_size=None,
value_at_initial_step=None,
value_at_zero=None,
converged=None,
threshold_use_approximate_wolfe_condition=1e-6,
shrinkage_param=0.66,
expa... | def hager_zhang(value_and_gradients_function,
initial_step_size=None,
value_at_initial_step=None,
value_at_zero=None,
converged=None,
threshold_use_approximate_wolfe_condition=1e-6,
shrinkage_param=0.66,
expa... | [
"The",
"Hager",
"Zhang",
"line",
"search",
"algorithm",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L69-L296 | [
"def",
"hager_zhang",
"(",
"value_and_gradients_function",
",",
"initial_step_size",
"=",
"None",
",",
"value_at_initial_step",
"=",
"None",
",",
"value_at_zero",
"=",
"None",
",",
"converged",
"=",
"None",
",",
"threshold_use_approximate_wolfe_condition",
"=",
"1e-6",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _fix_step_size | Shrinks the input step size until the value and grad become finite. | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _fix_step_size(value_and_gradients_function,
val_c_input,
active,
step_size_shrink_param):
"""Shrinks the input step size until the value and grad become finite."""
# The maximum iterations permitted are determined as the number of halvings
# it takes t... | def _fix_step_size(value_and_gradients_function,
val_c_input,
active,
step_size_shrink_param):
"""Shrinks the input step size until the value and grad become finite."""
# The maximum iterations permitted are determined as the number of halvings
# it takes t... | [
"Shrinks",
"the",
"input",
"step",
"size",
"until",
"the",
"value",
"and",
"grad",
"become",
"finite",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L299-L320 | [
"def",
"_fix_step_size",
"(",
"value_and_gradients_function",
",",
"val_c_input",
",",
"active",
",",
"step_size_shrink_param",
")",
":",
"# The maximum iterations permitted are determined as the number of halvings",
"# it takes to reduce 1 to 0 in the given dtype.",
"iter_max",
"=",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _bracket_and_search | Brackets the minimum and performs a line search.
Args:
value_and_gradients_function: A Python callable that accepts a real scalar
tensor and returns a namedtuple with the fields 'x', 'f', and 'df' that
correspond to scalar tensors of real dtype containing the point at which
the function was eva... | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _bracket_and_search(
value_and_gradients_function,
init_interval,
f_lim,
max_iterations,
shrinkage_param,
expansion_param,
sufficient_decrease_param,
curvature_param):
"""Brackets the minimum and performs a line search.
Args:
value_and_gradients_function: A Python callable t... | def _bracket_and_search(
value_and_gradients_function,
init_interval,
f_lim,
max_iterations,
shrinkage_param,
expansion_param,
sufficient_decrease_param,
curvature_param):
"""Brackets the minimum and performs a line search.
Args:
value_and_gradients_function: A Python callable t... | [
"Brackets",
"the",
"minimum",
"and",
"performs",
"a",
"line",
"search",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L332-L417 | [
"def",
"_bracket_and_search",
"(",
"value_and_gradients_function",
",",
"init_interval",
",",
"f_lim",
",",
"max_iterations",
",",
"shrinkage_param",
",",
"expansion_param",
",",
"sufficient_decrease_param",
",",
"curvature_param",
")",
":",
"bracket_result",
"=",
"hzl",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _line_search_after_bracketing | The main loop of line search after the minimum has been bracketed.
Args:
value_and_gradients_function: A Python callable that accepts a real scalar
tensor and returns a namedtuple with the fields 'x', 'f', and 'df' that
correspond to scalar tensors of real dtype containing the point at which
th... | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _line_search_after_bracketing(
value_and_gradients_function,
search_interval,
val_0,
f_lim,
max_iterations,
sufficient_decrease_param,
curvature_param,
shrinkage_param):
"""The main loop of line search after the minimum has been bracketed.
Args:
value_and_gradients_function:... | def _line_search_after_bracketing(
value_and_gradients_function,
search_interval,
val_0,
f_lim,
max_iterations,
sufficient_decrease_param,
curvature_param,
shrinkage_param):
"""The main loop of line search after the minimum has been bracketed.
Args:
value_and_gradients_function:... | [
"The",
"main",
"loop",
"of",
"line",
"search",
"after",
"the",
"minimum",
"has",
"been",
"bracketed",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L420-L542 | [
"def",
"_line_search_after_bracketing",
"(",
"value_and_gradients_function",
",",
"search_interval",
",",
"val_0",
",",
"f_lim",
",",
"max_iterations",
",",
"sufficient_decrease_param",
",",
"curvature_param",
",",
"shrinkage_param",
")",
":",
"def",
"_loop_cond",
"(",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _line_search_inner_bisection | Performs bisection and updates the interval. | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _line_search_inner_bisection(
value_and_gradients_function,
search_interval,
active,
f_lim):
"""Performs bisection and updates the interval."""
midpoint = (search_interval.left.x + search_interval.right.x) / 2
val_mid = value_and_gradients_function(midpoint)
is_valid_mid = hzl.is_finite(val_... | def _line_search_inner_bisection(
value_and_gradients_function,
search_interval,
active,
f_lim):
"""Performs bisection and updates the interval."""
midpoint = (search_interval.left.x + search_interval.right.x) / 2
val_mid = value_and_gradients_function(midpoint)
is_valid_mid = hzl.is_finite(val_... | [
"Performs",
"bisection",
"and",
"updates",
"the",
"interval",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L545-L576 | [
"def",
"_line_search_inner_bisection",
"(",
"value_and_gradients_function",
",",
"search_interval",
",",
"active",
",",
"f_lim",
")",
":",
"midpoint",
"=",
"(",
"search_interval",
".",
"left",
".",
"x",
"+",
"search_interval",
".",
"right",
".",
"x",
")",
"/",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _prepare_args | Prepares the arguments for the line search initialization.
Args:
value_and_gradients_function: A Python callable that accepts a real scalar
tensor and returns a namedtuple with the fields 'x', 'f', and 'df' that
correspond to scalar tensors of real dtype containing the point at which
the functi... | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _prepare_args(value_and_gradients_function,
initial_step_size,
val_initial,
val_0,
approximate_wolfe_threshold):
"""Prepares the arguments for the line search initialization.
Args:
value_and_gradients_function: A Python callable that a... | def _prepare_args(value_and_gradients_function,
initial_step_size,
val_initial,
val_0,
approximate_wolfe_threshold):
"""Prepares the arguments for the line search initialization.
Args:
value_and_gradients_function: A Python callable that a... | [
"Prepares",
"the",
"arguments",
"for",
"the",
"line",
"search",
"initialization",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L579-L650 | [
"def",
"_prepare_args",
"(",
"value_and_gradients_function",
",",
"initial_step_size",
",",
"val_initial",
",",
"val_0",
",",
"approximate_wolfe_threshold",
")",
":",
"eval_count",
"=",
"0",
"if",
"val_initial",
"is",
"None",
":",
"if",
"initial_step_size",
"is",
"n... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _to_str | Converts a bool tensor to a string with True/False values. | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _to_str(x):
"""Converts a bool tensor to a string with True/False values."""
x = tf.convert_to_tensor(value=x)
if x.dtype == tf.bool:
return tf.where(x, tf.fill(x.shape, 'True'), tf.fill(x.shape, 'False'))
return x | def _to_str(x):
"""Converts a bool tensor to a string with True/False values."""
x = tf.convert_to_tensor(value=x)
if x.dtype == tf.bool:
return tf.where(x, tf.fill(x.shape, 'True'), tf.fill(x.shape, 'False'))
return x | [
"Converts",
"a",
"bool",
"tensor",
"to",
"a",
"string",
"with",
"True",
"/",
"False",
"values",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L657-L662 | [
"def",
"_to_str",
"(",
"x",
")",
":",
"x",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"value",
"=",
"x",
")",
"if",
"x",
".",
"dtype",
"==",
"tf",
".",
"bool",
":",
"return",
"tf",
".",
"where",
"(",
"x",
",",
"tf",
".",
"fill",
"(",
"x",
".",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _print | Wrapper for tf.Print which supports lists and namedtuples for printing. | tensorflow_probability/python/optimizer/linesearch/hager_zhang.py | def _print(pass_through_tensor, values):
"""Wrapper for tf.Print which supports lists and namedtuples for printing."""
flat_values = []
for value in values:
# Checks if it is a namedtuple.
if hasattr(value, '_fields'):
for field in value._fields:
flat_values.extend([field, _to_str(getattr(va... | def _print(pass_through_tensor, values):
"""Wrapper for tf.Print which supports lists and namedtuples for printing."""
flat_values = []
for value in values:
# Checks if it is a namedtuple.
if hasattr(value, '_fields'):
for field in value._fields:
flat_values.extend([field, _to_str(getattr(va... | [
"Wrapper",
"for",
"tf",
".",
"Print",
"which",
"supports",
"lists",
"and",
"namedtuples",
"for",
"printing",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/linesearch/hager_zhang.py#L666-L680 | [
"def",
"_print",
"(",
"pass_through_tensor",
",",
"values",
")",
":",
"flat_values",
"=",
"[",
"]",
"for",
"value",
"in",
"values",
":",
"# Checks if it is a namedtuple.",
"if",
"hasattr",
"(",
"value",
",",
"'_fields'",
")",
":",
"for",
"field",
"in",
"valu... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _kl_brute_force | Batched KL divergence `KL(a || b)` for multivariate Normals.
With `X`, `Y` both multivariate Normals in `R^k` with means `mu_a`, `mu_b` and
covariance `C_a`, `C_b` respectively,
```
KL(a || b) = 0.5 * ( L - k + T + Q ),
L := Log[Det(C_b)] - Log[Det(C_a)]
T := trace(C_b^{-1} C_a),
Q := (mu_b - mu_a)^T C_... | tensorflow_probability/python/distributions/mvn_linear_operator.py | def _kl_brute_force(a, b, name=None):
"""Batched KL divergence `KL(a || b)` for multivariate Normals.
With `X`, `Y` both multivariate Normals in `R^k` with means `mu_a`, `mu_b` and
covariance `C_a`, `C_b` respectively,
```
KL(a || b) = 0.5 * ( L - k + T + Q ),
L := Log[Det(C_b)] - Log[Det(C_a)]
T := tra... | def _kl_brute_force(a, b, name=None):
"""Batched KL divergence `KL(a || b)` for multivariate Normals.
With `X`, `Y` both multivariate Normals in `R^k` with means `mu_a`, `mu_b` and
covariance `C_a`, `C_b` respectively,
```
KL(a || b) = 0.5 * ( L - k + T + Q ),
L := Log[Det(C_b)] - Log[Det(C_a)]
T := tra... | [
"Batched",
"KL",
"divergence",
"KL",
"(",
"a",
"||",
"b",
")",
"for",
"multivariate",
"Normals",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/mvn_linear_operator.py#L269-L340 | [
"def",
"_kl_brute_force",
"(",
"a",
",",
"b",
",",
"name",
"=",
"None",
")",
":",
"def",
"squared_frobenius_norm",
"(",
"x",
")",
":",
"\"\"\"Helper to make KL calculation slightly more readable.\"\"\"",
"# http://mathworld.wolfram.com/FrobeniusNorm.html",
"# The gradient of ... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | quadrature_scheme_softmaxnormal_gauss_hermite | Use Gauss-Hermite quadrature to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(normal_loc, normal_scale)
```
Note: for a given `quadrature_size`, this method is generally less accurate
than `quadrature_scheme_softmax... | tensorflow_probability/python/distributions/vector_diffeomixture.py | def quadrature_scheme_softmaxnormal_gauss_hermite(
normal_loc, normal_scale, quadrature_size,
validate_args=False, name=None):
"""Use Gauss-Hermite quadrature to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(norm... | def quadrature_scheme_softmaxnormal_gauss_hermite(
normal_loc, normal_scale, quadrature_size,
validate_args=False, name=None):
"""Use Gauss-Hermite quadrature to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(norm... | [
"Use",
"Gauss",
"-",
"Hermite",
"quadrature",
"to",
"form",
"quadrature",
"on",
"K",
"-",
"1",
"simplex",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L46-L105 | [
"def",
"quadrature_scheme_softmaxnormal_gauss_hermite",
"(",
"normal_loc",
",",
"normal_scale",
",",
"quadrature_size",
",",
"validate_args",
"=",
"False",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"quadrature_scheme_s... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | quadrature_scheme_softmaxnormal_quantiles | Use SoftmaxNormal quantiles to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(normal_loc, normal_scale)
```
Args:
normal_loc: `float`-like `Tensor` with shape `[b1, ..., bB, K-1]`, B>=0.
The location paramete... | tensorflow_probability/python/distributions/vector_diffeomixture.py | def quadrature_scheme_softmaxnormal_quantiles(
normal_loc, normal_scale, quadrature_size,
validate_args=False, name=None):
"""Use SoftmaxNormal quantiles to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(normal_lo... | def quadrature_scheme_softmaxnormal_quantiles(
normal_loc, normal_scale, quadrature_size,
validate_args=False, name=None):
"""Use SoftmaxNormal quantiles to form quadrature on `K - 1` simplex.
A `SoftmaxNormal` random variable `Y` may be generated via
```
Y = SoftmaxCentered(X),
X = Normal(normal_lo... | [
"Use",
"SoftmaxNormal",
"quantiles",
"to",
"form",
"quadrature",
"on",
"K",
"-",
"1",
"simplex",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L108-L199 | [
"def",
"quadrature_scheme_softmaxnormal_quantiles",
"(",
"normal_loc",
",",
"normal_scale",
",",
"quadrature_size",
",",
"validate_args",
"=",
"False",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"softmax_normal_grid_and... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | maybe_check_quadrature_param | Helper which checks validity of `loc` and `scale` init args. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def maybe_check_quadrature_param(param, name, validate_args):
"""Helper which checks validity of `loc` and `scale` init args."""
with tf.name_scope("check_" + name):
assertions = []
if tensorshape_util.rank(param.shape) is not None:
if tensorshape_util.rank(param.shape) == 0:
raise ValueError(... | def maybe_check_quadrature_param(param, name, validate_args):
"""Helper which checks validity of `loc` and `scale` init args."""
with tf.name_scope("check_" + name):
assertions = []
if tensorshape_util.rank(param.shape) is not None:
if tensorshape_util.rank(param.shape) == 0:
raise ValueError(... | [
"Helper",
"which",
"checks",
"validity",
"of",
"loc",
"and",
"scale",
"init",
"args",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L776-L811 | [
"def",
"maybe_check_quadrature_param",
"(",
"param",
",",
"name",
",",
"validate_args",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"\"check_\"",
"+",
"name",
")",
":",
"assertions",
"=",
"[",
"]",
"if",
"tensorshape_util",
".",
"rank",
"(",
"param",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | determine_batch_event_shapes | Helper to infer batch_shape and event_shape. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def determine_batch_event_shapes(grid, endpoint_affine):
"""Helper to infer batch_shape and event_shape."""
with tf.name_scope("determine_batch_event_shapes"):
# grid # shape: [B, k, q]
# endpoint_affine # len=k, shape: [B, d, d]
batch_shape = grid.shape[:-2]
batch_shape_tensor = tf.shape(input... | def determine_batch_event_shapes(grid, endpoint_affine):
"""Helper to infer batch_shape and event_shape."""
with tf.name_scope("determine_batch_event_shapes"):
# grid # shape: [B, k, q]
# endpoint_affine # len=k, shape: [B, d, d]
batch_shape = grid.shape[:-2]
batch_shape_tensor = tf.shape(input... | [
"Helper",
"to",
"infer",
"batch_shape",
"and",
"event_shape",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L814-L850 | [
"def",
"determine_batch_event_shapes",
"(",
"grid",
",",
"endpoint_affine",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"\"determine_batch_event_shapes\"",
")",
":",
"# grid # shape: [B, k, q]",
"# endpoint_affine # len=k, shape: [B, d, d]",
"batch_shape",
"=",
"grid... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | interpolate_loc | Helper which interpolates between two locs. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def interpolate_loc(grid, loc):
"""Helper which interpolates between two locs."""
if len(loc) != 2:
raise NotImplementedError("Currently only bimixtures are supported; "
"len(scale)={} is not 2.".format(len(loc)))
deg = tf.compat.dimension_value(
tensorshape_util.with_rank_... | def interpolate_loc(grid, loc):
"""Helper which interpolates between two locs."""
if len(loc) != 2:
raise NotImplementedError("Currently only bimixtures are supported; "
"len(scale)={} is not 2.".format(len(loc)))
deg = tf.compat.dimension_value(
tensorshape_util.with_rank_... | [
"Helper",
"which",
"interpolates",
"between",
"two",
"locs",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L853-L879 | [
"def",
"interpolate_loc",
"(",
"grid",
",",
"loc",
")",
":",
"if",
"len",
"(",
"loc",
")",
"!=",
"2",
":",
"raise",
"NotImplementedError",
"(",
"\"Currently only bimixtures are supported; \"",
"\"len(scale)={} is not 2.\"",
".",
"format",
"(",
"len",
"(",
"loc",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | interpolate_scale | Helper which interpolates between two scales. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def interpolate_scale(grid, scale):
"""Helper which interpolates between two scales."""
if len(scale) != 2:
raise NotImplementedError("Currently only bimixtures are supported; "
"len(scale)={} is not 2.".format(len(scale)))
deg = tf.compat.dimension_value(
tensorshape_util.... | def interpolate_scale(grid, scale):
"""Helper which interpolates between two scales."""
if len(scale) != 2:
raise NotImplementedError("Currently only bimixtures are supported; "
"len(scale)={} is not 2.".format(len(scale)))
deg = tf.compat.dimension_value(
tensorshape_util.... | [
"Helper",
"which",
"interpolates",
"between",
"two",
"scales",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L882-L896 | [
"def",
"interpolate_scale",
"(",
"grid",
",",
"scale",
")",
":",
"if",
"len",
"(",
"scale",
")",
"!=",
"2",
":",
"raise",
"NotImplementedError",
"(",
"\"Currently only bimixtures are supported; \"",
"\"len(scale)={} is not 2.\"",
".",
"format",
"(",
"len",
"(",
"s... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | linop_scale | Creates weighted `LinOp` from existing `LinOp`. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def linop_scale(w, op):
"""Creates weighted `LinOp` from existing `LinOp`."""
# We assume w > 0. (This assumption only relates to the is_* attributes.)
with tf.name_scope("linop_scale"):
# TODO(b/35301104): LinearOperatorComposition doesn't combine operators, so
# special case combinations here. Once it d... | def linop_scale(w, op):
"""Creates weighted `LinOp` from existing `LinOp`."""
# We assume w > 0. (This assumption only relates to the is_* attributes.)
with tf.name_scope("linop_scale"):
# TODO(b/35301104): LinearOperatorComposition doesn't combine operators, so
# special case combinations here. Once it d... | [
"Creates",
"weighted",
"LinOp",
"from",
"existing",
"LinOp",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L899-L933 | [
"def",
"linop_scale",
"(",
"w",
",",
"op",
")",
":",
"# We assume w > 0. (This assumption only relates to the is_* attributes.)",
"with",
"tf",
".",
"name_scope",
"(",
"\"linop_scale\"",
")",
":",
"# TODO(b/35301104): LinearOperatorComposition doesn't combine operators, so",
"# s... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | concat_vectors | Concatenates input vectors, statically if possible. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def concat_vectors(*args):
"""Concatenates input vectors, statically if possible."""
args_ = [tf.get_static_value(x) for x in args]
if any(vec is None for vec in args_):
return tf.concat(args, axis=0)
return [val for vec in args_ for val in vec] | def concat_vectors(*args):
"""Concatenates input vectors, statically if possible."""
args_ = [tf.get_static_value(x) for x in args]
if any(vec is None for vec in args_):
return tf.concat(args, axis=0)
return [val for vec in args_ for val in vec] | [
"Concatenates",
"input",
"vectors",
"statically",
"if",
"possible",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L936-L941 | [
"def",
"concat_vectors",
"(",
"*",
"args",
")",
":",
"args_",
"=",
"[",
"tf",
".",
"get_static_value",
"(",
"x",
")",
"for",
"x",
"in",
"args",
"]",
"if",
"any",
"(",
"vec",
"is",
"None",
"for",
"vec",
"in",
"args_",
")",
":",
"return",
"tf",
"."... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | softmax | Equivalent to tf.nn.softmax but works around b/70297725. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def softmax(x, axis, name=None):
"""Equivalent to tf.nn.softmax but works around b/70297725."""
with tf.name_scope(name or "softmax"):
x = tf.convert_to_tensor(value=x, name="x")
ndims = (
tensorshape_util.rank(x.shape)
if tensorshape_util.rank(x.shape) is not None else tf.rank(
... | def softmax(x, axis, name=None):
"""Equivalent to tf.nn.softmax but works around b/70297725."""
with tf.name_scope(name or "softmax"):
x = tf.convert_to_tensor(value=x, name="x")
ndims = (
tensorshape_util.rank(x.shape)
if tensorshape_util.rank(x.shape) is not None else tf.rank(
... | [
"Equivalent",
"to",
"tf",
".",
"nn",
".",
"softmax",
"but",
"works",
"around",
"b",
"/",
"70297725",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L958-L972 | [
"def",
"softmax",
"(",
"x",
",",
"axis",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"softmax\"",
")",
":",
"x",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"value",
"=",
"x",
",",
"name",
"=",
"\"x\"",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | VectorDiffeomixture._expand_base_distribution_mean | Ensures `self.distribution.mean()` has `[batch, event]` shape. | tensorflow_probability/python/distributions/vector_diffeomixture.py | def _expand_base_distribution_mean(self):
"""Ensures `self.distribution.mean()` has `[batch, event]` shape."""
single_draw_shape = concat_vectors(self.batch_shape_tensor(),
self.event_shape_tensor())
m = tf.reshape(
self.distribution.mean(), # A scalar.
... | def _expand_base_distribution_mean(self):
"""Ensures `self.distribution.mean()` has `[batch, event]` shape."""
single_draw_shape = concat_vectors(self.batch_shape_tensor(),
self.event_shape_tensor())
m = tf.reshape(
self.distribution.mean(), # A scalar.
... | [
"Ensures",
"self",
".",
"distribution",
".",
"mean",
"()",
"has",
"[",
"batch",
"event",
"]",
"shape",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/vector_diffeomixture.py#L745-L755 | [
"def",
"_expand_base_distribution_mean",
"(",
"self",
")",
":",
"single_draw_shape",
"=",
"concat_vectors",
"(",
"self",
".",
"batch_shape_tensor",
"(",
")",
",",
"self",
".",
"event_shape_tensor",
"(",
")",
")",
"m",
"=",
"tf",
".",
"reshape",
"(",
"self",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _log_vector_matrix | Multiply tensor of vectors by matrices assuming values stored are logs. | tensorflow_probability/python/distributions/hidden_markov_model.py | def _log_vector_matrix(vs, ms):
"""Multiply tensor of vectors by matrices assuming values stored are logs."""
return tf.reduce_logsumexp(input_tensor=vs[..., tf.newaxis] + ms, axis=-2) | def _log_vector_matrix(vs, ms):
"""Multiply tensor of vectors by matrices assuming values stored are logs."""
return tf.reduce_logsumexp(input_tensor=vs[..., tf.newaxis] + ms, axis=-2) | [
"Multiply",
"tensor",
"of",
"vectors",
"by",
"matrices",
"assuming",
"values",
"stored",
"are",
"logs",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L908-L911 | [
"def",
"_log_vector_matrix",
"(",
"vs",
",",
"ms",
")",
":",
"return",
"tf",
".",
"reduce_logsumexp",
"(",
"input_tensor",
"=",
"vs",
"[",
"...",
",",
"tf",
".",
"newaxis",
"]",
"+",
"ms",
",",
"axis",
"=",
"-",
"2",
")"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _log_matrix_vector | Multiply tensor of matrices by vectors assuming values stored are logs. | tensorflow_probability/python/distributions/hidden_markov_model.py | def _log_matrix_vector(ms, vs):
"""Multiply tensor of matrices by vectors assuming values stored are logs."""
return tf.reduce_logsumexp(input_tensor=ms + vs[..., tf.newaxis, :], axis=-1) | def _log_matrix_vector(ms, vs):
"""Multiply tensor of matrices by vectors assuming values stored are logs."""
return tf.reduce_logsumexp(input_tensor=ms + vs[..., tf.newaxis, :], axis=-1) | [
"Multiply",
"tensor",
"of",
"matrices",
"by",
"vectors",
"assuming",
"values",
"stored",
"are",
"logs",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L914-L917 | [
"def",
"_log_matrix_vector",
"(",
"ms",
",",
"vs",
")",
":",
"return",
"tf",
".",
"reduce_logsumexp",
"(",
"input_tensor",
"=",
"ms",
"+",
"vs",
"[",
"...",
",",
"tf",
".",
"newaxis",
",",
":",
"]",
",",
"axis",
"=",
"-",
"1",
")"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _vector_matrix | Multiply tensor of vectors by matrices. | tensorflow_probability/python/distributions/hidden_markov_model.py | def _vector_matrix(vs, ms):
"""Multiply tensor of vectors by matrices."""
return tf.reduce_sum(input_tensor=vs[..., tf.newaxis] * ms, axis=-2) | def _vector_matrix(vs, ms):
"""Multiply tensor of vectors by matrices."""
return tf.reduce_sum(input_tensor=vs[..., tf.newaxis] * ms, axis=-2) | [
"Multiply",
"tensor",
"of",
"vectors",
"by",
"matrices",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L920-L923 | [
"def",
"_vector_matrix",
"(",
"vs",
",",
"ms",
")",
":",
"return",
"tf",
".",
"reduce_sum",
"(",
"input_tensor",
"=",
"vs",
"[",
"...",
",",
"tf",
".",
"newaxis",
"]",
"*",
"ms",
",",
"axis",
"=",
"-",
"2",
")"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _extract_log_probs | Tabulate log probabilities from a batch of distributions. | tensorflow_probability/python/distributions/hidden_markov_model.py | def _extract_log_probs(num_states, dist):
"""Tabulate log probabilities from a batch of distributions."""
states = tf.reshape(tf.range(num_states),
tf.concat([[num_states],
tf.ones_like(dist.batch_shape_tensor())],
axis=0))
re... | def _extract_log_probs(num_states, dist):
"""Tabulate log probabilities from a batch of distributions."""
states = tf.reshape(tf.range(num_states),
tf.concat([[num_states],
tf.ones_like(dist.batch_shape_tensor())],
axis=0))
re... | [
"Tabulate",
"log",
"probabilities",
"from",
"a",
"batch",
"of",
"distributions",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L926-L933 | [
"def",
"_extract_log_probs",
"(",
"num_states",
",",
"dist",
")",
":",
"states",
"=",
"tf",
".",
"reshape",
"(",
"tf",
".",
"range",
"(",
"num_states",
")",
",",
"tf",
".",
"concat",
"(",
"[",
"[",
"num_states",
"]",
",",
"tf",
".",
"ones_like",
"(",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | HiddenMarkovModel._marginal_hidden_probs | Compute marginal pdf for each individual observable. | tensorflow_probability/python/distributions/hidden_markov_model.py | def _marginal_hidden_probs(self):
"""Compute marginal pdf for each individual observable."""
initial_log_probs = tf.broadcast_to(self._log_init,
tf.concat([self.batch_shape_tensor(),
[self._num_states]],
... | def _marginal_hidden_probs(self):
"""Compute marginal pdf for each individual observable."""
initial_log_probs = tf.broadcast_to(self._log_init,
tf.concat([self.batch_shape_tensor(),
[self._num_states]],
... | [
"Compute",
"marginal",
"pdf",
"for",
"each",
"individual",
"observable",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L489-L517 | [
"def",
"_marginal_hidden_probs",
"(",
"self",
")",
":",
"initial_log_probs",
"=",
"tf",
".",
"broadcast_to",
"(",
"self",
".",
"_log_init",
",",
"tf",
".",
"concat",
"(",
"[",
"self",
".",
"batch_shape_tensor",
"(",
")",
",",
"[",
"self",
".",
"_num_states... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | HiddenMarkovModel.posterior_marginals | Compute marginal posterior distribution for each state.
This function computes, for each time step, the marginal
conditional probability that the hidden Markov model was in
each possible state given the observations that were made
at each time step.
So if the hidden states are `z[0],...,z[num_steps... | tensorflow_probability/python/distributions/hidden_markov_model.py | def posterior_marginals(self, observations, name=None):
"""Compute marginal posterior distribution for each state.
This function computes, for each time step, the marginal
conditional probability that the hidden Markov model was in
each possible state given the observations that were made
at each t... | def posterior_marginals(self, observations, name=None):
"""Compute marginal posterior distribution for each state.
This function computes, for each time step, the marginal
conditional probability that the hidden Markov model was in
each possible state given the observations that were made
at each t... | [
"Compute",
"marginal",
"posterior",
"distribution",
"for",
"each",
"state",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L623-L734 | [
"def",
"posterior_marginals",
"(",
"self",
",",
"observations",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"posterior_marginals\"",
")",
":",
"with",
"tf",
".",
"control_dependencies",
"(",
"self",
".",
"_runtim... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | HiddenMarkovModel.posterior_mode | Compute maximum likelihood sequence of hidden states.
When this function is provided with a sequence of observations
`x[0], ..., x[num_steps - 1]`, it returns the sequence of hidden
states `z[0], ..., z[num_steps - 1]`, drawn from the underlying
Markov chain, that is most likely to yield those observat... | tensorflow_probability/python/distributions/hidden_markov_model.py | def posterior_mode(self, observations, name=None):
"""Compute maximum likelihood sequence of hidden states.
When this function is provided with a sequence of observations
`x[0], ..., x[num_steps - 1]`, it returns the sequence of hidden
states `z[0], ..., z[num_steps - 1]`, drawn from the underlying
... | def posterior_mode(self, observations, name=None):
"""Compute maximum likelihood sequence of hidden states.
When this function is provided with a sequence of observations
`x[0], ..., x[num_steps - 1]`, it returns the sequence of hidden
states `z[0], ..., z[num_steps - 1]`, drawn from the underlying
... | [
"Compute",
"maximum",
"likelihood",
"sequence",
"of",
"hidden",
"states",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/hidden_markov_model.py#L736-L905 | [
"def",
"posterior_mode",
"(",
"self",
",",
"observations",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"posterior_mode\"",
")",
":",
"with",
"tf",
".",
"control_dependencies",
"(",
"self",
".",
"_runtime_assertio... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _choose_random_direction | Chooses a random direction in the event space. | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def _choose_random_direction(current_state_parts, batch_rank, seed=None):
"""Chooses a random direction in the event space."""
seed_gen = distributions.SeedStream(seed, salt='_choose_random_direction')
# Chooses the random directions across each of the input components.
rnd_direction_parts = [
tf.random.n... | def _choose_random_direction(current_state_parts, batch_rank, seed=None):
"""Chooses a random direction in the event space."""
seed_gen = distributions.SeedStream(seed, salt='_choose_random_direction')
# Chooses the random directions across each of the input components.
rnd_direction_parts = [
tf.random.n... | [
"Chooses",
"a",
"random",
"direction",
"in",
"the",
"event",
"space",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L356-L378 | [
"def",
"_choose_random_direction",
"(",
"current_state_parts",
",",
"batch_rank",
",",
"seed",
"=",
"None",
")",
":",
"seed_gen",
"=",
"distributions",
".",
"SeedStream",
"(",
"seed",
",",
"salt",
"=",
"'_choose_random_direction'",
")",
"# Chooses the random direction... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _sample_next | Applies a single iteration of slice sampling update.
Applies hit and run style slice sampling. Chooses a uniform random direction
on the unit sphere in the event space. Applies the one dimensional slice
sampling update along that direction.
Args:
target_log_prob_fn: Python callable which takes an argument... | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def _sample_next(target_log_prob_fn,
current_state_parts,
step_sizes,
max_doublings,
current_target_log_prob,
batch_rank,
seed=None,
name=None):
"""Applies a single iteration of slice sampling update... | def _sample_next(target_log_prob_fn,
current_state_parts,
step_sizes,
max_doublings,
current_target_log_prob,
batch_rank,
seed=None,
name=None):
"""Applies a single iteration of slice sampling update... | [
"Applies",
"a",
"single",
"iteration",
"of",
"slice",
"sampling",
"update",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L381-L537 | [
"def",
"_sample_next",
"(",
"target_log_prob_fn",
",",
"current_state_parts",
",",
"step_sizes",
",",
"max_doublings",
",",
"current_target_log_prob",
",",
"batch_rank",
",",
"seed",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"compat",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _maybe_call_fn | Helper which computes `fn_result` if needed. | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def _maybe_call_fn(fn,
fn_arg_list,
fn_result=None,
description='target_log_prob'):
"""Helper which computes `fn_result` if needed."""
fn_arg_list = (list(fn_arg_list) if mcmc_util.is_list_like(fn_arg_list)
else [fn_arg_list])
if fn_result ... | def _maybe_call_fn(fn,
fn_arg_list,
fn_result=None,
description='target_log_prob'):
"""Helper which computes `fn_result` if needed."""
fn_arg_list = (list(fn_arg_list) if mcmc_util.is_list_like(fn_arg_list)
else [fn_arg_list])
if fn_result ... | [
"Helper",
"which",
"computes",
"fn_result",
"if",
"needed",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L540-L552 | [
"def",
"_maybe_call_fn",
"(",
"fn",
",",
"fn_arg_list",
",",
"fn_result",
"=",
"None",
",",
"description",
"=",
"'target_log_prob'",
")",
":",
"fn_arg_list",
"=",
"(",
"list",
"(",
"fn_arg_list",
")",
"if",
"mcmc_util",
".",
"is_list_like",
"(",
"fn_arg_list",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _right_pad | Pads the shape of x to the right to be of rank final_rank.
Expands the dims of `x` to the right such that its rank is equal to
final_rank. For example, if `x` is of shape [1, 5, 7, 2] and `final_rank` is
7, we return padded_x, which is of shape [1, 5, 7, 2, 1, 1, 1].
Args:
x: The tensor whose shape is to ... | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def _right_pad(x, final_rank):
"""Pads the shape of x to the right to be of rank final_rank.
Expands the dims of `x` to the right such that its rank is equal to
final_rank. For example, if `x` is of shape [1, 5, 7, 2] and `final_rank` is
7, we return padded_x, which is of shape [1, 5, 7, 2, 1, 1, 1].
Args:
... | def _right_pad(x, final_rank):
"""Pads the shape of x to the right to be of rank final_rank.
Expands the dims of `x` to the right such that its rank is equal to
final_rank. For example, if `x` is of shape [1, 5, 7, 2] and `final_rank` is
7, we return padded_x, which is of shape [1, 5, 7, 2, 1, 1, 1].
Args:
... | [
"Pads",
"the",
"shape",
"of",
"x",
"to",
"the",
"right",
"to",
"be",
"of",
"rank",
"final_rank",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L555-L580 | [
"def",
"_right_pad",
"(",
"x",
",",
"final_rank",
")",
":",
"padded_shape",
"=",
"tf",
".",
"concat",
"(",
"[",
"tf",
".",
"shape",
"(",
"input",
"=",
"x",
")",
",",
"tf",
".",
"ones",
"(",
"final_rank",
"-",
"tf",
".",
"rank",
"(",
"x",
")",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _prepare_args | Processes input args to meet list-like assumptions. | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def _prepare_args(target_log_prob_fn, state, step_size,
target_log_prob=None, maybe_expand=False,
description='target_log_prob'):
"""Processes input args to meet list-like assumptions."""
state_parts = list(state) if mcmc_util.is_list_like(state) else [state]
state_parts = [
... | def _prepare_args(target_log_prob_fn, state, step_size,
target_log_prob=None, maybe_expand=False,
description='target_log_prob'):
"""Processes input args to meet list-like assumptions."""
state_parts = list(state) if mcmc_util.is_list_like(state) else [state]
state_parts = [
... | [
"Processes",
"input",
"args",
"to",
"meet",
"list",
"-",
"like",
"assumptions",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L583-L615 | [
"def",
"_prepare_args",
"(",
"target_log_prob_fn",
",",
"state",
",",
"step_size",
",",
"target_log_prob",
"=",
"None",
",",
"maybe_expand",
"=",
"False",
",",
"description",
"=",
"'target_log_prob'",
")",
":",
"state_parts",
"=",
"list",
"(",
"state",
")",
"i... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | SliceSampler.one_step | Runs one iteration of Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
`r = tf.rank(target_log_prob_fn(*current_state))`.
previous_kernel_result... | tensorflow_probability/python/mcmc/slice_sampler_kernel.py | def one_step(self, current_state, previous_kernel_results):
"""Runs one iteration of Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
`r = tf.rank... | def one_step(self, current_state, previous_kernel_results):
"""Runs one iteration of Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
`r = tf.rank... | [
"Runs",
"one",
"iteration",
"of",
"Slice",
"Sampler",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/mcmc/slice_sampler_kernel.py#L259-L336 | [
"def",
"one_step",
"(",
"self",
",",
"current_state",
",",
"previous_kernel_results",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"name",
"=",
"mcmc_util",
".",
"make_name",
"(",
"self",
".",
"name",
",",
"'slice'",
",",
"'o... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | sample_uniform_initial_state | Initialize from a uniform [-2, 2] distribution in unconstrained space.
Args:
parameter: `sts.Parameter` named tuple instance.
return_constrained: if `True`, re-applies the constraining bijector
to return initializations in the original domain. Otherwise, returns
initializations in the unconstrain... | tensorflow_probability/python/sts/fitting.py | def sample_uniform_initial_state(parameter,
return_constrained=True,
init_sample_shape=(),
seed=None):
"""Initialize from a uniform [-2, 2] distribution in unconstrained space.
Args:
parameter: `sts.Parameter` na... | def sample_uniform_initial_state(parameter,
return_constrained=True,
init_sample_shape=(),
seed=None):
"""Initialize from a uniform [-2, 2] distribution in unconstrained space.
Args:
parameter: `sts.Parameter` na... | [
"Initialize",
"from",
"a",
"uniform",
"[",
"-",
"2",
"2",
"]",
"distribution",
"in",
"unconstrained",
"space",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/fitting.py#L30-L62 | [
"def",
"sample_uniform_initial_state",
"(",
"parameter",
",",
"return_constrained",
"=",
"True",
",",
"init_sample_shape",
"=",
"(",
")",
",",
"seed",
"=",
"None",
")",
":",
"unconstrained_prior_sample",
"=",
"parameter",
".",
"bijector",
".",
"inverse",
"(",
"p... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _build_trainable_posterior | Built a transformed-normal variational dist over a parameter's support. | tensorflow_probability/python/sts/fitting.py | def _build_trainable_posterior(param, initial_loc_fn):
"""Built a transformed-normal variational dist over a parameter's support."""
loc = tf.compat.v1.get_variable(
param.name + '_loc',
initializer=lambda: initial_loc_fn(param),
dtype=param.prior.dtype,
use_resource=True)
scale = tf.nn.so... | def _build_trainable_posterior(param, initial_loc_fn):
"""Built a transformed-normal variational dist over a parameter's support."""
loc = tf.compat.v1.get_variable(
param.name + '_loc',
initializer=lambda: initial_loc_fn(param),
dtype=param.prior.dtype,
use_resource=True)
scale = tf.nn.so... | [
"Built",
"a",
"transformed",
"-",
"normal",
"variational",
"dist",
"over",
"a",
"parameter",
"s",
"support",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/fitting.py#L65-L89 | [
"def",
"_build_trainable_posterior",
"(",
"param",
",",
"initial_loc_fn",
")",
":",
"loc",
"=",
"tf",
".",
"compat",
".",
"v1",
".",
"get_variable",
"(",
"param",
".",
"name",
"+",
"'_loc'",
",",
"initializer",
"=",
"lambda",
":",
"initial_loc_fn",
"(",
"p... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | build_factored_variational_loss | Build a loss function for variational inference in STS models.
Variational inference searches for the distribution within some family of
approximate posteriors that minimizes a divergence between the approximate
posterior `q(z)` and true posterior `p(z|observed_time_series)`. By converting
inference to optimiz... | tensorflow_probability/python/sts/fitting.py | def build_factored_variational_loss(model,
observed_time_series,
init_batch_shape=(),
seed=None,
name=None):
"""Build a loss function for variational inference in STS models.... | def build_factored_variational_loss(model,
observed_time_series,
init_batch_shape=(),
seed=None,
name=None):
"""Build a loss function for variational inference in STS models.... | [
"Build",
"a",
"loss",
"function",
"for",
"variational",
"inference",
"in",
"STS",
"models",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/fitting.py#L92-L264 | [
"def",
"build_factored_variational_loss",
"(",
"model",
",",
"observed_time_series",
",",
"init_batch_shape",
"=",
"(",
")",
",",
"seed",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"name... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _minimize_in_graph | Run an optimizer within the graph to minimize a loss function. | tensorflow_probability/python/sts/fitting.py | def _minimize_in_graph(build_loss_fn, num_steps=200, optimizer=None):
"""Run an optimizer within the graph to minimize a loss function."""
optimizer = tf.compat.v1.train.AdamOptimizer(
0.1) if optimizer is None else optimizer
def train_loop_body(step):
train_op = optimizer.minimize(
build_loss_... | def _minimize_in_graph(build_loss_fn, num_steps=200, optimizer=None):
"""Run an optimizer within the graph to minimize a loss function."""
optimizer = tf.compat.v1.train.AdamOptimizer(
0.1) if optimizer is None else optimizer
def train_loop_body(step):
train_op = optimizer.minimize(
build_loss_... | [
"Run",
"an",
"optimizer",
"within",
"the",
"graph",
"to",
"minimize",
"a",
"loss",
"function",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/fitting.py#L267-L282 | [
"def",
"_minimize_in_graph",
"(",
"build_loss_fn",
",",
"num_steps",
"=",
"200",
",",
"optimizer",
"=",
"None",
")",
":",
"optimizer",
"=",
"tf",
".",
"compat",
".",
"v1",
".",
"train",
".",
"AdamOptimizer",
"(",
"0.1",
")",
"if",
"optimizer",
"is",
"Non... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | fit_with_hmc | Draw posterior samples using Hamiltonian Monte Carlo (HMC).
Markov chain Monte Carlo (MCMC) methods are considered the gold standard of
Bayesian inference; under suitable conditions and in the limit of infinitely
many draws they generate samples from the true posterior distribution. HMC [1]
uses gradients of t... | tensorflow_probability/python/sts/fitting.py | def fit_with_hmc(model,
observed_time_series,
num_results=100,
num_warmup_steps=50,
num_leapfrog_steps=15,
initial_state=None,
initial_step_size=None,
chain_batch_shape=(),
num_variati... | def fit_with_hmc(model,
observed_time_series,
num_results=100,
num_warmup_steps=50,
num_leapfrog_steps=15,
initial_state=None,
initial_step_size=None,
chain_batch_shape=(),
num_variati... | [
"Draw",
"posterior",
"samples",
"using",
"Hamiltonian",
"Monte",
"Carlo",
"(",
"HMC",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/fitting.py#L285-L537 | [
"def",
"fit_with_hmc",
"(",
"model",
",",
"observed_time_series",
",",
"num_results",
"=",
"100",
",",
"num_warmup_steps",
"=",
"50",
",",
"num_leapfrog_steps",
"=",
"15",
",",
"initial_state",
"=",
"None",
",",
"initial_step_size",
"=",
"None",
",",
"chain_batc... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | moments_of_masked_time_series | Compute mean and variance, accounting for a mask.
Args:
time_series_tensor: float `Tensor` time series of shape
`concat([batch_shape, [num_timesteps]])`.
broadcast_mask: bool `Tensor` of the same shape as `time_series`.
Returns:
mean: float `Tensor` of shape `batch_shape`.
variance: float `Te... | tensorflow_probability/python/sts/internal/missing_values_util.py | def moments_of_masked_time_series(time_series_tensor, broadcast_mask):
"""Compute mean and variance, accounting for a mask.
Args:
time_series_tensor: float `Tensor` time series of shape
`concat([batch_shape, [num_timesteps]])`.
broadcast_mask: bool `Tensor` of the same shape as `time_series`.
Retur... | def moments_of_masked_time_series(time_series_tensor, broadcast_mask):
"""Compute mean and variance, accounting for a mask.
Args:
time_series_tensor: float `Tensor` time series of shape
`concat([batch_shape, [num_timesteps]])`.
broadcast_mask: bool `Tensor` of the same shape as `time_series`.
Retur... | [
"Compute",
"mean",
"and",
"variance",
"accounting",
"for",
"a",
"mask",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/missing_values_util.py#L109-L134 | [
"def",
"moments_of_masked_time_series",
"(",
"time_series_tensor",
",",
"broadcast_mask",
")",
":",
"num_unmasked_entries",
"=",
"tf",
".",
"cast",
"(",
"tf",
".",
"reduce_sum",
"(",
"input_tensor",
"=",
"tf",
".",
"cast",
"(",
"~",
"broadcast_mask",
",",
"tf",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | initial_value_of_masked_time_series | Get the first unmasked entry of each time series in the batch.
Args:
time_series_tensor: float `Tensor` of shape [..., num_timesteps].
broadcast_mask: bool `Tensor` of same shape as `time_series`. | tensorflow_probability/python/sts/internal/missing_values_util.py | def initial_value_of_masked_time_series(time_series_tensor, broadcast_mask):
"""Get the first unmasked entry of each time series in the batch.
Args:
time_series_tensor: float `Tensor` of shape [..., num_timesteps].
broadcast_mask: bool `Tensor` of same shape as `time_series`.
"""
num_timesteps = tf.sh... | def initial_value_of_masked_time_series(time_series_tensor, broadcast_mask):
"""Get the first unmasked entry of each time series in the batch.
Args:
time_series_tensor: float `Tensor` of shape [..., num_timesteps].
broadcast_mask: bool `Tensor` of same shape as `time_series`.
"""
num_timesteps = tf.sh... | [
"Get",
"the",
"first",
"unmasked",
"entry",
"of",
"each",
"time",
"series",
"in",
"the",
"batch",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/missing_values_util.py#L137-L162 | [
"def",
"initial_value_of_masked_time_series",
"(",
"time_series_tensor",
",",
"broadcast_mask",
")",
":",
"num_timesteps",
"=",
"tf",
".",
"shape",
"(",
"input",
"=",
"time_series_tensor",
")",
"[",
"-",
"1",
"]",
"# Compute the index of the first unmasked entry for each ... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | broadcast_batch_shape | Get broadcast batch shape from distributions, statically if possible. | tensorflow_probability/python/sts/internal/util.py | def broadcast_batch_shape(distributions):
"""Get broadcast batch shape from distributions, statically if possible."""
# Static case
batch_shape = distributions[0].batch_shape
for distribution in distributions:
batch_shape = tf.broadcast_static_shape(batch_shape,
... | def broadcast_batch_shape(distributions):
"""Get broadcast batch shape from distributions, statically if possible."""
# Static case
batch_shape = distributions[0].batch_shape
for distribution in distributions:
batch_shape = tf.broadcast_static_shape(batch_shape,
... | [
"Get",
"broadcast",
"batch",
"shape",
"from",
"distributions",
"statically",
"if",
"possible",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L32-L49 | [
"def",
"broadcast_batch_shape",
"(",
"distributions",
")",
":",
"# Static case",
"batch_shape",
"=",
"distributions",
"[",
"0",
"]",
".",
"batch_shape",
"for",
"distribution",
"in",
"distributions",
":",
"batch_shape",
"=",
"tf",
".",
"broadcast_static_shape",
"(",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | pad_batch_dimension_for_multiple_chains | Expand the observed time series with extra batch dimension(s). | tensorflow_probability/python/sts/internal/util.py | def pad_batch_dimension_for_multiple_chains(
observed_time_series, model, chain_batch_shape):
""""Expand the observed time series with extra batch dimension(s)."""
# Running with multiple chains introduces an extra batch dimension. In
# general we also need to pad the observed time series with a matching batc... | def pad_batch_dimension_for_multiple_chains(
observed_time_series, model, chain_batch_shape):
""""Expand the observed time series with extra batch dimension(s)."""
# Running with multiple chains introduces an extra batch dimension. In
# general we also need to pad the observed time series with a matching batc... | [
"Expand",
"the",
"observed",
"time",
"series",
"with",
"extra",
"batch",
"dimension",
"(",
"s",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L52-L116 | [
"def",
"pad_batch_dimension_for_multiple_chains",
"(",
"observed_time_series",
",",
"model",
",",
"chain_batch_shape",
")",
":",
"# Running with multiple chains introduces an extra batch dimension. In",
"# general we also need to pad the observed time series with a matching batch",
"# dimens... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | factored_joint_mvn | Combine MultivariateNormals into a factored joint distribution.
Given a list of multivariate normal distributions
`dist[i] = Normal(loc[i], scale[i])`, construct the joint
distribution given by concatenating independent samples from these
distributions. This is multivariate normal with mean vector given by... | tensorflow_probability/python/sts/internal/util.py | def factored_joint_mvn(distributions):
"""Combine MultivariateNormals into a factored joint distribution.
Given a list of multivariate normal distributions
`dist[i] = Normal(loc[i], scale[i])`, construct the joint
distribution given by concatenating independent samples from these
distributions. This is m... | def factored_joint_mvn(distributions):
"""Combine MultivariateNormals into a factored joint distribution.
Given a list of multivariate normal distributions
`dist[i] = Normal(loc[i], scale[i])`, construct the joint
distribution given by concatenating independent samples from these
distributions. This is m... | [
"Combine",
"MultivariateNormals",
"into",
"a",
"factored",
"joint",
"distribution",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L119-L161 | [
"def",
"factored_joint_mvn",
"(",
"distributions",
")",
":",
"graph_parents",
"=",
"[",
"tensor",
"for",
"distribution",
"in",
"distributions",
"for",
"tensor",
"in",
"distribution",
".",
"_graph_parents",
"]",
"# pylint: disable=protected-access",
"with",
"tf",
".",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | sum_mvns | Attempt to sum MultivariateNormal distributions.
The sum of (multivariate) normal random variables is itself (multivariate)
normal, with mean given by the sum of means and (co)variance given by the
sum of (co)variances. This method exploits this fact to compute the
sum of a list of `tfd.MultivariateNormalDiag`... | tensorflow_probability/python/sts/internal/util.py | def sum_mvns(distributions):
"""Attempt to sum MultivariateNormal distributions.
The sum of (multivariate) normal random variables is itself (multivariate)
normal, with mean given by the sum of means and (co)variance given by the
sum of (co)variances. This method exploits this fact to compute the
sum of a li... | def sum_mvns(distributions):
"""Attempt to sum MultivariateNormal distributions.
The sum of (multivariate) normal random variables is itself (multivariate)
normal, with mean given by the sum of means and (co)variance given by the
sum of (co)variances. This method exploits this fact to compute the
sum of a li... | [
"Attempt",
"to",
"sum",
"MultivariateNormal",
"distributions",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L164-L198 | [
"def",
"sum_mvns",
"(",
"distributions",
")",
":",
"graph_parents",
"=",
"[",
"tensor",
"for",
"distribution",
"in",
"distributions",
"for",
"tensor",
"in",
"distribution",
".",
"_graph_parents",
"]",
"# pylint: disable=protected-access",
"with",
"tf",
".",
"compat"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | empirical_statistics | Compute statistics of a provided time series, as heuristic initialization.
Args:
observed_time_series: `Tensor` representing a time series, or batch of time
series, of shape either `batch_shape + [num_timesteps, 1]` or
`batch_shape + [num_timesteps]` (allowed if `num_timesteps > 1`).
Returns:
... | tensorflow_probability/python/sts/internal/util.py | def empirical_statistics(observed_time_series):
"""Compute statistics of a provided time series, as heuristic initialization.
Args:
observed_time_series: `Tensor` representing a time series, or batch of time
series, of shape either `batch_shape + [num_timesteps, 1]` or
`batch_shape + [num_timeste... | def empirical_statistics(observed_time_series):
"""Compute statistics of a provided time series, as heuristic initialization.
Args:
observed_time_series: `Tensor` representing a time series, or batch of time
series, of shape either `batch_shape + [num_timesteps, 1]` or
`batch_shape + [num_timeste... | [
"Compute",
"statistics",
"of",
"a",
"provided",
"time",
"series",
"as",
"heuristic",
"initialization",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L201-L252 | [
"def",
"empirical_statistics",
"(",
"observed_time_series",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"'empirical_statistics'",
",",
"values",
"=",
"[",
"observed_time_series",
"]",
")",
":",
"[",
"observed_time_series",
",",
"mas... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _maybe_expand_trailing_dim | Ensures `observed_time_series_tensor` has a trailing dimension of size 1.
The `tfd.LinearGaussianStateSpaceModel` Distribution has event shape of
`[num_timesteps, observation_size]`, but canonical BSTS models
are univariate, so their observation_size is always `1`. The extra trailing
dimension gets annoying, s... | tensorflow_probability/python/sts/internal/util.py | def _maybe_expand_trailing_dim(observed_time_series_tensor):
"""Ensures `observed_time_series_tensor` has a trailing dimension of size 1.
The `tfd.LinearGaussianStateSpaceModel` Distribution has event shape of
`[num_timesteps, observation_size]`, but canonical BSTS models
are univariate, so their observation_s... | def _maybe_expand_trailing_dim(observed_time_series_tensor):
"""Ensures `observed_time_series_tensor` has a trailing dimension of size 1.
The `tfd.LinearGaussianStateSpaceModel` Distribution has event shape of
`[num_timesteps, observation_size]`, but canonical BSTS models
are univariate, so their observation_s... | [
"Ensures",
"observed_time_series_tensor",
"has",
"a",
"trailing",
"dimension",
"of",
"size",
"1",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L255-L293 | [
"def",
"_maybe_expand_trailing_dim",
"(",
"observed_time_series_tensor",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"'maybe_expand_trailing_dim'",
",",
"values",
"=",
"[",
"observed_time_series_tensor",
"]",
")",
":",
"if",
"(",
"obs... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | canonicalize_observed_time_series_with_mask | Extract a Tensor with canonical shape and optional mask.
Args:
maybe_masked_observed_time_series: a `Tensor`-like object with shape
`[..., num_timesteps]` or `[..., num_timesteps, 1]`, or a
`tfp.sts.MaskedTimeSeries` containing such an object.
Returns:
masked_time_series: a `tfp.sts.MaskedTimeS... | tensorflow_probability/python/sts/internal/util.py | def canonicalize_observed_time_series_with_mask(
maybe_masked_observed_time_series):
"""Extract a Tensor with canonical shape and optional mask.
Args:
maybe_masked_observed_time_series: a `Tensor`-like object with shape
`[..., num_timesteps]` or `[..., num_timesteps, 1]`, or a
`tfp.sts.MaskedTi... | def canonicalize_observed_time_series_with_mask(
maybe_masked_observed_time_series):
"""Extract a Tensor with canonical shape and optional mask.
Args:
maybe_masked_observed_time_series: a `Tensor`-like object with shape
`[..., num_timesteps]` or `[..., num_timesteps, 1]`, or a
`tfp.sts.MaskedTi... | [
"Extract",
"a",
"Tensor",
"with",
"canonical",
"shape",
"and",
"optional",
"mask",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L296-L329 | [
"def",
"canonicalize_observed_time_series_with_mask",
"(",
"maybe_masked_observed_time_series",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"'canonicalize_observed_time_series_with_mask'",
")",
":",
"if",
"hasattr",
"(",
"maybe_masked_observed_... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | mix_over_posterior_draws | Construct a predictive normal distribution that mixes over posterior draws.
Args:
means: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
variances: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
Returns:
mixture_dist: `tfd.MixtureSameFamily(tfd.In... | tensorflow_probability/python/sts/internal/util.py | def mix_over_posterior_draws(means, variances):
"""Construct a predictive normal distribution that mixes over posterior draws.
Args:
means: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
variances: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
Ret... | def mix_over_posterior_draws(means, variances):
"""Construct a predictive normal distribution that mixes over posterior draws.
Args:
means: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
variances: float `Tensor` of shape
`[num_posterior_draws, ..., num_timesteps]`.
Ret... | [
"Construct",
"a",
"predictive",
"normal",
"distribution",
"that",
"mixes",
"over",
"posterior",
"draws",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/internal/util.py#L332-L375 | [
"def",
"mix_over_posterior_draws",
"(",
"means",
",",
"variances",
")",
":",
"# The inputs `means`, `variances` have shape",
"# `concat([",
"# [num_posterior_draws],",
"# sample_shape,",
"# batch_shape,",
"# [num_timesteps]])`",
"# Because MixtureSameFamily mixes ov... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _kl_uniform_uniform | Calculate the batched KL divergence KL(a || b) with a and b Uniform.
Note that the KL divergence is infinite if the support of `a` is not a subset
of the support of `b`.
Args:
a: instance of a Uniform distribution object.
b: instance of a Uniform distribution object.
name: (optional) Name to use for... | tensorflow_probability/python/distributions/uniform.py | def _kl_uniform_uniform(a, b, name=None):
"""Calculate the batched KL divergence KL(a || b) with a and b Uniform.
Note that the KL divergence is infinite if the support of `a` is not a subset
of the support of `b`.
Args:
a: instance of a Uniform distribution object.
b: instance of a Uniform distributi... | def _kl_uniform_uniform(a, b, name=None):
"""Calculate the batched KL divergence KL(a || b) with a and b Uniform.
Note that the KL divergence is infinite if the support of `a` is not a subset
of the support of `b`.
Args:
a: instance of a Uniform distribution object.
b: instance of a Uniform distributi... | [
"Calculate",
"the",
"batched",
"KL",
"divergence",
"KL",
"(",
"a",
"||",
"b",
")",
"with",
"a",
"and",
"b",
"Uniform",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/uniform.py#L214-L242 | [
"def",
"_kl_uniform_uniform",
"(",
"a",
",",
"b",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"kl_uniform_uniform\"",
")",
":",
"# Consistent with",
"# http://www.mast.queensu.ca/~communications/Papers/gil-msc11.pdf, page 60... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | Uniform.range | `high - low`. | tensorflow_probability/python/distributions/uniform.py | def range(self, name="range"):
"""`high - low`."""
with self._name_scope(name):
return self.high - self.low | def range(self, name="range"):
"""`high - low`."""
with self._name_scope(name):
return self.high - self.low | [
"high",
"-",
"low",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/uniform.py#L144-L147 | [
"def",
"range",
"(",
"self",
",",
"name",
"=",
"\"range\"",
")",
":",
"with",
"self",
".",
"_name_scope",
"(",
"name",
")",
":",
"return",
"self",
".",
"high",
"-",
"self",
".",
"low"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _make_summary_statistic | Factory for making summary statistics, eg, mean, mode, stddev. | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _make_summary_statistic(attr):
"""Factory for making summary statistics, eg, mean, mode, stddev."""
def _fn(self):
if any(self._dist_fn_args): # pylint: disable=protected-access
raise ValueError(
'Can only compute ' + attr + ' when all distributions are '
'independent; {}'.format(... | def _make_summary_statistic(attr):
"""Factory for making summary statistics, eg, mean, mode, stddev."""
def _fn(self):
if any(self._dist_fn_args): # pylint: disable=protected-access
raise ValueError(
'Can only compute ' + attr + ' when all distributions are '
'independent; {}'.format(... | [
"Factory",
"for",
"making",
"summary",
"statistics",
"eg",
"mean",
"mode",
"stddev",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L38-L46 | [
"def",
"_make_summary_statistic",
"(",
"attr",
")",
":",
"def",
"_fn",
"(",
"self",
")",
":",
"if",
"any",
"(",
"self",
".",
"_dist_fn_args",
")",
":",
"# pylint: disable=protected-access",
"raise",
"ValueError",
"(",
"'Can only compute '",
"+",
"attr",
"+",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _unify_call_signature | Creates `dist_fn_wrapped` which calls `dist_fn` with all prev nodes.
Args:
i: Python `int` corresponding to position in topologically sorted DAG.
dist_fn: Python `callable` which takes a subset of previously constructed
distributions (in reverse order) and produces a new distribution instance.
Retur... | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _unify_call_signature(i, dist_fn):
"""Creates `dist_fn_wrapped` which calls `dist_fn` with all prev nodes.
Args:
i: Python `int` corresponding to position in topologically sorted DAG.
dist_fn: Python `callable` which takes a subset of previously constructed
distributions (in reverse order) and pr... | def _unify_call_signature(i, dist_fn):
"""Creates `dist_fn_wrapped` which calls `dist_fn` with all prev nodes.
Args:
i: Python `int` corresponding to position in topologically sorted DAG.
dist_fn: Python `callable` which takes a subset of previously constructed
distributions (in reverse order) and pr... | [
"Creates",
"dist_fn_wrapped",
"which",
"calls",
"dist_fn",
"with",
"all",
"prev",
"nodes",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L409-L449 | [
"def",
"_unify_call_signature",
"(",
"i",
",",
"dist_fn",
")",
":",
"if",
"distribution_util",
".",
"is_distribution_instance",
"(",
"dist_fn",
")",
":",
"return",
"(",
"lambda",
"*",
"_",
":",
"dist_fn",
")",
",",
"None",
"if",
"not",
"callable",
"(",
"di... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _resolve_distribution_names | Uses arg names to resolve distribution names. | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _resolve_distribution_names(dist_fn_args, dist_names, leaf_name):
"""Uses arg names to resolve distribution names."""
if dist_names is None:
dist_names = []
else:
dist_names = dist_names.copy()
n = len(dist_fn_args)
dist_names.extend([None]*(n - len(dist_names)))
for i_, args in enumerate(revers... | def _resolve_distribution_names(dist_fn_args, dist_names, leaf_name):
"""Uses arg names to resolve distribution names."""
if dist_names is None:
dist_names = []
else:
dist_names = dist_names.copy()
n = len(dist_fn_args)
dist_names.extend([None]*(n - len(dist_names)))
for i_, args in enumerate(revers... | [
"Uses",
"arg",
"names",
"to",
"resolve",
"distribution",
"names",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L452-L472 | [
"def",
"_resolve_distribution_names",
"(",
"dist_fn_args",
",",
"dist_names",
",",
"leaf_name",
")",
":",
"if",
"dist_names",
"is",
"None",
":",
"dist_names",
"=",
"[",
"]",
"else",
":",
"dist_names",
"=",
"dist_names",
".",
"copy",
"(",
")",
"n",
"=",
"le... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _get_required_args | Returns the distribution's required args. | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _get_required_args(fn):
"""Returns the distribution's required args."""
argspec = tf_inspect.getfullargspec(fn)
args = argspec.args
if tf_inspect.isclass(fn):
args = args[1:] # Remove the `self` arg.
if argspec.defaults:
# Remove the args which have defaults. By convention we only feed
# *req... | def _get_required_args(fn):
"""Returns the distribution's required args."""
argspec = tf_inspect.getfullargspec(fn)
args = argspec.args
if tf_inspect.isclass(fn):
args = args[1:] # Remove the `self` arg.
if argspec.defaults:
# Remove the args which have defaults. By convention we only feed
# *req... | [
"Returns",
"the",
"distribution",
"s",
"required",
"args",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L475-L487 | [
"def",
"_get_required_args",
"(",
"fn",
")",
":",
"argspec",
"=",
"tf_inspect",
".",
"getfullargspec",
"(",
"fn",
")",
"args",
"=",
"argspec",
".",
"args",
"if",
"tf_inspect",
".",
"isclass",
"(",
"fn",
")",
":",
"args",
"=",
"args",
"[",
"1",
":",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _kl_joint_joint | Calculate the KL divergence between two `JointDistributionSequential`s.
Args:
d0: instance of a `JointDistributionSequential` object.
d1: instance of a `JointDistributionSequential` object.
name: (optional) Name to use for created operations.
Default value: `"kl_joint_joint"`.
Returns:
kl_jo... | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _kl_joint_joint(d0, d1, name=None):
"""Calculate the KL divergence between two `JointDistributionSequential`s.
Args:
d0: instance of a `JointDistributionSequential` object.
d1: instance of a `JointDistributionSequential` object.
name: (optional) Name to use for created operations.
Default val... | def _kl_joint_joint(d0, d1, name=None):
"""Calculate the KL divergence between two `JointDistributionSequential`s.
Args:
d0: instance of a `JointDistributionSequential` object.
d1: instance of a `JointDistributionSequential` object.
name: (optional) Name to use for created operations.
Default val... | [
"Calculate",
"the",
"KL",
"divergence",
"between",
"two",
"JointDistributionSequential",
"s",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L492-L523 | [
"def",
"_kl_joint_joint",
"(",
"d0",
",",
"d1",
",",
"name",
"=",
"None",
")",
":",
"if",
"len",
"(",
"d0",
".",
"_dist_fn_wrapped",
")",
"!=",
"len",
"(",
"d1",
".",
"_dist_fn_wrapped",
")",
":",
"# pylint: disable=protected-access",
"raise",
"ValueError",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | JointDistributionSequential._build | Creates `dist_fn`, `dist_fn_wrapped`, `dist_fn_args`. | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _build(self, model):
"""Creates `dist_fn`, `dist_fn_wrapped`, `dist_fn_args`."""
if not isinstance(model, collections.Sequence):
raise TypeError('`model` must be `list`-like (saw: {}).'.format(
type(model).__name__))
self._dist_fn = model
self._dist_fn_wrapped, self._dist_fn_args = z... | def _build(self, model):
"""Creates `dist_fn`, `dist_fn_wrapped`, `dist_fn_args`."""
if not isinstance(model, collections.Sequence):
raise TypeError('`model` must be `list`-like (saw: {}).'.format(
type(model).__name__))
self._dist_fn = model
self._dist_fn_wrapped, self._dist_fn_args = z... | [
"Creates",
"dist_fn",
"dist_fn_wrapped",
"dist_fn_args",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L210-L218 | [
"def",
"_build",
"(",
"self",
",",
"model",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"collections",
".",
"Sequence",
")",
":",
"raise",
"TypeError",
"(",
"'`model` must be `list`-like (saw: {}).'",
".",
"format",
"(",
"type",
"(",
"model",
")"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | JointDistributionSequential._resolve_graph | Creates a `tuple` of `tuple`s of dependencies.
This function is **experimental**. That said, we encourage its use
and ask that you report problems to `tfprobability@tensorflow.org`.
Args:
distribution_names: `list` of `str` or `None` names corresponding to each
of `model` elements. (`None`s ... | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _resolve_graph(self, distribution_names=None, leaf_name='x'):
"""Creates a `tuple` of `tuple`s of dependencies.
This function is **experimental**. That said, we encourage its use
and ask that you report problems to `tfprobability@tensorflow.org`.
Args:
distribution_names: `list` of `str` or ... | def _resolve_graph(self, distribution_names=None, leaf_name='x'):
"""Creates a `tuple` of `tuple`s of dependencies.
This function is **experimental**. That said, we encourage its use
and ask that you report problems to `tfprobability@tensorflow.org`.
Args:
distribution_names: `list` of `str` or ... | [
"Creates",
"a",
"tuple",
"of",
"tuple",
"s",
"of",
"dependencies",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L276-L326 | [
"def",
"_resolve_graph",
"(",
"self",
",",
"distribution_names",
"=",
"None",
",",
"leaf_name",
"=",
"'x'",
")",
":",
"# This function additionally depends on:",
"# self._dist_fn_args",
"# self._dist_fn_wrapped",
"# TODO(b/129008220): Robustify this procedure. Eg, handle collis... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | JointDistributionSequential._entropy | Shannon entropy in nats. | tensorflow_probability/python/distributions/joint_distribution_sequential.py | def _entropy(self):
"""Shannon entropy in nats."""
if any(self._dist_fn_args):
raise ValueError(
'Can only compute entropy when all distributions are independent.')
return sum(joint_distribution_lib.maybe_check_wont_broadcast(
(d().entropy() for d in self._dist_fn_wrapped),
s... | def _entropy(self):
"""Shannon entropy in nats."""
if any(self._dist_fn_args):
raise ValueError(
'Can only compute entropy when all distributions are independent.')
return sum(joint_distribution_lib.maybe_check_wont_broadcast(
(d().entropy() for d in self._dist_fn_wrapped),
s... | [
"Shannon",
"entropy",
"in",
"nats",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_sequential.py#L333-L340 | [
"def",
"_entropy",
"(",
"self",
")",
":",
"if",
"any",
"(",
"self",
".",
"_dist_fn_args",
")",
":",
"raise",
"ValueError",
"(",
"'Can only compute entropy when all distributions are independent.'",
")",
"return",
"sum",
"(",
"joint_distribution_lib",
".",
"maybe_check... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | check_arg_in_support | Decorator function for argument bounds checking.
This decorator is meant to be used with methods that require the first
argument to be in the support of the distribution. If `validate_args` is
`True`, the method is wrapped with an assertion that the first argument is
greater than or equal to `loc`, since the s... | tensorflow_probability/python/distributions/half_cauchy.py | def check_arg_in_support(f):
"""Decorator function for argument bounds checking.
This decorator is meant to be used with methods that require the first
argument to be in the support of the distribution. If `validate_args` is
`True`, the method is wrapped with an assertion that the first argument is
greater t... | def check_arg_in_support(f):
"""Decorator function for argument bounds checking.
This decorator is meant to be used with methods that require the first
argument to be in the support of the distribution. If `validate_args` is
`True`, the method is wrapped with an assertion that the first argument is
greater t... | [
"Decorator",
"function",
"for",
"argument",
"bounds",
"checking",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/half_cauchy.py#L36-L63 | [
"def",
"check_arg_in_support",
"(",
"f",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"_check_arg_and_apply_f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"dist",
"=",
"args",
"[",
"0",
"]",
"x",
"=",
"args",
"[",
"1",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | HalfCauchy._extend_support_with_default_value | Returns `f(x)` if x is in the support, and `default_value` otherwise.
Given `f` which is defined on the support of this distribution
(`x >= loc`), extend the function definition to the real line
by defining `f(x) = default_value` for `x < loc`.
Args:
x: Floating-point `Tensor` to evaluate `f` at... | tensorflow_probability/python/distributions/half_cauchy.py | def _extend_support_with_default_value(self, x, f, default_value):
"""Returns `f(x)` if x is in the support, and `default_value` otherwise.
Given `f` which is defined on the support of this distribution
(`x >= loc`), extend the function definition to the real line
by defining `f(x) = default_value` for... | def _extend_support_with_default_value(self, x, f, default_value):
"""Returns `f(x)` if x is in the support, and `default_value` otherwise.
Given `f` which is defined on the support of this distribution
(`x >= loc`), extend the function definition to the real line
by defining `f(x) = default_value` for... | [
"Returns",
"f",
"(",
"x",
")",
"if",
"x",
"is",
"in",
"the",
"support",
"and",
"default_value",
"otherwise",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/half_cauchy.py#L228-L259 | [
"def",
"_extend_support_with_default_value",
"(",
"self",
",",
"x",
",",
"f",
",",
"default_value",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"\"extend_support_with_default_value\"",
")",
":",
"x",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"value",
"=",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _prepare_args | Processes input args to meet list-like assumptions. | experimental/mcmc/elliptical_slice_sampler.py | def _prepare_args(log_likelihood_fn, state,
log_likelihood=None, description='log_likelihood'):
"""Processes input args to meet list-like assumptions."""
state_parts = list(state) if mcmc_util.is_list_like(state) else [state]
state_parts = [tf.convert_to_tensor(s, name='current_state')
... | def _prepare_args(log_likelihood_fn, state,
log_likelihood=None, description='log_likelihood'):
"""Processes input args to meet list-like assumptions."""
state_parts = list(state) if mcmc_util.is_list_like(state) else [state]
state_parts = [tf.convert_to_tensor(s, name='current_state')
... | [
"Processes",
"input",
"args",
"to",
"meet",
"list",
"-",
"like",
"assumptions",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/experimental/mcmc/elliptical_slice_sampler.py#L405-L417 | [
"def",
"_prepare_args",
"(",
"log_likelihood_fn",
",",
"state",
",",
"log_likelihood",
"=",
"None",
",",
"description",
"=",
"'log_likelihood'",
")",
":",
"state_parts",
"=",
"list",
"(",
"state",
")",
"if",
"mcmc_util",
".",
"is_list_like",
"(",
"state",
")",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | EllipticalSliceSampler.one_step | Runs one iteration of the Elliptical Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
`r = tf.rank(log_likelihood_fn(*normal_sampler_fn()))`.
pr... | experimental/mcmc/elliptical_slice_sampler.py | def one_step(self, current_state, previous_kernel_results):
"""Runs one iteration of the Elliptical Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
... | def one_step(self, current_state, previous_kernel_results):
"""Runs one iteration of the Elliptical Slice Sampler.
Args:
current_state: `Tensor` or Python `list` of `Tensor`s representing the
current state(s) of the Markov chain(s). The first `r` dimensions
index independent chains,
... | [
"Runs",
"one",
"iteration",
"of",
"the",
"Elliptical",
"Slice",
"Sampler",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/experimental/mcmc/elliptical_slice_sampler.py#L228-L372 | [
"def",
"one_step",
"(",
"self",
",",
"current_state",
",",
"previous_kernel_results",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"name",
"=",
"mcmc_util",
".",
"make_name",
"(",
"self",
".",
"name",
",",
"'elliptical_slice'",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | image_summary | Visualizes sequences as TensorBoard summaries.
Args:
seqs: A tensor of shape [n, t, h, w, c].
name: String name of this summary.
num: Integer for the number of examples to visualize. Defaults to
all examples. | tensorflow_probability/examples/disentangled_vae.py | def image_summary(seqs, name, num=None):
"""Visualizes sequences as TensorBoard summaries.
Args:
seqs: A tensor of shape [n, t, h, w, c].
name: String name of this summary.
num: Integer for the number of examples to visualize. Defaults to
all examples.
"""
seqs = tf.clip_by_value(seqs, 0., 1.... | def image_summary(seqs, name, num=None):
"""Visualizes sequences as TensorBoard summaries.
Args:
seqs: A tensor of shape [n, t, h, w, c].
name: String name of this summary.
num: Integer for the number of examples to visualize. Defaults to
all examples.
"""
seqs = tf.clip_by_value(seqs, 0., 1.... | [
"Visualizes",
"sequences",
"as",
"TensorBoard",
"summaries",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L965-L982 | [
"def",
"image_summary",
"(",
"seqs",
",",
"name",
",",
"num",
"=",
"None",
")",
":",
"seqs",
"=",
"tf",
".",
"clip_by_value",
"(",
"seqs",
",",
"0.",
",",
"1.",
")",
"seqs",
"=",
"tf",
".",
"unstack",
"(",
"seqs",
"[",
":",
"num",
"]",
")",
"jo... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | visualize_reconstruction | Visualizes the reconstruction of inputs in TensorBoard.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
reconstruct: A tensor of a reconstruction of inputs, of shape
[batch, timesteps, h, w, c].
num: Integer for the number of examples to visualize.
nam... | tensorflow_probability/examples/disentangled_vae.py | def visualize_reconstruction(inputs, reconstruct, num=3, name="reconstruction"):
"""Visualizes the reconstruction of inputs in TensorBoard.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
reconstruct: A tensor of a reconstruction of inputs, of shape
[batch, ... | def visualize_reconstruction(inputs, reconstruct, num=3, name="reconstruction"):
"""Visualizes the reconstruction of inputs in TensorBoard.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
reconstruct: A tensor of a reconstruction of inputs, of shape
[batch, ... | [
"Visualizes",
"the",
"reconstruction",
"of",
"inputs",
"in",
"TensorBoard",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L985-L998 | [
"def",
"visualize_reconstruction",
"(",
"inputs",
",",
"reconstruct",
",",
"num",
"=",
"3",
",",
"name",
"=",
"\"reconstruction\"",
")",
":",
"reconstruct",
"=",
"tf",
".",
"clip_by_value",
"(",
"reconstruct",
",",
"0.",
",",
"1.",
")",
"inputs_and_reconstruct... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | visualize_qualitative_analysis | Visualizes a qualitative analysis of a given model.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
model: A DisentangledSequentialVAE model.
samples: Number of samples to draw from the latent distributions.
batch_size: Number of sequences to generate.
l... | tensorflow_probability/examples/disentangled_vae.py | def visualize_qualitative_analysis(inputs, model, samples=1, batch_size=3,
length=8):
"""Visualizes a qualitative analysis of a given model.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
model: A DisentangledSequentialVAE model... | def visualize_qualitative_analysis(inputs, model, samples=1, batch_size=3,
length=8):
"""Visualizes a qualitative analysis of a given model.
Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
model: A DisentangledSequentialVAE model... | [
"Visualizes",
"a",
"qualitative",
"analysis",
"of",
"a",
"given",
"model",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L1001-L1032 | [
"def",
"visualize_qualitative_analysis",
"(",
"inputs",
",",
"model",
",",
"samples",
"=",
"1",
",",
"batch_size",
"=",
"3",
",",
"length",
"=",
"8",
")",
":",
"average",
"=",
"lambda",
"dist",
":",
"tf",
".",
"reduce_mean",
"(",
"input_tensor",
"=",
"di... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | summarize_dist_params | Summarize the parameters of a distribution.
Args:
dist: A Distribution object with mean and standard deviation
parameters.
name: The name of the distribution.
name_scope: The name scope of this summary. | tensorflow_probability/examples/disentangled_vae.py | def summarize_dist_params(dist, name, name_scope="dist_params"):
"""Summarize the parameters of a distribution.
Args:
dist: A Distribution object with mean and standard deviation
parameters.
name: The name of the distribution.
name_scope: The name scope of this summary.
"""
with tf.compat.v1.... | def summarize_dist_params(dist, name, name_scope="dist_params"):
"""Summarize the parameters of a distribution.
Args:
dist: A Distribution object with mean and standard deviation
parameters.
name: The name of the distribution.
name_scope: The name scope of this summary.
"""
with tf.compat.v1.... | [
"Summarize",
"the",
"parameters",
"of",
"a",
"distribution",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L1035-L1052 | [
"def",
"summarize_dist_params",
"(",
"dist",
",",
"name",
",",
"name_scope",
"=",
"\"dist_params\"",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"name_scope",
")",
":",
"tf",
".",
"compat",
".",
"v2",
".",
"summary",
".",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | summarize_mean_in_nats_and_bits | Summarize the mean of a tensor in nats and bits per unit.
Args:
inputs: A tensor of values measured in nats.
units: The units of the tensor with which to compute the mean bits
per unit.
name: The name of the tensor.
nats_name_scope: The name scope of the nats summary.
bits_name_scope: The n... | tensorflow_probability/examples/disentangled_vae.py | def summarize_mean_in_nats_and_bits(inputs, units, name,
nats_name_scope="nats",
bits_name_scope="bits_per_dim"):
"""Summarize the mean of a tensor in nats and bits per unit.
Args:
inputs: A tensor of values measured in nats.
units: Th... | def summarize_mean_in_nats_and_bits(inputs, units, name,
nats_name_scope="nats",
bits_name_scope="bits_per_dim"):
"""Summarize the mean of a tensor in nats and bits per unit.
Args:
inputs: A tensor of values measured in nats.
units: Th... | [
"Summarize",
"the",
"mean",
"of",
"a",
"tensor",
"in",
"nats",
"and",
"bits",
"per",
"unit",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L1055-L1078 | [
"def",
"summarize_mean_in_nats_and_bits",
"(",
"inputs",
",",
"units",
",",
"name",
",",
"nats_name_scope",
"=",
"\"nats\"",
",",
"bits_name_scope",
"=",
"\"bits_per_dim\"",
")",
":",
"mean",
"=",
"tf",
".",
"reduce_mean",
"(",
"input_tensor",
"=",
"inputs",
")"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | LearnableMultivariateNormalDiag.call | Runs the model to generate multivariate normal distribution.
Args:
inputs: Unused.
Returns:
A MultivariateNormalDiag distribution with event shape
[dimensions], batch shape [], and sample shape [sample_shape,
dimensions]. | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate multivariate normal distribution.
Args:
inputs: Unused.
Returns:
A MultivariateNormalDiag distribution with event shape
[dimensions], batch shape [], and sample shape [sample_shape,
dimensions].
"""
del inputs # unused
... | def call(self, inputs):
"""Runs the model to generate multivariate normal distribution.
Args:
inputs: Unused.
Returns:
A MultivariateNormalDiag distribution with event shape
[dimensions], batch shape [], and sample shape [sample_shape,
dimensions].
"""
del inputs # unused
... | [
"Runs",
"the",
"model",
"to",
"generate",
"multivariate",
"normal",
"distribution",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L216-L229 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"del",
"inputs",
"# unused",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"self",
".",
"_name",
")",
":",
"return",
"tfd",
".",
"MultivariateNormalDiag",
"(",
"self",
".",
"loc",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | LearnableMultivariateNormalDiagCell.zero_state | Returns an initial state for the LSTM cell.
Args:
sample_batch_shape: A 0D or 1D tensor of the combined sample and
batch shape.
Returns:
A tuple of the initial previous output at timestep 0 of shape
[sample_batch_shape, dimensions], and the cell state. | tensorflow_probability/examples/disentangled_vae.py | def zero_state(self, sample_batch_shape=()):
"""Returns an initial state for the LSTM cell.
Args:
sample_batch_shape: A 0D or 1D tensor of the combined sample and
batch shape.
Returns:
A tuple of the initial previous output at timestep 0 of shape
[sample_batch_shape, dimensions],... | def zero_state(self, sample_batch_shape=()):
"""Returns an initial state for the LSTM cell.
Args:
sample_batch_shape: A 0D or 1D tensor of the combined sample and
batch shape.
Returns:
A tuple of the initial previous output at timestep 0 of shape
[sample_batch_shape, dimensions],... | [
"Returns",
"an",
"initial",
"state",
"for",
"the",
"LSTM",
"cell",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L264-L281 | [
"def",
"zero_state",
"(",
"self",
",",
"sample_batch_shape",
"=",
"(",
")",
")",
":",
"h0",
"=",
"tf",
".",
"zeros",
"(",
"[",
"1",
",",
"self",
".",
"hidden_size",
"]",
")",
"c0",
"=",
"tf",
".",
"zeros",
"(",
"[",
"1",
",",
"self",
".",
"hidd... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | LearnableMultivariateNormalDiagCell.call | Runs the model to generate a distribution for a single timestep.
This generates a batched MultivariateNormalDiag distribution using
the output of the recurrent model at the current timestep to
parameterize the distribution.
Args:
inputs: The sampled value of `z` at the previous timestep, i.e.,
... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs, state):
"""Runs the model to generate a distribution for a single timestep.
This generates a batched MultivariateNormalDiag distribution using
the output of the recurrent model at the current timestep to
parameterize the distribution.
Args:
inputs: The sampled value of... | def call(self, inputs, state):
"""Runs the model to generate a distribution for a single timestep.
This generates a batched MultivariateNormalDiag distribution using
the output of the recurrent model at the current timestep to
parameterize the distribution.
Args:
inputs: The sampled value of... | [
"Runs",
"the",
"model",
"to",
"generate",
"a",
"distribution",
"for",
"a",
"single",
"timestep",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L283-L315 | [
"def",
"call",
"(",
"self",
",",
"inputs",
",",
"state",
")",
":",
"# In order to allow the user to pass in a single example without a batch",
"# dimension, we always expand the input to at least two dimensions, then",
"# fix the output shape to remove the batch dimension if necessary.",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | Decoder.call | Runs the model to generate a distribution p(x_t | z_t, f).
Args:
inputs: A tuple of (z_{1:T}, f), where `z_{1:T}` is a tensor of
shape [..., batch_size, timesteps, latent_size_dynamic], and `f`
is of shape [..., batch_size, latent_size_static].
Returns:
A batched Independent distri... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate a distribution p(x_t | z_t, f).
Args:
inputs: A tuple of (z_{1:T}, f), where `z_{1:T}` is a tensor of
shape [..., batch_size, timesteps, latent_size_dynamic], and `f`
is of shape [..., batch_size, latent_size_static].
Returns:
... | def call(self, inputs):
"""Runs the model to generate a distribution p(x_t | z_t, f).
Args:
inputs: A tuple of (z_{1:T}, f), where `z_{1:T}` is a tensor of
shape [..., batch_size, timesteps, latent_size_dynamic], and `f`
is of shape [..., batch_size, latent_size_static].
Returns:
... | [
"Runs",
"the",
"model",
"to",
"generate",
"a",
"distribution",
"p",
"(",
"x_t",
"|",
"z_t",
"f",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L358-L391 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"# We explicitly broadcast f to the same shape as z other than the final",
"# dimension, because `tf.concat` can't automatically do this.",
"dynamic",
",",
"static",
"=",
"inputs",
"timesteps",
"=",
"tf",
".",
"shape",
"(",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | Compressor.call | Runs the model to generate an intermediate representation of x_t.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[sample_shape, batch_size, timesteps, height, width,
channels]`.
Returns:
A batch of intermediate representations of shape [sample_shape,
batch_size,... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate an intermediate representation of x_t.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[sample_shape, batch_size, timesteps, height, width,
channels]`.
Returns:
A batch of intermediate representations of shape [... | def call(self, inputs):
"""Runs the model to generate an intermediate representation of x_t.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[sample_shape, batch_size, timesteps, height, width,
channels]`.
Returns:
A batch of intermediate representations of shape [... | [
"Runs",
"the",
"model",
"to",
"generate",
"an",
"intermediate",
"representation",
"of",
"x_t",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L421-L441 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"image_shape",
"=",
"tf",
".",
"shape",
"(",
"input",
"=",
"inputs",
")",
"[",
"-",
"3",
":",
"]",
"collapsed_shape",
"=",
"tf",
".",
"concat",
"(",
"(",
"[",
"-",
"1",
"]",
",",
"image_shape",... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | EncoderStatic.call | Runs the model to generate a distribution `q(f | x_{1:T})`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A batch of intermediate representations of image frames
... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate a distribution `q(f | x_{1:T})`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A batch of intermediate repre... | def call(self, inputs):
"""Runs the model to generate a distribution `q(f | x_{1:T})`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A batch of intermediate repre... | [
"Runs",
"the",
"model",
"to",
"generate",
"a",
"distribution",
"q",
"(",
"f",
"|",
"x_",
"{",
"1",
":",
"T",
"}",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L488-L515 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"# TODO(dusenberrymw): Remove these reshaping commands after b/113126249 is",
"# fixed.",
"collapsed_shape",
"=",
"tf",
".",
"concat",
"(",
"(",
"[",
"-",
"1",
"]",
",",
"tf",
".",
"shape",
"(",
"input",
"=",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | EncoderDynamicFactorized.call | Runs the model to generate a distribution `q(z_{1:T} | x_{1:T})`.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
Returns:
A batch of MultivariateNormalDiag distributions with event shap... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate a distribution `q(z_{1:T} | x_{1:T})`.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
Returns:
A batch of MultivariateNormalDia... | def call(self, inputs):
"""Runs the model to generate a distribution `q(z_{1:T} | x_{1:T})`.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
Returns:
A batch of MultivariateNormalDia... | [
"Runs",
"the",
"model",
"to",
"generate",
"a",
"distribution",
"q",
"(",
"z_",
"{",
"1",
":",
"T",
"}",
"|",
"x_",
"{",
"1",
":",
"T",
"}",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L552-L570 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"out",
"=",
"self",
".",
"dense",
"(",
"inputs",
")",
"# (..., batch, time, hidden)",
"out",
"=",
"self",
".",
"output_layer",
"(",
"out",
")",
"# (..., batch, time, 2*latent)",
"loc",
"=",
"out",
"[",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | EncoderDynamicFull.call | Runs the model to generate a distribution `q(z_{1:T} | x_{1:T}, f)`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A tuple of a batch of intermediate representations ... | tensorflow_probability/examples/disentangled_vae.py | def call(self, inputs):
"""Runs the model to generate a distribution `q(z_{1:T} | x_{1:T}, f)`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A tuple of a batch o... | def call(self, inputs):
"""Runs the model to generate a distribution `q(z_{1:T} | x_{1:T}, f)`.
This generates a list of batched MultivariateNormalDiag
distributions using the output of the recurrent model at each
timestep to parameterize each distribution.
Args:
inputs: A tuple of a batch o... | [
"Runs",
"the",
"model",
"to",
"generate",
"a",
"distribution",
"q",
"(",
"z_",
"{",
"1",
":",
"T",
"}",
"|",
"x_",
"{",
"1",
":",
"T",
"}",
"f",
")",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L614-L663 | [
"def",
"call",
"(",
"self",
",",
"inputs",
")",
":",
"# We explicitly broadcast `x` and `f` to the same shape other than the final",
"# dimension, because `tf.concat` can't automatically do this. This will",
"# entail adding a `timesteps` dimension to `f` to give the shape `(...,",
"# batch, t... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.generate | Generate new sequences.
Args:
batch_size: Number of sequences to generate.
length: Number of timesteps to generate for each sequence.
samples: Number of samples to draw from the latent distributions.
fix_static: Boolean for whether or not to share the same random
sample of the stati... | tensorflow_probability/examples/disentangled_vae.py | def generate(self, batch_size, length, samples=1, fix_static=False,
fix_dynamic=False):
"""Generate new sequences.
Args:
batch_size: Number of sequences to generate.
length: Number of timesteps to generate for each sequence.
samples: Number of samples to draw from the latent di... | def generate(self, batch_size, length, samples=1, fix_static=False,
fix_dynamic=False):
"""Generate new sequences.
Args:
batch_size: Number of sequences to generate.
length: Number of timesteps to generate for each sequence.
samples: Number of samples to draw from the latent di... | [
"Generate",
"new",
"sequences",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L758-L785 | [
"def",
"generate",
"(",
"self",
",",
"batch_size",
",",
"length",
",",
"samples",
"=",
"1",
",",
"fix_static",
"=",
"False",
",",
"fix_dynamic",
"=",
"False",
")",
":",
"static_sample",
",",
"_",
"=",
"self",
".",
"sample_static_prior",
"(",
"samples",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.reconstruct | Reconstruct the given input sequences.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[batch_size, timesteps, height, width, channels]`.
samples: Number of samples to draw from the latent distributions.
sample_static: Boolean for whether or not to randomly sample the
... | tensorflow_probability/examples/disentangled_vae.py | def reconstruct(self, inputs, samples=1, sample_static=False,
sample_dynamic=False, swap_static=False, swap_dynamic=False,
fix_static=False, fix_dynamic=False):
"""Reconstruct the given input sequences.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
... | def reconstruct(self, inputs, samples=1, sample_static=False,
sample_dynamic=False, swap_static=False, swap_dynamic=False,
fix_static=False, fix_dynamic=False):
"""Reconstruct the given input sequences.
Args:
inputs: A batch of image sequences `x_{1:T}` of shape
... | [
"Reconstruct",
"the",
"given",
"input",
"sequences",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L787-L844 | [
"def",
"reconstruct",
"(",
"self",
",",
"inputs",
",",
"samples",
"=",
"1",
",",
"sample_static",
"=",
"False",
",",
"sample_dynamic",
"=",
"False",
",",
"swap_static",
"=",
"False",
",",
"swap_dynamic",
"=",
"False",
",",
"fix_static",
"=",
"False",
",",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.sample_static_prior | Sample the static latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
fixed: Boolean for whether or not to share the same random
sample across all sequences.
Returns:
A tuple of a sample tensor of shape... | tensorflow_probability/examples/disentangled_vae.py | def sample_static_prior(self, samples, batch_size, fixed=False):
"""Sample the static latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
fixed: Boolean for whether or not to share the same random
sample acros... | def sample_static_prior(self, samples, batch_size, fixed=False):
"""Sample the static latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
fixed: Boolean for whether or not to share the same random
sample acros... | [
"Sample",
"the",
"static",
"latent",
"prior",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L846-L866 | [
"def",
"sample_static_prior",
"(",
"self",
",",
"samples",
",",
"batch_size",
",",
"fixed",
"=",
"False",
")",
":",
"dist",
"=",
"self",
".",
"static_prior",
"(",
")",
"if",
"fixed",
":",
"# in either case, shape is (samples, batch, latent)",
"sample",
"=",
"dis... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.sample_static_posterior | Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples to draw from the latent distribution.
Returns:
A tuple of a sample te... | tensorflow_probability/examples/disentangled_vae.py | def sample_static_posterior(self, inputs, samples):
"""Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples to draw from the late... | def sample_static_posterior(self, inputs, samples):
"""Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples to draw from the late... | [
"Sample",
"the",
"static",
"latent",
"posterior",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L868-L885 | [
"def",
"sample_static_posterior",
"(",
"self",
",",
"inputs",
",",
"samples",
")",
":",
"dist",
"=",
"self",
".",
"static_encoder",
"(",
"inputs",
")",
"sample",
"=",
"dist",
".",
"sample",
"(",
"samples",
")",
"return",
"sample",
",",
"dist"
] | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.sample_dynamic_prior | Sample the dynamic latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
length: Number of timesteps to sample for each sequence.
fixed: Boolean for whether or not to share the same random
sample across all se... | tensorflow_probability/examples/disentangled_vae.py | def sample_dynamic_prior(self, samples, batch_size, length, fixed=False):
"""Sample the dynamic latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
length: Number of timesteps to sample for each sequence.
fixed:... | def sample_dynamic_prior(self, samples, batch_size, length, fixed=False):
"""Sample the dynamic latent prior.
Args:
samples: Number of samples to draw from the latent distribution.
batch_size: Number of sequences to sample.
length: Number of timesteps to sample for each sequence.
fixed:... | [
"Sample",
"the",
"dynamic",
"latent",
"prior",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L887-L927 | [
"def",
"sample_dynamic_prior",
"(",
"self",
",",
"samples",
",",
"batch_size",
",",
"length",
",",
"fixed",
"=",
"False",
")",
":",
"if",
"fixed",
":",
"sample_batch_size",
"=",
"1",
"else",
":",
"sample_batch_size",
"=",
"batch_size",
"sample",
",",
"state"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | DisentangledSequentialVAE.sample_dynamic_posterior | Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples to draw from the latent distribution.
static_sample: A tensor sample of th... | tensorflow_probability/examples/disentangled_vae.py | def sample_dynamic_posterior(self, inputs, samples, static_sample=None):
"""Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples ... | def sample_dynamic_posterior(self, inputs, samples, static_sample=None):
"""Sample the static latent posterior.
Args:
inputs: A batch of intermediate representations of image frames
across all timesteps, of shape [..., batch_size, timesteps,
hidden_size].
samples: Number of samples ... | [
"Sample",
"the",
"static",
"latent",
"posterior",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L929-L962 | [
"def",
"sample_dynamic_posterior",
"(",
"self",
",",
"inputs",
",",
"samples",
",",
"static_sample",
"=",
"None",
")",
":",
"if",
"self",
".",
"latent_posterior",
"==",
"\"factorized\"",
":",
"dist",
"=",
"self",
".",
"dynamic_encoder",
"(",
"inputs",
")",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries.batch_shape | Static batch shape of models represented by this component.
Returns:
batch_shape: A `tf.TensorShape` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_space_model(...).batch_shape`. It may ... | tensorflow_probability/python/sts/structural_time_series.py | def batch_shape(self):
"""Static batch shape of models represented by this component.
Returns:
batch_shape: A `tf.TensorShape` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_space_mo... | def batch_shape(self):
"""Static batch shape of models represented by this component.
Returns:
batch_shape: A `tf.TensorShape` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_space_mo... | [
"Static",
"batch",
"shape",
"of",
"models",
"represented",
"by",
"this",
"component",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L80-L94 | [
"def",
"batch_shape",
"(",
"self",
")",
":",
"batch_shape",
"=",
"tf",
".",
"TensorShape",
"(",
"[",
"]",
")",
"for",
"param",
"in",
"self",
".",
"parameters",
":",
"batch_shape",
"=",
"tf",
".",
"broadcast_static_shape",
"(",
"batch_shape",
",",
"param",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries.batch_shape_tensor | Runtime batch shape of models represented by this component.
Returns:
batch_shape: `int` `Tensor` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_space_model(...).batch_shape_tensor()`. | tensorflow_probability/python/sts/structural_time_series.py | def batch_shape_tensor(self):
"""Runtime batch shape of models represented by this component.
Returns:
batch_shape: `int` `Tensor` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_spac... | def batch_shape_tensor(self):
"""Runtime batch shape of models represented by this component.
Returns:
batch_shape: `int` `Tensor` giving the broadcast batch shape of
all model parameters. This should match the batch shape of
derived state space models, i.e.,
`self.make_state_spac... | [
"Runtime",
"batch",
"shape",
"of",
"models",
"represented",
"by",
"this",
"component",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L96-L109 | [
"def",
"batch_shape_tensor",
"(",
"self",
")",
":",
"batch_shape",
"=",
"tf",
".",
"constant",
"(",
"[",
"]",
",",
"dtype",
"=",
"tf",
".",
"int32",
")",
"for",
"param",
"in",
"self",
".",
"parameters",
":",
"batch_shape",
"=",
"tf",
".",
"broadcast_dy... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries._canonicalize_param_vals_as_map | If given an ordered list of parameter values, build a name:value map.
This is a utility method that allows parameter values to be specified as
either lists or dicts, by transforming lists to a canonical dict
representation.
Args:
param_vals: Python list (or other `iterable`) of `Tensor` values
... | tensorflow_probability/python/sts/structural_time_series.py | def _canonicalize_param_vals_as_map(self, param_vals):
"""If given an ordered list of parameter values, build a name:value map.
This is a utility method that allows parameter values to be specified as
either lists or dicts, by transforming lists to a canonical dict
representation.
Args:
para... | def _canonicalize_param_vals_as_map(self, param_vals):
"""If given an ordered list of parameter values, build a name:value map.
This is a utility method that allows parameter values to be specified as
either lists or dicts, by transforming lists to a canonical dict
representation.
Args:
para... | [
"If",
"given",
"an",
"ordered",
"list",
"of",
"parameter",
"values",
"build",
"a",
"name",
":",
"value",
"map",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L111-L132 | [
"def",
"_canonicalize_param_vals_as_map",
"(",
"self",
",",
"param_vals",
")",
":",
"if",
"hasattr",
"(",
"param_vals",
",",
"'keys'",
")",
":",
"param_map",
"=",
"param_vals",
"else",
":",
"param_map",
"=",
"{",
"p",
".",
"name",
":",
"v",
"for",
"(",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries.make_state_space_model | Instantiate this model as a Distribution over specified `num_timesteps`.
Args:
num_timesteps: Python `int` number of timesteps to model.
param_vals: a list of `Tensor` parameter values in order corresponding to
`self.parameters`, or a dict mapping from parameter names to values.
initial_s... | tensorflow_probability/python/sts/structural_time_series.py | def make_state_space_model(self,
num_timesteps,
param_vals=None,
initial_state_prior=None,
initial_step=0):
"""Instantiate this model as a Distribution over specified `num_timesteps`.
Args:
... | def make_state_space_model(self,
num_timesteps,
param_vals=None,
initial_state_prior=None,
initial_step=0):
"""Instantiate this model as a Distribution over specified `num_timesteps`.
Args:
... | [
"Instantiate",
"this",
"model",
"as",
"a",
"Distribution",
"over",
"specified",
"num_timesteps",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L134-L159 | [
"def",
"make_state_space_model",
"(",
"self",
",",
"num_timesteps",
",",
"param_vals",
"=",
"None",
",",
"initial_state_prior",
"=",
"None",
",",
"initial_step",
"=",
"0",
")",
":",
"return",
"self",
".",
"_make_state_space_model",
"(",
"num_timesteps",
"=",
"nu... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries.prior_sample | Sample from the joint prior over model parameters and trajectories.
Args:
num_timesteps: Scalar `int` `Tensor` number of timesteps to model.
initial_step: Optional scalar `int` `Tensor` specifying the starting
timestep.
Default value: 0.
params_sample_shape: Number of possible w... | tensorflow_probability/python/sts/structural_time_series.py | def prior_sample(self,
num_timesteps,
initial_step=0,
params_sample_shape=(),
trajectories_sample_shape=(),
seed=None):
"""Sample from the joint prior over model parameters and trajectories.
Args:
num_timesteps... | def prior_sample(self,
num_timesteps,
initial_step=0,
params_sample_shape=(),
trajectories_sample_shape=(),
seed=None):
"""Sample from the joint prior over model parameters and trajectories.
Args:
num_timesteps... | [
"Sample",
"from",
"the",
"joint",
"prior",
"over",
"model",
"parameters",
"and",
"trajectories",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L161-L209 | [
"def",
"prior_sample",
"(",
"self",
",",
"num_timesteps",
",",
"initial_step",
"=",
"0",
",",
"params_sample_shape",
"=",
"(",
")",
",",
"trajectories_sample_shape",
"=",
"(",
")",
",",
"seed",
"=",
"None",
")",
":",
"seed",
"=",
"distributions",
".",
"See... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | StructuralTimeSeries.joint_log_prob | Build the joint density `log p(params) + log p(y|params)` as a callable.
Args:
observed_time_series: Observed `Tensor` trajectories of shape
`sample_shape + batch_shape + [num_timesteps, 1]` (the trailing
`1` dimension is optional if `num_timesteps > 1`), where
`batch_shape` should ma... | tensorflow_probability/python/sts/structural_time_series.py | def joint_log_prob(self, observed_time_series):
"""Build the joint density `log p(params) + log p(y|params)` as a callable.
Args:
observed_time_series: Observed `Tensor` trajectories of shape
`sample_shape + batch_shape + [num_timesteps, 1]` (the trailing
`1` dimension is optional if `num... | def joint_log_prob(self, observed_time_series):
"""Build the joint density `log p(params) + log p(y|params)` as a callable.
Args:
observed_time_series: Observed `Tensor` trajectories of shape
`sample_shape + batch_shape + [num_timesteps, 1]` (the trailing
`1` dimension is optional if `num... | [
"Build",
"the",
"joint",
"density",
"log",
"p",
"(",
"params",
")",
"+",
"log",
"p",
"(",
"y|params",
")",
"as",
"a",
"callable",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/sts/structural_time_series.py#L211-L272 | [
"def",
"joint_log_prob",
"(",
"self",
",",
"observed_time_series",
")",
":",
"with",
"tf",
".",
"compat",
".",
"v1",
".",
"name_scope",
"(",
"'joint_log_prob'",
",",
"values",
"=",
"[",
"observed_time_series",
"]",
")",
":",
"[",
"observed_time_series",
",",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _compute_min_event_ndims | Computes the min_event_ndims associated with the give list of bijectors.
Given a list `bijector_list` of bijectors, compute the min_event_ndims that is
associated with the composition of bijectors in that list.
min_event_ndims is the # of right most dimensions for which the bijector has
done necessary computa... | tensorflow_probability/python/bijectors/chain.py | def _compute_min_event_ndims(bijector_list, compute_forward=True):
"""Computes the min_event_ndims associated with the give list of bijectors.
Given a list `bijector_list` of bijectors, compute the min_event_ndims that is
associated with the composition of bijectors in that list.
min_event_ndims is the # of r... | def _compute_min_event_ndims(bijector_list, compute_forward=True):
"""Computes the min_event_ndims associated with the give list of bijectors.
Given a list `bijector_list` of bijectors, compute the min_event_ndims that is
associated with the composition of bijectors in that list.
min_event_ndims is the # of r... | [
"Computes",
"the",
"min_event_ndims",
"associated",
"with",
"the",
"give",
"list",
"of",
"bijectors",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/bijectors/chain.py#L40-L109 | [
"def",
"_compute_min_event_ndims",
"(",
"bijector_list",
",",
"compute_forward",
"=",
"True",
")",
":",
"min_event_ndims",
"=",
"0",
"# This is a mouthful, but what this encapsulates is that if not for rank",
"# changing bijectors, we'd only need to compute the largest of the min",
"# ... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | vector_size_to_square_matrix_size | Convert a vector size to a matrix size. | tensorflow_probability/python/bijectors/fill_triangular.py | def vector_size_to_square_matrix_size(d, validate_args, name=None):
"""Convert a vector size to a matrix size."""
if isinstance(d, (float, int, np.generic, np.ndarray)):
n = (-1 + np.sqrt(1 + 8 * d)) / 2.
if float(int(n)) != n:
raise ValueError("Vector length is not a triangular number.")
return i... | def vector_size_to_square_matrix_size(d, validate_args, name=None):
"""Convert a vector size to a matrix size."""
if isinstance(d, (float, int, np.generic, np.ndarray)):
n = (-1 + np.sqrt(1 + 8 * d)) / 2.
if float(int(n)) != n:
raise ValueError("Vector length is not a triangular number.")
return i... | [
"Convert",
"a",
"vector",
"size",
"to",
"a",
"matrix",
"size",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/bijectors/fill_triangular.py#L135-L153 | [
"def",
"vector_size_to_square_matrix_size",
"(",
"d",
",",
"validate_args",
",",
"name",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"d",
",",
"(",
"float",
",",
"int",
",",
"np",
".",
"generic",
",",
"np",
".",
"ndarray",
")",
")",
":",
"n",
"="... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _argsort | Numpy implementation of `tf.argsort`. | tensorflow_probability/python/internal/backend/numpy/misc.py | def _argsort(values, axis=-1, direction='ASCENDING', stable=False, name=None): # pylint: disable=unused-argument
"""Numpy implementation of `tf.argsort`."""
if direction == 'ASCENDING':
pass
elif direction == 'DESCENDING':
values = np.negative(values)
else:
raise ValueError('Unrecognized direction:... | def _argsort(values, axis=-1, direction='ASCENDING', stable=False, name=None): # pylint: disable=unused-argument
"""Numpy implementation of `tf.argsort`."""
if direction == 'ASCENDING':
pass
elif direction == 'DESCENDING':
values = np.negative(values)
else:
raise ValueError('Unrecognized direction:... | [
"Numpy",
"implementation",
"of",
"tf",
".",
"argsort",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/backend/numpy/misc.py#L49-L57 | [
"def",
"_argsort",
"(",
"values",
",",
"axis",
"=",
"-",
"1",
",",
"direction",
"=",
"'ASCENDING'",
",",
"stable",
"=",
"False",
",",
"name",
"=",
"None",
")",
":",
"# pylint: disable=unused-argument",
"if",
"direction",
"==",
"'ASCENDING'",
":",
"pass",
"... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _sort | Numpy implementation of `tf.sort`. | tensorflow_probability/python/internal/backend/numpy/misc.py | def _sort(values, axis=-1, direction='ASCENDING', stable=False, name=None): # pylint: disable=unused-argument
"""Numpy implementation of `tf.sort`."""
if direction == 'ASCENDING':
pass
elif direction == 'DESCENDING':
values = np.negative(values)
else:
raise ValueError('Unrecognized direction: {}.'.... | def _sort(values, axis=-1, direction='ASCENDING', stable=False, name=None): # pylint: disable=unused-argument
"""Numpy implementation of `tf.sort`."""
if direction == 'ASCENDING':
pass
elif direction == 'DESCENDING':
values = np.negative(values)
else:
raise ValueError('Unrecognized direction: {}.'.... | [
"Numpy",
"implementation",
"of",
"tf",
".",
"sort",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/backend/numpy/misc.py#L60-L71 | [
"def",
"_sort",
"(",
"values",
",",
"axis",
"=",
"-",
"1",
",",
"direction",
"=",
"'ASCENDING'",
",",
"stable",
"=",
"False",
",",
"name",
"=",
"None",
")",
":",
"# pylint: disable=unused-argument",
"if",
"direction",
"==",
"'ASCENDING'",
":",
"pass",
"eli... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _kl_gumbel_gumbel | Calculate the batched KL divergence KL(a || b) with a and b Gumbel.
Args:
a: instance of a Gumbel distribution object.
b: instance of a Gumbel distribution object.
name: (optional) Name to use for created operations.
default is "kl_gumbel_gumbel".
Returns:
Batchwise KL(a || b) | tensorflow_probability/python/distributions/gumbel.py | def _kl_gumbel_gumbel(a, b, name=None):
"""Calculate the batched KL divergence KL(a || b) with a and b Gumbel.
Args:
a: instance of a Gumbel distribution object.
b: instance of a Gumbel distribution object.
name: (optional) Name to use for created operations.
default is "kl_gumbel_gumbel".
Ret... | def _kl_gumbel_gumbel(a, b, name=None):
"""Calculate the batched KL divergence KL(a || b) with a and b Gumbel.
Args:
a: instance of a Gumbel distribution object.
b: instance of a Gumbel distribution object.
name: (optional) Name to use for created operations.
default is "kl_gumbel_gumbel".
Ret... | [
"Calculate",
"the",
"batched",
"KL",
"divergence",
"KL",
"(",
"a",
"||",
"b",
")",
"with",
"a",
"and",
"b",
"Gumbel",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/gumbel.py#L201-L224 | [
"def",
"_kl_gumbel_gumbel",
"(",
"a",
",",
"b",
",",
"name",
"=",
"None",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
"or",
"\"kl_gumbel_gumbel\"",
")",
":",
"# Consistent with",
"# http://www.mast.queensu.ca/~communications/Papers/gil-msc11.pdf, page 64",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | ndtr | Normal distribution function.
Returns the area under the Gaussian probability density function, integrated
from minus infinity to x:
```
1 / x
ndtr(x) = ---------- | exp(-0.5 t**2) dt
sqrt(2 pi) /-inf
= 0.5 (1 + erf(x / sqrt(2)))
... | tensorflow_probability/python/internal/special_math.py | def ndtr(x, name="ndtr"):
"""Normal distribution function.
Returns the area under the Gaussian probability density function, integrated
from minus infinity to x:
```
1 / x
ndtr(x) = ---------- | exp(-0.5 t**2) dt
sqrt(2 pi) /-inf
= 0.5 (1 + e... | def ndtr(x, name="ndtr"):
"""Normal distribution function.
Returns the area under the Gaussian probability density function, integrated
from minus infinity to x:
```
1 / x
ndtr(x) = ---------- | exp(-0.5 t**2) dt
sqrt(2 pi) /-inf
= 0.5 (1 + e... | [
"Normal",
"distribution",
"function",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/special_math.py#L110-L142 | [
"def",
"ndtr",
"(",
"x",
",",
"name",
"=",
"\"ndtr\"",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
")",
":",
"x",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"value",
"=",
"x",
",",
"name",
"=",
"\"x\"",
")",
"if",
"dtype_util",
".",
"a... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _ndtr | Implements ndtr core logic. | tensorflow_probability/python/internal/special_math.py | def _ndtr(x):
"""Implements ndtr core logic."""
half_sqrt_2 = tf.constant(
0.5 * np.sqrt(2.), dtype=x.dtype, name="half_sqrt_2")
w = x * half_sqrt_2
z = tf.abs(w)
y = tf.where(
tf.less(z, half_sqrt_2), 1. + tf.math.erf(w),
tf.where(tf.greater(w, 0.), 2. - tf.math.erfc(z), tf.math.erfc(z)))
... | def _ndtr(x):
"""Implements ndtr core logic."""
half_sqrt_2 = tf.constant(
0.5 * np.sqrt(2.), dtype=x.dtype, name="half_sqrt_2")
w = x * half_sqrt_2
z = tf.abs(w)
y = tf.where(
tf.less(z, half_sqrt_2), 1. + tf.math.erf(w),
tf.where(tf.greater(w, 0.), 2. - tf.math.erfc(z), tf.math.erfc(z)))
... | [
"Implements",
"ndtr",
"core",
"logic",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/special_math.py#L145-L154 | [
"def",
"_ndtr",
"(",
"x",
")",
":",
"half_sqrt_2",
"=",
"tf",
".",
"constant",
"(",
"0.5",
"*",
"np",
".",
"sqrt",
"(",
"2.",
")",
",",
"dtype",
"=",
"x",
".",
"dtype",
",",
"name",
"=",
"\"half_sqrt_2\"",
")",
"w",
"=",
"x",
"*",
"half_sqrt_2",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | ndtri | The inverse of the CDF of the Normal distribution function.
Returns x such that the area under the pdf from minus infinity to x is equal
to p.
A piece-wise rational approximation is done for the function.
This is a port of the implementation in netlib.
Args:
p: `Tensor` of type `float32`, `float64`.
... | tensorflow_probability/python/internal/special_math.py | def ndtri(p, name="ndtri"):
"""The inverse of the CDF of the Normal distribution function.
Returns x such that the area under the pdf from minus infinity to x is equal
to p.
A piece-wise rational approximation is done for the function.
This is a port of the implementation in netlib.
Args:
p: `Tensor`... | def ndtri(p, name="ndtri"):
"""The inverse of the CDF of the Normal distribution function.
Returns x such that the area under the pdf from minus infinity to x is equal
to p.
A piece-wise rational approximation is done for the function.
This is a port of the implementation in netlib.
Args:
p: `Tensor`... | [
"The",
"inverse",
"of",
"the",
"CDF",
"of",
"the",
"Normal",
"distribution",
"function",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/special_math.py#L157-L183 | [
"def",
"ndtri",
"(",
"p",
",",
"name",
"=",
"\"ndtri\"",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"name",
")",
":",
"p",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"value",
"=",
"p",
",",
"name",
"=",
"\"p\"",
")",
"if",
"dtype_util",
".",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | _ndtri | Implements ndtri core logic. | tensorflow_probability/python/internal/special_math.py | def _ndtri(p):
"""Implements ndtri core logic."""
# Constants used in piece-wise rational approximations. Taken from the cephes
# library:
# https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html
p0 = list(reversed([-5.99633501014107895267E1,
9.80010754185999661536E1,
... | def _ndtri(p):
"""Implements ndtri core logic."""
# Constants used in piece-wise rational approximations. Taken from the cephes
# library:
# https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html
p0 = list(reversed([-5.99633501014107895267E1,
9.80010754185999661536E1,
... | [
"Implements",
"ndtri",
"core",
"logic",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/special_math.py#L186-L288 | [
"def",
"_ndtri",
"(",
"p",
")",
":",
"# Constants used in piece-wise rational approximations. Taken from the cephes",
"# library:",
"# https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html",
"p0",
"=",
"list",
"(",
"reversed",
"(",
"[",
"-",
"5.99633501014107895267E1",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
test | log_ndtr | Log Normal distribution function.
For details of the Normal distribution function see `ndtr`.
This function calculates `(log o ndtr)(x)` by either calling `log(ndtr(x))` or
using an asymptotic series. Specifically:
- For `x > upper_segment`, use the approximation `-ndtr(-x)` based on
`log(1-x) ~= -x, x <<... | tensorflow_probability/python/internal/special_math.py | def log_ndtr(x, series_order=3, name="log_ndtr"):
"""Log Normal distribution function.
For details of the Normal distribution function see `ndtr`.
This function calculates `(log o ndtr)(x)` by either calling `log(ndtr(x))` or
using an asymptotic series. Specifically:
- For `x > upper_segment`, use the appro... | def log_ndtr(x, series_order=3, name="log_ndtr"):
"""Log Normal distribution function.
For details of the Normal distribution function see `ndtr`.
This function calculates `(log o ndtr)(x)` by either calling `log(ndtr(x))` or
using an asymptotic series. Specifically:
- For `x > upper_segment`, use the appro... | [
"Log",
"Normal",
"distribution",
"function",
"."
] | tensorflow/probability | python | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/internal/special_math.py#L291-L380 | [
"def",
"log_ndtr",
"(",
"x",
",",
"series_order",
"=",
"3",
",",
"name",
"=",
"\"log_ndtr\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"series_order",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"\"series_order must be a Python integer.\"",
")",
"if",
... | e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.