The Categorical distribution is parameterized by either probabilities or log-probabilities of a set of K classes. It is defined over the integers {0, 1, ..., K-1}.

tfd_categorical(logits = NULL, probs = NULL, dtype = tf$int32,
  validate_args = FALSE, allow_nan_stats = TRUE,
  name = "Categorical")

Arguments

logits

An N-D Tensor, N >= 1, representing the log probabilities of a set of Categorical distributions. The first N - 1 dimensions index into a batch of independent distributions and the last dimension represents a vector of logits for each class. Only one of logits or probs should be passed in.

probs

An N-D Tensor, N >= 1, representing the probabilities of a set of Categorical distributions. The first N - 1 dimensions index into a batch of independent distributions and the last dimension represents a vector of probabilities for each class. Only one of logits or probs should be passed in.

dtype

The type of the event samples (default: int32).

validate_args

Logical, default FALSE. When TRUE distribution parameters are checked for validity despite possibly degrading runtime performance. When FALSE invalid inputs may silently render incorrect outputs. Default value: FALSE.

allow_nan_stats

Logical, default TRUE. When TRUE, statistics (e.g., mean, mode, variance) use the value NaN to indicate the result is undefined. When FALSE, an exception is raised if one or more of the statistic's batch members are undefined.

name

name prefixed to Ops created by this class.

Value

a distribution instance.

Details

The Categorical distribution is closely related to the OneHotCategorical and Multinomial distributions. The Categorical distribution can be intuited as generating samples according to argmax{ OneHotCategorical(probs) } itself being identical to argmax{ Multinomial(probs, total_count=1) }.

Mathematical Details

The probability mass function (pmf) is,

pmf(k; pi) = prod_j pi_j**[k == j]

Pitfalls

The number of classes, K, must not exceed:

  • the largest integer representable by self$dtype, i.e., 2**(mantissa_bits+1) (IEEE 754),

  • the maximum Tensor index, i.e., 2**31-1.

Note: This condition is validated only when validate_args = TRUE.

See also

For usage examples see e.g. tfd_sample(), tfd_log_prob(), tfd_mean().

Other distributions: tfd_autoregressive, tfd_batch_reshape, tfd_bernoulli, tfd_beta, tfd_binomial, tfd_cauchy, tfd_chi2, tfd_chi, tfd_cholesky_lkj, tfd_deterministic, tfd_dirichlet_multinomial, tfd_dirichlet, tfd_empirical, tfd_exponential, tfd_gamma_gamma, tfd_gamma, tfd_gaussian_process_regression_model, tfd_gaussian_process, tfd_geometric, tfd_gumbel, tfd_half_cauchy, tfd_half_normal, tfd_hidden_markov_model, tfd_horseshoe, tfd_independent, tfd_inverse_gamma, tfd_inverse_gaussian, tfd_joint_distribution_named, tfd_joint_distribution_sequential, tfd_kumaraswamy, tfd_laplace, tfd_linear_gaussian_state_space_model, tfd_lkj, tfd_log_normal, tfd_logistic, tfd_mixture_same_family, tfd_mixture, tfd_multinomial, tfd_multivariate_normal_diag_plus_low_rank, tfd_multivariate_normal_diag, tfd_multivariate_normal_full_covariance, tfd_multivariate_normal_linear_operator, tfd_multivariate_normal_tri_l, tfd_multivariate_student_t_linear_operator, tfd_negative_binomial, tfd_normal, tfd_one_hot_categorical, tfd_pareto, tfd_pixel_cnn, tfd_poisson_log_normal_quadrature_compound, tfd_poisson, tfd_probit_bernoulli, tfd_quantized, tfd_relaxed_bernoulli, tfd_relaxed_one_hot_categorical, tfd_sample_distribution, tfd_sinh_arcsinh, tfd_student_t_process, tfd_student_t, tfd_transformed_distribution, tfd_triangular, tfd_truncated_normal, tfd_uniform, tfd_variational_gaussian_process, tfd_vector_diffeomixture, tfd_vector_exponential_diag, tfd_vector_exponential_linear_operator, tfd_vector_laplace_diag, tfd_vector_laplace_linear_operator, tfd_vector_sinh_arcsinh_diag, tfd_von_mises_fisher, tfd_von_mises, tfd_wishart_linear_operator, tfd_wishart_tri_l, tfd_wishart, tfd_zipf