Skip to content

Commit

Permalink
added scalar to log transform
Browse files Browse the repository at this point in the history
  • Loading branch information
grantbuster committed Jun 20, 2024
1 parent bf052ab commit 594549e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions phygnn/layers/custom_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,23 +960,28 @@ def call(self, x):
class LogTransform(tf.keras.layers.Layer):
"""Log transform or inverse transform of data
``y = log(x + adder)`` or ``y = exp(x) - adder`` for inverse
``y = log(x + adder) * scalar`` or
``y = exp(x / scalar) - adder`` for the inverse
"""

def __init__(self, name=None, adder=0, inverse=False):
def __init__(self, name=None, adder=0, scalar=1, inverse=False):
"""
Parameters
----------
name : str | None
Name of the tensorflow layer
adder : float
Adder for ``y = log(x + adder)``
Adder term for ``y = log(x + adder) * scalar``
scalar : float
Scalar term for ``y = log(x + adder) * scalar``
inverse : bool
Option to perform the inverse operation e.g. ``y = exp(x) - adder``
Option to perform the inverse operation e.g.
``y = exp(x / scalar) - adder``
"""

super().__init__(name=name)
self.adder = adder
self.scalar = scalar
self.inverse = inverse
self.rank = None

Expand All @@ -1001,9 +1006,9 @@ def call(self, x):
Returns
-------
y : tf.Tensor
Output ``y = log(x + adder)`` or ``y = exp(x) - adder`` if inverse
Log-transformed x tensor
"""
if not self.inverse:
return tf.math.log(x + self.adder)
return tf.math.log(x + self.adder) * self.scalar
else:
return tf.math.exp(x) - self.adder
return tf.math.exp(x / self.scalar) - self.adder

0 comments on commit 594549e

Please sign in to comment.