Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
1c1b6377
Commit
1c1b6377
authored
Aug 23, 2017
by
Theo Steininger
Browse files
Merge branch 'tweak_limited_exp' into 'master'
Tweak limited exp See merge request !193
parents
41c87296
9f86a5cb
Pipeline
#17226
passed with stages
in 35 minutes and 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/basic_arithmetics.py
View file @
1c1b6377
...
...
@@ -24,7 +24,7 @@ from .field import Field
__all__
=
[
'cos'
,
'sin'
,
'cosh'
,
'sinh'
,
'tan'
,
'tanh'
,
'arccos'
,
'arcsin'
,
'arccosh'
,
'arcsinh'
,
'arctan'
,
'arctanh'
,
'sqrt'
,
'exp'
,
'log'
,
'conjugate'
,
'clipped_exp'
,
'limited_exp'
]
'conjugate'
,
'clipped_exp'
,
'limited_exp'
,
'limited_exp_deriv'
]
def
_math_helper
(
x
,
function
):
...
...
@@ -101,15 +101,28 @@ def clipped_exp(x):
def
limited_exp
(
x
):
thr
=
200
expthr
=
np
.
exp
(
thr
)
return
_math_helper
(
x
,
lambda
z
:
_limited_exp_helper
(
z
,
thr
,
expthr
))
return
_math_helper
(
x
,
_limited_exp_helper
)
def
_limited_exp_helper
(
x
):
thr
=
200.
mask
=
x
>
thr
if
np
.
count_nonzero
(
mask
)
==
0
:
return
np
.
exp
(
x
)
result
=
((
1.
-
thr
)
+
x
)
*
np
.
exp
(
thr
)
result
[
~
mask
]
=
np
.
exp
(
x
[
~
mask
])
return
result
def
_limited_exp_helper
(
x
,
thr
,
expthr
):
mask
=
(
x
>
thr
)
result
=
np
.
exp
(
x
)
result
[
mask
]
=
((
1
-
thr
)
+
x
[
mask
])
*
expthr
def
limited_exp_deriv
(
x
):
return
_math_helper
(
x
,
_limited_exp_deriv_helper
)
def
_limited_exp_deriv_helper
(
x
):
thr
=
200.
mask
=
x
>
thr
if
np
.
count_nonzero
(
mask
)
==
0
:
return
np
.
exp
(
x
)
result
=
np
.
empty_like
(
x
)
result
[
mask
]
=
np
.
exp
(
thr
)
result
[
~
mask
]
=
np
.
exp
(
x
[
~
mask
])
return
result
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment