reduce_group_ndims

tfsnippet.reduce_group_ndims(operation, tensor, group_ndims, name=None)

Reduce the last group_ndims dimensions in tensor, using operation.

In Distribution, when computing the (log-)densities of certain tensor, the last few dimensions may represent a group of events, thus should be accounted together. This method can be used to reduce these dimensions, for example:

log_prob = reduce_group_ndims(tf.reduce_sum, log_prob, group_ndims)
prob = reduce_group_ndims(tf.reduce_prod, log_prob, group_ndims)
Parameters:
  • operation – The operation for reducing the last group_ndims dimensions. It must receive tensor as the 1st argument, and axis as the 2nd argument.
  • tensor – The tensor to be reduced.
  • group_ndims – The number of dimensions at the end of tensor to be reduced. If it is a constant integer and is zero, then no operation will take place.
  • name – TensorFlow name scope of the graph nodes. (default “reduce_group_ndims”)
Returns:

The reduced tensor.

Return type:

tf.Tensor

Raises:

ValueError – If group_ndims cannot be validated by validate_group_ndims().