|
1 | 1 |
|
2 | 2 | """
|
3 |
| - normalise(x; dims=ndims(x), ϵ=1e-5) |
| 3 | + normalise(x; dims=ndims(x), eps=1e-5) |
4 | 4 |
|
5 | 5 | Normalise `x` to mean 0 and standard deviation 1 across the dimension(s) given by `dims`.
|
6 | 6 | Per default, `dims` is the last dimension.
|
7 |
| -`ϵ` is a small additive factor added to the denominator for numerical stability. |
| 7 | +`eps` is a small term added to the denominator for numerical stability. |
8 | 8 |
|
9 | 9 | # Examples
|
10 | 10 | ```jldoctest
|
11 | 11 | julia> using Statistics
|
12 | 12 |
|
13 |
| -julia> x = [9, 10, 20, 60]; |
| 13 | +julia> x = [90, 100, 110, 130, 70]; |
14 | 14 |
|
15 |
| -julia> y = Flux.normalise(x); |
| 15 | +julia> mean(x), std(x; corrected=false) |
| 16 | +(100.0, 20.0) |
16 | 17 |
|
17 |
| -julia> isapprox(std(y), 1, atol=0.2) && std(y) != std(x) |
| 18 | +julia> y = Flux.normalise(x) |
| 19 | +5-element Vector{Float64}: |
| 20 | + -0.49999975000012503 |
| 21 | + 0.0 |
| 22 | + 0.49999975000012503 |
| 23 | + 1.499999250000375 |
| 24 | + -1.499999250000375 |
| 25 | +
|
| 26 | +julia> isapprox(std(y; corrected=false), 1, atol=1e-5) |
18 | 27 | true
|
19 | 28 |
|
20 |
| -julia> x = rand(1:100, 10, 2); |
| 29 | +julia> x = rand(10:100, 10, 10); |
21 | 30 |
|
22 | 31 | julia> y = Flux.normalise(x, dims=1);
|
23 | 32 |
|
24 |
| -julia> isapprox(std(y, dims=1), ones(1, 2), atol=0.2) && std(y, dims=1) != std(x, dims=1) |
| 33 | +julia> isapprox(std(y; dims=1, corrected=false), ones(1, 10), atol=1e-5) |
25 | 34 | true
|
26 | 35 | ```
|
27 | 36 | """
|
28 |
| -@inline function normalise(x::AbstractArray; dims=ndims(x), ϵ=ofeltype(x, 1e-5)) |
| 37 | +@inline function normalise(x::AbstractArray; dims=ndims(x), eps=ofeltype(x, 1e-5), ϵ=nothing) |
| 38 | + ε = _greek_ascii_depwarn(ϵ => eps, :InstanceNorm, "ϵ" => "eps") |
29 | 39 | μ = mean(x, dims=dims)
|
30 | 40 | σ = std(x, dims=dims, mean=μ, corrected=false)
|
31 |
| - return @. (x - μ) / (σ + ϵ) |
| 41 | + return @. (x - μ) / (σ + ε) |
32 | 42 | end
|
33 | 43 |
|
34 | 44 | """
|
|
0 commit comments