Skip to content

Commit

Permalink
Bugfixes in normal and gaussian, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmaostc committed Sep 17, 2021
1 parent d5dde0e commit ea7524e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ gaussian
normal([T=Float64], size::NTuple{N, Int};
offset=CtrFT,
sigma=1.0,
dims=ntuple(+, N),
scale=ScaUnit,
weight=1,
accumulator=sum)
Expand All @@ -643,7 +642,6 @@ For a version with normalized to the maximum, see `gaussian`.
* `sigma`: the (standard deviation) width of the Gaussian
* `offset`: the center position of the Gaussian. You can use a tuple or the indicators `CtrCorner`, `CtrEnd`, `CtrFT`, `CtrRFT` etc.
* `scale`: the scale of the pixel. By default `ScaUnit` is assumed
* `dims`: the dimensions over which to apply this function to.
* `weight`: the strength of the result. Supports list-mode (see rr2 for documentation)
* `accumulator`: the method used for superimposing list-mode data. Only applies in list-mode
```jldoctest
Expand Down Expand Up @@ -960,7 +958,8 @@ A multidimensional (separable) window with a transition according to a decaying
By default the standard deviation `sigma` of the Gaussian is adjusted such that the `2 sigma` level is reached at `border_out`.
However, this window is not clipped at the outer border, thus allowing the sigma to be adjusted by placing `border_out` closer to `border_in`.
See `?window_linear` for more details on the arguments.
```jldoctest
```jldoctest
julia> w1 = window_gaussian((9,9), border_in=(0.3,0.3), border_out=(0.6,1))
9×9 IndexFunArray{Float64, 2, IndexFunArrays.var"#286#288"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}, Tuple{Float64, Float64}, Tuple{Float64, Int64}}}:
0.000109245 0.000259904 0.000413188 0.000449917 0.000449917 0.000449917 0.000413188 0.000259904 0.000109245
Expand All @@ -974,8 +973,9 @@ julia> w1 = window_gaussian((9,9), border_in=(0.3,0.3), border_out=(0.6,1))
0.000109245 0.000259904 0.000413188 0.000449917 0.000449917 0.000449917 0.000413188 0.000259904 0.000109245
```
---
window_gaussian(arr::AbstractArray;
offset=CtrFT, scale=ScaFTEdge, border_in=0.8, border_out=1.0, dims=ntuple(+, N))
window_gaussian(arr::AbstractArray;
offset=CtrFT, scale=ScaFTEdge, border_in=0.8, border_out=1.0, dims=ntuple(+, N))
This is a wrapper for
`window_gaussian(eltype(arr), size(arr), scaling=scaling, offset=offset, border_in=border_in, border_out=border_out)`.
Expand Down
2 changes: 1 addition & 1 deletion src/other_ifas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function normal(::Type{T}, size::NTuple{N, Int}; sigma=1.0, offset=CtrFT, scale=
end

function normal(sz::NTuple{N, Int}; sigma=1.0, offset=CtrFT, scale=ScaUnit, dims=ntuple(+, N), accumulator=sum, weight=1) where {N}
myscale = apply_tuple_list((x,y)-> DEFAULT_T.(x ./( 2 .*y.*y)), get_scale(size, scale), optional_mat_to_iter(sigma))
myscale = apply_tuple_list((x,y)-> DEFAULT_T.(x ./( 2 .*y.*y)), get_scale(sz, scale), optional_mat_to_iter(sigma))
return exp_sqr_norm(DEFAULT_T, sz, scale = myscale, offset=offset, dims = dims, accumulator=accumulator, weight=weight)
end

Expand Down
16 changes: 16 additions & 0 deletions test/other_ifas.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

@testset "normal distribution, integral normed to 1" begin
@test 1 / (2π)^2 / 1 * exp.(.- rr2((5,5)) / 2 .* 1^2) normal((5,5))
@test 1 / (2π)^2 / 1 * exp.(.- rr2((8,5)) / 2 .* 1^2) normal((8,5))
@test 1 / (2π)^2 / 1 * exp.(.- rr2((8,5)) / 2 .* 1^2) normal(zeros(8,5))
@test eltype(normal(Float32, (8,5))) === Float32
end



@testset "Gaussian function, normed to 1" begin
arr = 1 / (2π)^2 / 1 * exp.(.- rr2((5,5)) / 2 .* 1^2)
arr ./= maximum(arr)
@test arr gaussian((5,5))
@test eltype(gaussian(Float32, (8,5))) === Float32
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using BenchmarkTools
BenchmarkTools.DEFAULT_PARAMETERS.samples = 2
BenchmarkTools.DEFAULT_PARAMETERS.evals = 2

include("other_ifas.jl")
include("test_center_scaling.jl")
include("constructors.jl")
include("concrete_generators.jl")
Expand Down

0 comments on commit ea7524e

Please sign in to comment.