Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert clamp changes from aeee627 (destabilized training) #252

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
15 changes: 7 additions & 8 deletions bayesflow/networks/coupling_flow/transforms/affine_transform.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import math

import keras.ops as ops
from keras.saving import register_keras_serializable as serializable

from bayesflow.types import Tensor
from bayesflow.utils.keras_utils import shifted_softplus
from .transform import Transform


@serializable(package="networks.coupling_flow")
class AffineTransform(Transform):
def __init__(self, clamp: float | None = 1.9, **kwargs):
def __init__(self, clamp: bool = True, **kwargs):
super().__init__(**kwargs)
self.clamp = clamp

Expand All @@ -25,12 +24,12 @@ def split_parameters(self, parameters: Tensor) -> dict[str, Tensor]:
def constrain_parameters(self, parameters: dict[str, Tensor]) -> dict[str, Tensor]:
scale = parameters["scale"]

# soft clamp
if self.clamp is not None:
(2.0 * self.clamp / math.pi) * ops.arctan(scale / self.clamp)

# constrain to positive values
scale = ops.exp(scale)
scale = shifted_softplus(scale)

# soft clamp
if self.clamp:
scale = ops.arcsinh(scale)

parameters["scale"] = scale
return parameters
Expand Down
Loading