Commit f169e794 authored by Victor's avatar Victor
Browse files

Modified increment for graph, since randomwalk return same vertex as the one...

Modified increment for graph, since randomwalk return same vertex as the one provided when niter = 1
parent fe417f69
using LightGraphs
using Test
using Revise,ABMEv
mysegmentgraph = GraphSpace(grid([10,1]))
mysegment = DiscreteSegment(1,10)
myplot = Plots.plot(grid = false)
for D in [1e-3,1e-2,1e-1,1e0,1e1]
graphinc = [get_inc(5,D,mysegmentgraph) for i in 1:10000]
seginc = [get_inc(5,D,mysegment) for i in 1:10000]
using StatsPlots
StatsPlots.density!(graphinc,label="Dispersal distribution for graph segment")
StatsPlots.density!(seginc,label="Dispersal distribution for regular segment",linestyle=:dash)
......@@ -52,18 +52,20 @@ A real pace with dimension N and type T
struct RealSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end
# TODO: find a way to put a type on D in get_inc
Returns increment
function get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T<:AbstractFloat,I<:IsFinite{false}}
function _get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T<:AbstractFloat,I<:IsFinite{false}}
if Dim > 1
return Tuple(D .* randn(T,Dim))
return D * randn(T)
get_inc(x,D,s::AbstractSpace{Dim,T,I}) where {Dim,T,I<:IsFinite{false}} = get_inc(D,s)
Returns increment corresponding to space `s`
get_inc(x,D,s::AbstractSpace{Dim,T,I}) where {Dim,T,I<:IsFinite{false}} = _get_inc(D,s)
#TODO: there is probably a better way of dealing with those two functions
function get_inc(x,D,s::ContinuousSegment{T}) where {T}
......@@ -77,7 +79,8 @@ function get_inc(x,D,s::DiscreteSegment{T}) where {T}
function get_inc(x,D,s::GraphSpace{T}) where {T}
niter = round(Int,abs(D*randn()))
niter = round(Int,abs(D*randn())) + 1
# here we add +1 since randomwalk(s.g,x,niter) returns x
if niter > 0
return last(randomwalk(s.g,x,niter)) - x
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment