Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-scatter
Commits
2a3dca8e
Commit
2a3dca8e
authored
Nov 28, 2018
by
rusty1s
Browse files
numerical stability
parent
3e409bf4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
2 deletions
+4
-2
torch_scatter/std.py
torch_scatter/std.py
+4
-2
No files found.
torch_scatter/std.py
View file @
2a3dca8e
...
...
@@ -6,14 +6,16 @@ from torch_scatter.utils.gen import gen
def
scatter_std
(
src
,
index
,
dim
=-
1
,
out
=
None
,
dim_size
=
None
,
unbiased
=
True
):
src
,
out
,
index
,
dim
=
gen
(
src
,
index
,
dim
,
out
,
dim_size
,
fill_value
=
0
)
print
(
'src'
,
src
.
mean
())
tmp
=
scatter_add
(
src
,
index
,
dim
,
None
,
dim_size
)
count
=
scatter_add
(
torch
.
ones_like
(
src
),
index
,
dim
,
None
,
dim_size
)
mean
=
tmp
/
count
.
clamp
(
min
=
1
)
var
=
(
src
-
mean
.
gather
(
dim
,
index
))
**
2
var
=
(
src
-
mean
.
gather
(
dim
,
index
))
var
=
var
*
var
out
=
scatter_add
(
var
,
index
,
dim
,
out
,
dim_size
)
out
=
out
/
(
count
-
1
if
unbiased
else
count
).
clamp
(
min
=
1
)
out
=
torch
.
sqrt
(
out
)
out
=
torch
.
sqrt
(
out
.
clamp
(
min
=
1e-12
)
)
return
out
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