Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Created March 1, 2013 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasjansson/5065742 to your computer and use it in GitHub Desktop.
Save andreasjansson/5065742 to your computer and use it in GitHub Desktop.
def scaled_tanh(x, depth):
# scale [0, 255] to [-depth, depth]
x = x / (128.0 / depth) - depth
# apply tanh, scale now [-tanh(depth), tanh(depth)]
x = math.tanh(x)
# scale up again to [0, 255]
x = (x + math.tanh(depth)) * 128 / math.tanh(depth)
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment