|
177 | 177 | return ll
|
178 | 178 | end
|
179 | 179 |
|
180 |
| -## --- Biquadratic distribution (like bilinear, with quadratic sides) |
181 |
| - |
182 |
| - |
183 |
| - struct BiquadraticExponential{T<:Real} |
184 |
| - A::T |
185 |
| - μ::T |
186 |
| - σ::T |
187 |
| - shp::T |
188 |
| - skw::T |
189 |
| - end |
190 |
| - function BiquadraticExponential(p::AbstractVector) |
191 |
| - @assert length(p) == 5 |
192 |
| - @assert all(x->x>0, Iterators.drop(p,1)) |
193 |
| - BiquadraticExponential(p...) |
194 |
| - end |
195 |
| - |
196 |
| - function biquadratic_exponential(x::Number, p::AbstractVector{<:Number}) |
197 |
| - @assert length(p) == 5 |
198 |
| - _, μ, σ, shp, skw = (abs(x) for x in p) |
199 |
| - xs = (x - μ)/σ # X scaled by mean and variance |
200 |
| - v = 1/2 - atan(xs)/3.141592653589793 # Sigmoid (positive on LHS) |
201 |
| - return exp(first(p) -0.5*(shp*skw*xs*v - shp/skw*xs*(1-v))^2) |
202 |
| - end |
203 |
| - function biquadratic_exponential(x::AbstractVector, p::AbstractVector{<:Number}) |
204 |
| - @assert length(p) == 5 |
205 |
| - _, μ, σ, shp, skw = (abs(x) for x in p) |
206 |
| - result = Array{float(eltype(x))}(undef,size(x)) |
207 |
| - @inbounds for i ∈ eachindex(x) |
208 |
| - xs = (x[i] - μ)/σ # X scaled by mean and variance |
209 |
| - v = 1/2 - atan(xs)/3.141592653589793 # Sigmoid (positive on LHS) |
210 |
| - result[i] = exp(first(p) -0.5*(shp*skw*xs*v - shp/skw*xs*(1-v))^2) |
211 |
| - end |
212 |
| - return result |
213 |
| - end |
214 |
| - |
215 |
| - function biquadratic_exponential_ll(x::Number, p::AbstractVector{<:Number}) |
216 |
| - xs = (x - p[2])/abs(p[3]) # X scaled by mean and variance |
217 |
| - v = 1/2 - atan(xs)/3.141592653589793 # Sigmoid (positive on LHS) |
218 |
| - shp = abs(p[4]) |
219 |
| - skw = abs(p[5]) |
220 |
| - return -(shp*skw*xs*v - shp/skw*xs*(1-v))^2 |
221 |
| - end |
222 |
| - function biquadratic_exponential_ll(x::AbstractVector, ages::AbstractVector{BiquadraticExponential{T}}) where T |
223 |
| - ll = zero(T) |
224 |
| - @inbounds for i ∈ eachindex(x,ages) |
225 |
| - pᵢ = ages[i] |
226 |
| - xs = (x[i]-pᵢ.μ)/(pᵢ.σ) # X scaled by mean and variance |
227 |
| - v = 1/2 - atan(xs)/3.141592653589793 # Sigmoid (positive on LHS) |
228 |
| - shp = pᵢ.shp |
229 |
| - skw = pᵢ.skw |
230 |
| - ll -= (shp*skw*xs*v - shp/skw*xs*(1-v))^2 |
231 |
| - end |
232 |
| - return ll |
233 |
| - end |
234 |
| - |
235 | 180 | ## --- End of File
|
0 commit comments