diff --git a/Project.toml b/Project.toml index 069a638..13e02d4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ACTRModels" uuid = "c095b0ea-a6ca-5cbd-afed-dbab2e976880" authors = ["itsdfish"] -version = "0.10.3" +version = "0.10.4" [deps] ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471" diff --git a/src/MemoryFunctions.jl b/src/MemoryFunctions.jl index 3d4c88a..6964708 100644 --- a/src/MemoryFunctions.jl +++ b/src/MemoryFunctions.jl @@ -17,18 +17,19 @@ function baselevel(d, lags) end """ - baselevel(d, chunk) + baselevel!(N, L, k, lags, d) -Computes baselevel activation according exact equation. +Computes baselevel activation with hybrid approximation. # Arguments -- `actr`: an `ACTR` model object -- `chunk`: a chunk +- `N`: the number of times the chunk was used +- `L`: lifetime of chunk in seconds +- `k`: number of timestaps tracked +- `lags`: time since last use for each k +- `d`: decay rate """ -function baselevel!(actr, chunk) - @unpack N,L,k,lags = chunk - d = actr.parms.d +function baselevel!(N, L, k, lags, d) exact = baselevel(d, lags) approx = 0.0 if N > k @@ -37,14 +38,30 @@ function baselevel!(actr, chunk) x2 = (1 - d) * (L - tk) approx = x1 / x2 end - chunk.act_bll = log(exp(exact) + approx) + return log(exp(exact) + approx) +end + +""" + baselevel!(actr, chunk) + +Computes baselevel activation with hybrid approximation. + +# Arguments + +- `actr`: an `ACTR` model object +- `chunk`: a chunk +""" +function baselevel!(actr, chunk) + @unpack N,L,k,lags = chunk + d = actr.parms.d + chunk.act_bll = baselevel!(N, L, k, lags, d) return nothing end """ baselevel!(actr) -Computes baselevel activation for all chunks according exact equation. +Computes baselevel activation with hybrid approximation. # Arguments @@ -286,10 +303,11 @@ Computes the spreading activation for a given chunk - `chunk`: the chunk for which spreading activation is computed """ function spreading_activation!(actr, chunk) + @unpack γ,ω = actr.parms imaginal = actr.imaginal isempty(imaginal.buffer) ? (return nothing) : nothing - w = compute_weights(imaginal) - γ = actr.parms.γ; r = zero(γ); sa = zero(γ) + w = compute_weights(imaginal, ω) + r = zero(γ); sa = zero(γ) slots = imaginal.buffer[1].slots denoms = imaginal.denoms for (v,d) in zip(slots, denoms) @@ -323,8 +341,8 @@ function cache_denomitors(actr) return nothing end -function compute_weights(mod) - return mod.ω / length(mod.buffer[1].slots) +function compute_weights(mod, ω) + return ω / length(mod.buffer[1].slots) end function compute_denom(memory, value) diff --git a/src/Structs.jl b/src/Structs.jl index bb57191..e639508 100644 --- a/src/Structs.jl +++ b/src/Structs.jl @@ -30,8 +30,9 @@ ACT-R parameters with default values. Default values are overwritten with keywor - `τ=0.0`: retrieval threshold - `s=0.2`: logistic scalar for activation noise. - `γ=1.6`: maximum associative strength -- `blc=0.0`: base level constant - `δ=0.0`: mismatch penalty +- `ω=1.0`: weight for source of spreading activation +- `blc=0.0`: base level constant - `ter=0.0`: a constant for encoding and responding time - `mmp_fun`: a mismatch penalty function. By default, `mmp_fun` subtracts `δ` from each non-matching slot value - `sa_fun`: a function for spreading activation which requires arguments for actr and chunk @@ -56,6 +57,7 @@ ACT-R parameters with default values. Default values are overwritten with keywor s γ δ + ω blc ter mmp_fun @@ -81,6 +83,7 @@ function Parms(; s = .3, γ = 0.0, δ = 0.0, + ω = 1.0, blc = 0.0, ter = 0.0, mmp_fun = default_penalty, @@ -106,6 +109,7 @@ function Parms(; s, γ, δ, + ω, blc, ter, mmp_fun, diff --git a/test/benchmarks.jl b/test/benchmarks.jl index 77c238d..329eb67 100644 --- a/test/benchmarks.jl +++ b/test/benchmarks.jl @@ -1,4 +1,3 @@ - using ACTRModels, BenchmarkTools n = 10 parms = (sa=false, mmp=true, γ=1.3, δ=1.0)