gpflow.utilities.ops#
Functions#
gpflow.utilities.ops.broadcasting_elementwise#
- gpflow.utilities.ops.broadcasting_elementwise(op, a, b)[source]#
Apply binary operation op to every pair in tensors a and b.
- Parameters
op (
Callable
[[Tensor
,Tensor
],Tensor
]) – binary operator on tensors, e.g. tf.add, tf.substracta (
Tensor
) – tf.Tensor, shape [n_1, …, n_a]b (
Tensor
) – tf.Tensor, shape [m_1, …, m_b]
- Return type
Tensor
- Returns
tf.Tensor, shape [n_1, …, n_a, m_1, …, m_b]
gpflow.utilities.ops.cast#
gpflow.utilities.ops.difference_matrix#
- gpflow.utilities.ops.difference_matrix(X, X2)[source]#
Returns (X - X2ᵀ)
This function can deal with leading dimensions in X and X2. For example, If X has shape [M, D] and X2 has shape [N, D], the output will have shape [M, N, D]. If X has shape [I, J, M, D] and X2 has shape [K, L, N, D], the output will have shape [I, J, M, K, L, N, D].
- Parameters
X (
Tensor
) –X2 (
Optional
[Tensor
]) –
- Return type
Tensor
gpflow.utilities.ops.eye#
gpflow.utilities.ops.leading_transpose#
- gpflow.utilities.ops.leading_transpose(tensor, perm, leading_dim=0)[source]#
Transposes tensors with leading dimensions.
Leading dimensions in permutation list represented via ellipsis … and is of type List[Union[int, type(…)] (please note, due to mypy issues, List[Any] is used instead). When leading dimensions are found, transpose method considers them as a single grouped element indexed by 0 in perm list. So, passing perm=[-2, …, -1], you assume that your input tensor has […, A, B] shape, and you want to move leading dims between A and B dimensions. Dimension indices in permutation list can be negative or positive. Valid positive indices start from 1 up to the tensor rank, viewing leading dimensions … as zero index.
Example:
a = tf.random.normal((1, 2, 3, 4, 5, 6)) # [..., A, B, C], # where A is 1st element, # B is 2nd element and # C is 3rd element in # permutation list, # leading dimensions are [1, 2, 3] # which are 0th element in permutation list b = leading_transpose(a, [3, -3, ..., -2]) # [C, A, ..., B] sess.run(b).shape output> (6, 4, 1, 2, 3, 5)
- Parameters
tensor (
Tensor
) – TensorFlow tensor.perm (
List
[Any
]) – List of permutation indices.leading_dim (
int
) –
- Return type
Tensor
- Returns
TensorFlow tensor.
- Raises
ValueError – when … cannot be found.
gpflow.utilities.ops.pca_reduce#
- gpflow.utilities.ops.pca_reduce(X, latent_dim)[source]#
A helpful function for linearly reducing the dimensionality of the input points X to latent_dim dimensions.
- Parameters
X (
Tensor
) – data array of size N (number of points) x D (dimensions)latent_dim (
Tensor
) – Number of latent dimensions Q < D
- Return type
Tensor
- Returns
PCA projection array of size [N, Q].
gpflow.utilities.ops.square_distance#
- gpflow.utilities.ops.square_distance(X, X2)[source]#
Returns ||X - X2ᵀ||² Due to the implementation and floating-point imprecision, the result may actually be very slightly negative for entries very close to each other.
This function can deal with leading dimensions in X and X2. In the sample case, where X and X2 are both 2 dimensional, for example, X is [N, D] and X2 is [M, D], then a tensor of shape [N, M] is returned. If X is [N1, S1, D] and X2 is [N2, S2, D] then the output will be [N1, S1, N2, S2].
- Parameters
X (
Tensor
) –X2 (
Optional
[Tensor
]) –
- Return type
Tensor