mastrof / Bactos.jl

Agent-based modeling framework for bacterial behavior, based on Agents.jl
MIT License
3 stars 0 forks source link

Default turn angle distribution #12

Closed mastrof closed 1 year ago

mastrof commented 1 year ago

Default turn angle distributions for RunTumble should be modified such that, in D-dimensions, rotations are uniform on the D-sphere. At the moment, this is not true for D=3. In 3 dimensions, the two angles should be sampled as $\theta=2\pi u$ and $\phi=\arccos(2v-1)$ with $u,v\sim\text{Uniform}[0,1]$ The default constructor should define $\phi$ differently based on microbe dimensionality.

The arccos distribution will be defined by a custom distribution type

mastrof commented 1 year ago

Code to define this new distribution is here

struct Arccos{T<:Real} <: ContinuousUnivariateDistribution
    a::T # lower limit
    b::T # upper limit
    Arccos{T}(a::T,b::T) where {T} = new{T}(a::T, b::T)
end

function Arccos(a::Real, b::Real; check_args::Bool=true)
    Distributions.@check_args Arccos a≤b -1≤a≤1 -1≤b≤1
    return Arccos{Float64}(Float64(a),Float64(b))
end # function

Arccos() = Arccos(-1,1)

function Base.rand(rng::AbstractRNG, d::Arccos)
    d₁ = Uniform(d.a, d.b)
    return acos(rand(rng, d₁))
end # function

Will be implement asap