統計解析R たぶんpart3くらい (587レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
298: デフォルトの名無しさん [] 2019/09/13(金) 20:17:09.23 ID:wTJZs2gr(1/4) AAS
## Configuration over Configuration
$$
\require{TeX/extpfeil}\require{TeX/AMScd}
\newcommand{\eqtag}[1]{\tag{#1}\label{#1}}
\newcommand{\isa}[1]{\mathinner{\left[\!\left[{#1}\right]\!\right]}}
\DeclareMathOperator{\bbR}{\mathbb{R}}
\DeclareMathOperator{\ecdf}{\mathtt{ecdf}}
\DeclareMathOperator{\ebdf}{\mathtt{ebdf}}
\DeclareMathOperator{\relu}{\mathtt{relu}}
\DeclareMathOperator{\lure}{\mathtt{lure}}
$$
``` {r}
big_data = list ( size = length , add = rlist::list.append , test = testthat::test_that
, lty_none = 0 , lty_line = 1 , lty_dash = 2 , lty_dot = 3);
prelu = function (...) pmax (..., 0);
plure = function (...) pmin (..., 0);
```
続く
299: デフォルトの名無しさん [] 2019/09/13(金) 20:17:51.16 ID:wTJZs2gr(2/4) AAS
## Convex on Rails
多分、[村人の定理](https://en.wikipedia.org/wiki/Mathematical_folklore)
同値な関数達
``` {r}
ebdf_0 = function (xi) {
n = length (xi); qi = cumsum (sort (xi));
function (x) { purrr::reduce (.init = 0, .x = 1 : n, .f = function (out, j) {
pmax (out, j * x - qi [j]); }) / n; }; }; ebdf_1 = function (xi) {
n = length (xi); function (x) {
purrr::reduce (.init = 0, .x = xi, .f = function (out, xi) {
out + prelu (x - xi); }) / n; }; }; ebdf_huge = function (xi) {
n = length (xi); function (x) {
purrr::reduce (.init = 0, .x = 1 : n, .f = function (out, j) {
purrr::reduce (.init = out, .x = combn (1 : n, j, simplify = F), function (out, js) { pmax (out, j * x - sum (xi [js])); }); }) / n; }; };
ebdf_2 = function (xi) { n = length (xi); xi = sort (xi); qi = cumsum (xi);
function (x) { purrr::reduce (.init = n * x - qi [n], .x = n : 1, .f = function (out, j) {
out - plure ((out + qi [j]) / j - xi [j]); }) / n; }; };
dog_data = with (big_data, {
equal = testthat::expect_equal; xi = c (- 1, 0, 2, 3); test ('ebdf', {
doit = function (xi) { bdf_0 = ebdf_0 (xi); bdf_1 = ebdf_1 (xi);
bdf_2 = ebdf_2 (xi); bdf_huge = ebdf_huge (xi);
x = seq (min (xi) - 1, max (xi) + 1, len = 1e+3);
equal (bdf_0 (x), bdf_1 (x)); equal (bdf_0 (x), bdf_2 (x));
if (size (xi) < 5) { equal (bdf_0 (x), bdf_huge (x)); } }; doit (xi);
n = 10; doit (c (rnorm (n, - 1, 1), rnorm (n, 1, 2))); });
add (big_data, xi = xi, equal = equal); });
```
続く
300: デフォルトの名無しさん [] 2019/09/13(金) 20:18:38.86 ID:wTJZs2gr(3/4) AAS
Rの関数`ecdf`は次のように定義されている。 $$ \begin{split}
\ecdf(x) &:= \ecdf_\xi(x) := \frac{1}{n} \sum_{j=1}^n \isa{x \ge \xi_j}, \\
\isa{\operatorname{expr}} &:= \begin{cases}
1, & \text{ iff } \operatorname{expr} = \mathtt{true}, \\
0, & \text{ otherwise}. \end{cases} \end{split} \eqtag{eq:ecdf}
$$ ここで、$\xi_1<\cdots<\xi_n\in\bbR$を観測された値とする。
これを次のように積分したものを$\ebdf$と書くことにする。
$$ \ebdf(x) := \ebdf_\xi(x) := \int_{y=-\infty}^x \ecdf(x)
= \frac{1}{n} \sum_{j=1}^n \relu(x - \xi_j). \eqtag{eq:ebdf} $$
`ebdf_1`はこの式を、`ebdf_0, ebdf_huge, ebdf_2`は式変形したものを実装している。
``` {r}
with (dog_data, {
plot (ecdf (xi)); x = seq (min (xi) - 1, max (xi) + 1, len = 1e+3);
bdf = ebdf_2 (xi); plot (x, bdf (x), type = 'l', main = 'ebdf');
points (xi, bdf (xi)); lines (x, prelu (x - mean (xi)), lty = lty_dash); });
```
コードを見ると、`ebdf_2`は、
[ReLU](https://en.wikipedia.org/wiki/Rectifier_(neural_networks))を
[活性化関数](https://en.wikipedia.org/wiki/Activation_function)とする
[ResNet](https://en.wikipedia.org/wiki/Residual_neural_network)に
なっていることがわかる。さらに、`ebdf_2`を微分すると、ReLUとシグモイドが
混在したResNetになる。
``` {r}
ecdf_2 = function (xi) { n = length (xi); xi = sort (xi);
qi = cumsum (xi); function (x) {
purrr::reduce (.init = cbind (n * x - qi [n], n), .x = n : 1, .f = function (out, j) { f = out [, 1]; d_f = out [, 2]; g = (f + qi [j]) / j - xi [j];
cbind (f - plure (g), d_f - (g < 0)); }) / n; }; };
```
続く
301: デフォルトの名無しさん [] 2019/09/13(金) 20:19:21.78 ID:wTJZs2gr(4/4) AAS
``` {r}
with (dog_data, { test ('resnet-cdf', { doit = function (xi) {
cdf = ecdf (xi); cdf_2 = ecdf_2 (xi); x = seq (min (xi) - 1, max (xi) + 1, len = 1e+3);
equal (cdf (x), cdf_2 (x) [, 2]); };
doit (xi); n = 10; doit (c (rnorm (n, - 1, 1), rnorm (n, 1, 2))); }); });
```
何が嬉しいのかはさておき、$\eqref{eq:ecdf}$がResNetで書けたことになる。
おしまい
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 1.291s*