Commit d536e0d3 authored by rusty1s's avatar rusty1s
Browse files

typo

parent 632a1783
......@@ -28,6 +28,7 @@ The package consists of the following operations:
* [**Scatter Mul**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/mul.html)
* [**Scatter Div**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/div.html)
* [**Scatter Mean**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/mean.html)
* [**Scatter Std**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/std.html)
* [**Scatter Min**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/min.html)
* [**Scatter Max**](https://rusty1s.github.io/pytorch_scatter/build/html/functions/max.html)
......
#!/bin/bash
files=(add sub mul div mean max min)
files=(add sub mul div mean max min std)
for name in "${files[@]}"; do
pdflatex "$name"
......
This diff is collapsed.
\def\indices{{0, 0, 1, 0, 2, 2, 3, 3}}
\def\inputs{{5, 1, 7, 2, 3, 2, 1, 3}}
\def\outputs{{2.1, 0, 0.7, 1.4}}
\def\colors{{"cyan", "orange", "olive", "magenta"}}
\def\numberInputs{7}
\def\numberOutputs{3}
\def\operation{std}
\input{template}
Scatter Std
===========
.. automodule:: torch_scatter
.. autofunction:: scatter_std
......@@ -15,7 +15,7 @@ if CUDA_HOME is not None:
['cuda/scatter.cpp', 'cuda/scatter_kernel.cu'])
]
__version__ = '1.0.5'
__version__ = '1.1.0'
url = 'https://github.com/rusty1s/pytorch_scatter'
install_requires = []
......@@ -36,5 +36,4 @@ setup(
tests_require=tests_require,
ext_modules=ext_modules,
cmdclass=cmdclass,
packages=find_packages(),
)
packages=find_packages(), )
from itertools import product
import pytest
import torch
from torch_scatter import scatter_std
from .utils import grad_dtypes as dtypes, devices, tensor
biass = [True, False]
@pytest.mark.parametrize('dtype,device,bias', product(dtypes, devices, biass))
def test_std(dtype, device, bias):
src = tensor([[2, 0, 1, 4, 3], [0, 2, 1, 3, 4]], dtype, device)
index = tensor([[0, 0, 0, 0, 0], [1, 1, 1, 1, 1]], torch.long, device)
out = scatter_std(src, index, dim=-1, unbiased=bias)
expected = src.std(dim=-1, unbiased=bias)
assert out.tolist() == [[expected[0].item(), 0], [0, expected[0].item()]]
......@@ -7,7 +7,7 @@ from .std import scatter_std
from .max import scatter_max
from .min import scatter_min
__version__ = '1.0.5'
__version__ = '1.1.0'
__all__ = [
'scatter_add',
......
......@@ -13,7 +13,7 @@ def scatter_add(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
Sums all values from the :attr:`src` tensor into :attr:`out` at the indices
specified in the :attr:`index` tensor along an given axis :attr:`dim`. For
specified in the :attr:`index` tensor along a given axis :attr:`dim`. For
each value in :attr:`src`, its output index is specified by its index in
:attr:`input` for dimensions outside of :attr:`dim` and by the
corresponding value in :attr:`index` for dimension :attr:`dim`. If
......
......@@ -39,7 +39,7 @@ def scatter_div(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
|
Divides all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**contributions divide** (`cf.` :meth:`~torch_scatter.scatter_add`).
......
......@@ -42,7 +42,7 @@ def scatter_max(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
Maximizes all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
The second return tensor contains index location in :attr:`src` of each
......
......@@ -15,7 +15,7 @@ def scatter_mean(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
Averages all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**contributions average** (`cf.` :meth:`~torch_scatter.scatter_add`).
......
......@@ -42,7 +42,7 @@ def scatter_min(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
Minimizes all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**contributions maximize** (`cf.` :meth:`~torch_scatter.scatter_add`).
The second return tensor contains index location in :attr:`src` of each
......
......@@ -39,7 +39,7 @@ def scatter_mul(src, index, dim=-1, out=None, dim_size=None, fill_value=1):
|
Multiplies all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**contributions multiply** (`cf.` :meth:`~torch_scatter.scatter_add`).
......
......@@ -5,6 +5,45 @@ from torch_scatter.utils.gen import gen
def scatter_std(src, index, dim=-1, out=None, dim_size=None, unbiased=True):
r"""
|
.. image:: https://raw.githubusercontent.com/rusty1s/pytorch_scatter/
master/docs/source/_figures/std.svg?sanitize=true
:align: center
:width: 400px
|
Computes the standard-deviation from all values from the :attr:`src` tensor
into :attr:`out` at the indices specified in the :attr:`index` tensor along
a given axis :attr:`dim` (`cf.` :meth:`~torch_scatter.scatter_add`).
For one-dimensional tensors, the operation computes
.. math::
\mathrm{out}_i = \sqrt{\frac{\sum_j {\left( x_j - \overline{x}_i
\right)}^2}{N_i - 1}}
where :math:`\sum_j` is over :math:`j` such that
:math:`\mathrm{index}_j = i`. :math:`N_i` and :math:`\overline{x}_i`
indicate the number of indices referencing :math:`i` and their mean value,
respectively.
Args:
src (Tensor): The source tensor.
index (LongTensor): The indices of elements to scatter.
dim (int, optional): The axis along which to index.
(default: :obj:`-1`)
out (Tensor, optional): The destination tensor. (default: :obj:`None`)
dim_size (int, optional): If :attr:`out` is not given, automatically
create output with size :attr:`dim_size` at dimension :attr:`dim`.
If :attr:`dim_size` is not given, a minimal sized output tensor is
returned. (default: :obj:`None`)
unbiased (bool, optional): If set to :obj:`False`, then the standard-
deviation will be calculated via the biased estimator.
(default: :obj:`True`)
"""
src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value=0)
tmp = scatter_add(src, index, dim, None, dim_size)
......@@ -15,6 +54,6 @@ def scatter_std(src, index, dim=-1, out=None, dim_size=None, unbiased=True):
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.clamp(min=1e-12))
out = torch.sqrt(out)
return out
......@@ -13,7 +13,7 @@ def scatter_sub(src, index, dim=-1, out=None, dim_size=None, fill_value=0):
|
Subtracts all values from the :attr:`src` tensor into :attr:`out` at the
indices specified in the :attr:`index` tensor along an given axis
indices specified in the :attr:`index` tensor along a given axis
:attr:`dim`.If multiple indices reference the same location, their
**negated contributions add** (`cf.` :meth:`~torch_scatter.scatter_add`).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment