Skip to content

Commit

Permalink
updates to blending, remove dataframes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed Aug 22, 2021
1 parent f0cfede commit 3ca11f0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name = "ACTRModels"
uuid = "c095b0ea-a6ca-5cbd-afed-dbab2e976880"
authors = ["itsdfish"]
version = "0.8.0"
version = "0.8.1"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -20,7 +19,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
ConcreteStructs = "v0.2.0"
DataFrames = "0.22.0, 1.0"
Distributions = "^0.22.0, 0.23, 0.24, 0.25"
Parameters = "^0.12.0"
PrettyTables = "1.1.0"
Expand Down
66 changes: 61 additions & 5 deletions src/MemoryFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,25 @@ function get_parm(actr, p)
return getfield(actr.parms, p)
end

"""
blend_chunks(actr; request...)
Computes blended value over chunks given a retrieval request. By default,
values are blended over the set of slots formed by the set difference between all
slots of a chunk and the slots specified in the retrieval request. The default time used
in activation calculations is taken from `get_time`. Currently, blended
is only supported for numeric slot-values.
# Arguments
- `actr::AbstractACTR`: an `ACTR` model object
- `request...`: optional keywords for the retrieval request
"""
function blend_chunks(actr; request...)
t = get_time(actr)
return blend_chunks(actr, t; request...)
end

"""
blend_chunks(actr, cur_time::Float64=0.0; request...)
Expand All @@ -926,15 +945,52 @@ is only supported for numeric slot-values.
# Arguments
- `actr`: an `ACTR` model object
- `cur_time::Float64=0.0`: current simulated time
- `actr::AbstractACTR`: an `ACTR` model object
- `cur_time::Float64`: current simulated time
- `request...`: optional keywords for the retrieval request
"""
function blend_chunks(actr, cur_time::Float64=0.0; request...)
function blend_chunks(actr::AbstractACTR, cur_time::Float64; request...)
blended_slots = setdiff(keys(actr.declarative.memory[1].slots), keys(request))
return blend_chunks(actr, blended_slots, cur_time; request...)
end

"""
blend_chunks(actr; request...)
Computes blended value over chunks given a retrieval request. By default,
values are blended over the set of slots formed by the set difference between all
slots of a chunk and the slots specified in the retrieval request. The default time used
in activation calculations is taken from `get_time`. Currently, blended
is only supported for numeric slot-values.
# Arguments
- `actr::AbstractACTR`: an `ACTR` model object
- `request...`: optional keywords for the retrieval request
"""
function blend_chunks(actr::AbstractACTR; request...)
return blend_chunks(actr, get_time(actr); request...)
end

"""
blend_chunks(actr; request...)
Computes blended value over chunks given a retrieval request. By default,
values are blended over the set of slots formed by the set difference between all
slots of a chunk and the slots specified in the retrieval request. The default time used
in activation calculations is taken from `get_time(actr`). Currently, blended
is only supported for numeric slot-values.
# Arguments
- `actr::AbstractACTR`: an `ACTR` model object
- `blended_slots`: a set of slots over which slot-values are blended
- `request...`: optional keywords for the retrieval request
"""
function blend_chunks(actr::AbstractACTR, blended_slots; request...)
return blend_chunks(actr, blended_slots, get_time(actr); request...)
end

"""
blend_chunks(actr, cur_time::Float64=0.0; request...)
Expand All @@ -946,10 +1002,10 @@ for numeric slot-values.
- `actr`: an `ACTR` model object
- `blended_slots`: a set of slots over which slot-values are blended
- `cur_time::Float64=0.0`: current simulated time
- `cur_time`: current simulated time
- `request...`: optional keywords for the retrieval request
"""
function blend_chunks(actr, blended_slots, cur_time=0.0; request...)
function blend_chunks(actr, blended_slots, cur_time; request...)
chunks = retrieval_request(actr; request...)
compute_activation!(actr, chunks, cur_time; request...)
probs = soft_max(actr, chunks)
Expand Down
9 changes: 7 additions & 2 deletions src/Structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ function Imaginal(;buffer=Chunk[], ω=1.0, denoms=Int64[])
Imaginal(buffer, state, ω, denoms)
end


Imaginal(chunk::Chunk, state, ω, denoms) = Imaginal([chunk], state, ω, denoms)
Imaginal(T::DataType, state, ω, denoms) = Imaginal(T(undef,1), state, ω, denoms)

Expand Down Expand Up @@ -584,6 +583,12 @@ function Motor(T::DataType, state, mouse_position)
Motor(T(undef,1), state, mouse_position)
end

mutable struct Scheduler
time::Float64
end

Scheduler(;time=0.0) = Scheduler(time)

abstract type AbstractACTR end

"""
Expand Down Expand Up @@ -626,7 +631,7 @@ end
Broadcast.broadcastable(x::ACTR) = Ref(x)

function ACTR(;declarative=Declarative(), imaginal=Imaginal(),
goal = Goal(), scheduler=nothing, visual=nothing, visual_location=nothing,
goal = Goal(), scheduler=Scheduler(), visual=nothing, visual_location=nothing,
procedural=nothing, motor=nothing, visicon=init_visicon(), parms...)
parms′ = Parms(;parms...)
ACTR(declarative, imaginal, visual, visual_location, goal, procedural, motor, visicon, parms′, scheduler)
Expand Down
5 changes: 1 addition & 4 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,12 @@ function get_mean_activations(chunks::Vector{<:Chunk})
end

get_time(actr::AbstractACTR) = get_time(actr.scheduler)
get_time(scheduler::Float64) = scheduler
get_time(scheduler) = scheduler.time

add_time(actr::AbstractACTR, t) = add_time(actr.scheduler, t)
add_time(scheduler::Float64, t) = scheduler += t
add_time(scheduler) = scheduler.time += t
add_time(scheduler, t) = scheduler.time += t

reset_time!(actr::AbstractACTR) = reset_time!(actr.scheduler)
reset_time!(scheduler::Float64) = scheduler = 0.0
reset_time!(scheduler) = scheduler.time = 0.0

rnd_time(μ) = rand(Uniform* (2/3), μ * (4/3)))

0 comments on commit 3ca11f0

Please sign in to comment.