Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
353075f5
Commit
353075f5
authored
Feb 16, 2021
by
Philipp Frank
Browse files
unitstep
parent
c2d2eb28
Pipeline
#93595
passed with stages
in 11 minutes and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/pointwise.py
View file @
353075f5
...
...
@@ -82,6 +82,14 @@ def _clip_helper(v, a_min, a_max):
tmp2
=
np
.
where
(
tmp
==
a_max
,
0.
,
tmp2
)
return
(
tmp
,
tmp2
)
def
_step_helper
(
v
,
grad
):
if
np
.
issubdtype
(
v
.
dtype
,
np
.
complexfloating
):
raise
TypeError
(
"Argument must not be complex"
)
r
=
np
.
zeros
(
v
.
shape
)
r
[
v
>=
0.
]
=
1.
if
grad
:
return
(
r
,
np
.
zeros
(
v
.
shape
))
return
r
def
softplus
(
v
):
fv
=
np
.
empty
(
v
.
shape
,
dtype
=
np
.
float64
if
np
.
isrealobj
(
v
)
else
np
.
complex128
)
...
...
@@ -144,5 +152,6 @@ ptw_dict = {
"exponentiate"
:
(
exponentiate
,
_exponentiate_helper
),
"arcsin"
:
(
np
.
arcsin
,
lambda
v
:
(
np
.
arcsin
(
v
),
1.
/
np
.
sqrt
(
1.
-
v
**
2
))),
"arccos"
:
(
np
.
arccos
,
lambda
v
:
(
np
.
arccos
(
v
),
-
1.
/
np
.
sqrt
(
1.
-
v
**
2
))),
"arctan"
:
(
np
.
arctan
,
lambda
v
:
(
np
.
arctan
(
v
),
1.
/
(
1.
+
v
**
2
)))
"arctan"
:
(
np
.
arctan
,
lambda
v
:
(
np
.
arctan
(
v
),
1.
/
(
1.
+
v
**
2
))),
"unitstep"
:
(
lambda
v
:
_step_helper
(
v
,
False
),
lambda
v
:
_step_helper
(
v
,
True
))
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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