Commit ef82da8a authored by Victor's avatar Victor
Browse files

updates to include discretespace

parent d4c1e4ec
Pipeline #76099 passed with stage
in 18 minutes and 59 seconds
...@@ -22,7 +22,7 @@ module ABMEv ...@@ -22,7 +22,7 @@ module ABMEv
@reexport using Distributions, DataFrames @reexport using Distributions, DataFrames
export GraphSpace,ContinuousSegment,DiscreteSegment,RealSpace, export GraphSpace,ContinuousSegment,DiscreteSegment,RealSpace,NaturalSpace,
AbstractSpacesTuple,get_inc AbstractSpacesTuple,get_inc
export update_rates! export update_rates!
export AbstractAgent,Agent,get_fitness,get_x,get_t,get_dim, export AbstractAgent,Agent,get_fitness,get_x,get_t,get_dim,
......
...@@ -47,9 +47,11 @@ end ...@@ -47,9 +47,11 @@ end
""" """
$(TYPEDEF) $(TYPEDEF)
A real pace with dimension N and type T A real space with dimension N and type T
""" """
struct RealSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end struct RealSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end
struct NaturalSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end
# TODO: find a way to put a type on D in get_inc # TODO: find a way to put a type on D in get_inc
...@@ -61,6 +63,14 @@ function _get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T<:AbstractFloat,I<:Is ...@@ -61,6 +63,14 @@ function _get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T<:AbstractFloat,I<:Is
end end
end end
function _get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T<:Integer,I<:IsFinite{false}}
if Dim > 1
return Tuple(round.(T,D .*randn(Float32,Dim)))
else
return round(D * randn(Float32))
end
end
""" """
$(SIGNATURES) $(SIGNATURES)
Returns increment corresponding to space `s` Returns increment corresponding to space `s`
......
...@@ -7,6 +7,7 @@ mysegment = DiscreteSegment(1,10) ...@@ -7,6 +7,7 @@ mysegment = DiscreteSegment(1,10)
mygraph = GraphSpace(SimpleGraph(10,10)) mygraph = GraphSpace(SimpleGraph(10,10))
real2d = RealSpace{2,Float64}() real2d = RealSpace{2,Float64}()
myline = RealSpace{1,Float16}() myline = RealSpace{1,Float16}()
mydiscreteline = NaturalSpace{1,Int8}()
mycontinuoussegment = ContinuousSegment(-1.,1.) mycontinuoussegment = ContinuousSegment(-1.,1.)
myspace = (mysegment,mygraph,myline) myspace = (mysegment,mygraph,myline)
myspace2 = (mysegment,mycontinuoussegment,real2d) myspace2 = (mysegment,mycontinuoussegment,real2d)
...@@ -23,8 +24,11 @@ myspace2 = (mysegment,mycontinuoussegment,real2d) ...@@ -23,8 +24,11 @@ myspace2 = (mysegment,mycontinuoussegment,real2d)
# increment on infinite spaces # increment on infinite spaces
@test ABMEv._get_inc(0.,myline) (0.) @test ABMEv._get_inc(0.,myline) (0.)
@test ABMEv._get_inc(0.,mydiscreteline) (0.)
@test !(ABMEv._get_inc(1.,myline) 0.) @test !(ABMEv._get_inc(1.,myline) 0.)
@test !(get_inc(1,1.,myline) 0.) @test !(get_inc(1,1.,myline) 0.)
@test !(get_inc(1,1.,mydiscreteline) 0.)
@test typeof(ABMEv._get_inc([1.,0.],real2d)) == Tuple{Float64,Float64} @test typeof(ABMEv._get_inc([1.,0.],real2d)) == Tuple{Float64,Float64}
@test typeof(get_inc([1.,0.],[1.,0.],real2d)) == Tuple{Float64,Float64} @test typeof(get_inc([1.,0.],[1.,0.],real2d)) == Tuple{Float64,Float64}
......
Markdown is supported
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