Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions trieste/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,20 @@ def one_hot_encoder(self) -> EncoderFunction:

def binary_encoder(x: TensorType) -> TensorType:
# no need to one-hot encode binary categories (but we should still validate)
tf.debugging.Assert(tf.reduce_all((x == 0) | (x == 1)), [tf.constant([])])
tf.debugging.Assert(
tf.reduce_all((x == 0) | (x == 1)),
["Invalid binary values for one-hot encoding:", x],
)
return x

def encoder(x: TensorType) -> TensorType:
flat_x, unflatten = flatten_leading_dims(x)
tf.debugging.assert_equal(flat_x.shape[-1], len(self.tags))
tf.debugging.assert_equal(
flat_x.shape[-1],
len(self.tags),
message="Invalid input for one-hot encoding: "
f"expected {len(self.tags)} tags, got {flat_x.shape[-1]}",
)
columns = tf.split(flat_x, flat_x.shape[-1], axis=1)
encoders = [
(
Expand Down
Loading