/
SoftPlus.jl
38 lines (28 loc) · 967 Bytes
/
SoftPlus.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export SoftPlus
"""
`SoftPlus([domainType=Float64::Type,] dim_in::Tuple)`
Creates the softplus non-linear operator with input dimensions `dim_in`.
```math
\\sigma(\\mathbf{x}) = \\log (1 + e^{x} )
```
"""
struct SoftPlus{T,N} <: NonLinearOperator
dim::NTuple{N,Int}
end
function SoftPlus(DomainType::Type, DomainDim::NTuple{N,Int}) where {N}
SoftPlus{DomainType,N}(DomainDim)
end
SoftPlus(DomainDim::NTuple{N,Int}) where {N} = SoftPlus{Float64,N}(DomainDim)
function mul!(y::AbstractArray{T,N}, L::SoftPlus{T,N}, x::AbstractArray{T,N}) where {T,N}
y .= log.(1 .+exp.(x))
end
function mul!(y::AbstractArray,
J::AdjointOperator{Jacobian{A,TT}},
b::AbstractArray) where {T, N, A <: SoftPlus{T,N}, TT <: AbstractArray{T,N} }
L = J.A
y .= 1 ./(1 .+exp.(-L.x)).*b
end
fun_name(L::SoftPlus) = "σ"
size(L::SoftPlus) = (L.dim, L.dim)
domainType(L::SoftPlus{T,N}) where {T,N} = T
codomainType(L::SoftPlus{T,N}) where {T,N} = T