Losses: keras_proba.losses¶
Negative log-likelihoods for the probabilistic regression heads.
Loss classes¶
GaussianNLL ¶
Bases: keras.src.losses.loss.Loss
Gaussian negative log-likelihood loss for GaussianHead outputs.
Example:
model = keras.Sequential([keras.Input((8,)), keras.layers.Dense(64, "relu"), GaussianHead(1)])
model.compile(optimizer="adam", loss=GaussianNLL())
__doc__
class-attribute
¶
__doc__ = 'Gaussian negative log-likelihood loss for `GaussianHead` outputs.\n\n Example:\n\n ```python\n model = keras.Sequential([keras.Input((8,)), keras.layers.Dense(64, "relu"), GaussianHead(1)])\n model.compile(optimizer="adam", loss=GaussianNLL())\n ```\n '
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
MixtureGaussianNLL ¶
MixtureGaussianNLL(units=None, name='mixture_gaussian_nll', reduction='sum_over_batch_size', dtype=None)
Bases: keras.src.losses.loss.Loss
Negative log-likelihood loss for MixtureGaussianHead outputs.
Example:
model = keras.Sequential([
keras.Input((1,)),
keras.layers.Dense(64, activation="relu"),
MixtureGaussianHead(num_components=5),
])
model.compile(optimizer="adam", loss=MixtureGaussianNLL())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
Number of regression targets. Inferred from the targets if
|
None
|
|
name
|
Name of the loss. |
'mixture_gaussian_nll'
|
|
reduction
|
Keras loss reduction. |
'sum_over_batch_size'
|
|
dtype
|
Dtype of the loss computation. |
None
|
__doc__
class-attribute
¶
__doc__ = 'Negative log-likelihood loss for `MixtureGaussianHead` outputs.\n\n Example:\n\n ```python\n model = keras.Sequential([\n keras.Input((1,)),\n keras.layers.Dense(64, activation="relu"),\n MixtureGaussianHead(num_components=5),\n ])\n model.compile(optimizer="adam", loss=MixtureGaussianNLL())\n ```\n\n Args:\n units: Number of regression targets. Inferred from the targets if\n `None`; set it when targets of shape `(batch, units)` could be\n confused with `(batch,)` targets for `units=1`.\n name: Name of the loss.\n reduction: Keras loss reduction.\n dtype: Dtype of the loss computation.\n '
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
Functions¶
gaussian_nll ¶
Gaussian negative log-likelihood of y_true under a GaussianHead output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Targets of shape |
required | |
y_pred
|
|
required |
Returns:
| Type | Description |
|---|---|
|
Negative log-likelihood averaged over the last axis, shape |
mixture_gaussian_nll ¶
Negative log-likelihood of y_true under a MixtureGaussianHead output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Targets of shape |
required | |
y_pred
|
|
required | |
units
|
Number of regression targets. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
|
Negative log-likelihood of the joint |
|
|
|
|
|
as for |