trieste.models.keras.utils#
Module Contents#
- get_tensor_spec_from_data(dataset: trieste.data.Dataset) tuple[tensorflow.TensorSpec, tensorflow.TensorSpec][source]#
Extract tensor specifications for inputs and outputs of neural network models, based on the dataset. This utility faciliates constructing neural networks, providing the required dimensions for the input and the output of the network. For example
>>> data = Dataset( ... tf.constant([[0.1, 0.2], [0.3, 0.4]]), ... tf.constant([[0.5], [0.7]]) ... ) >>> input_spec, output_spec = get_tensor_spec_from_data(data) >>> input_spec TensorSpec(shape=(2,), dtype=tf.float32, name='query_points') >>> output_spec TensorSpec(shape=(1,), dtype=tf.float32, name='observations')
- Parameters:
dataset – A dataset with
query_pointsandobservationstensors.- Returns:
Tensor specification objects for the
query_pointsandobservationstensors.- Raises:
ValueError – If the dataset is not an instance of
Dataset.
- sample_with_replacement(dataset: trieste.data.Dataset) trieste.data.Dataset[source]#
Create a new
datasetwith data sampled with replacement. This function is useful for creating bootstrap samples of data for training ensembles.- Parameters:
dataset – The data that should be sampled.
- Returns:
A (new)
datasetwith sampled data.- Raises:
ValueError (or InvalidArgumentError) – If the dataset is not an instance of
Datasetor it is empty.
- sample_model_index(size: trieste.types.TensorType, num_samples: trieste.types.TensorType, seed: int | None = None) trieste.types.TensorType[source]#
Returns samples of indices of individual models in the ensemble.
If
num_samplesis smaller or equal tosize(i.e. the ensemble size) indices are sampled without replacement. Whennum_samplesis larger thansizethen untilsizeis reached we sample without replacement, while after that we sample with replacement. The rationale of this mixed scheme is that typically one wants to exhaust all networks and then resample them only if required.- Parameters:
size – The maximum index, effectively the number of models in the ensemble.
num_samples – The number of samples to take.
seed – Optional RNG seed.
- Returns:
A tensor with indices.
- negative_log_likelihood(y_true: trieste.types.TensorType, y_pred: tensorflow_probability.distributions.Distribution) trieste.types.TensorType[source]#
Maximum likelihood objective function for training neural networks.
- Parameters:
y_true – The output variable values.
y_pred – The output layer of the model. It has to be a probabilistic neural network with a distribution as a final layer.
- Returns:
Negative log likelihood values.