Example 1
This example will demonstrate how to create memory chunks, add them to the model, perform a memory retrieval, and compute the retrieval time. Declarative memory will consist of two chunks representing two co-workers and their departments:
\[\mathbf{c}_1 = \{(\mathrm{name,Bob}),(\mathrm{department,accounting}) \} \\ \mathbf{c}_2 = \{(\mathrm{name,Alice}),(\mathrm{department,HR}) \}\]
Load Packages
The first step is to load the required packages. Next, we set a seed for the random number generator.
using ACTRModels
using Random
using Plots
Random.seed!(87545)
Random.TaskLocalRNG()
Create Chunks
we can create a vector of chunks using the Chunk
constructor. Constructor accepts a variable number of keyword arguments as slot-value pairs.
# create chunks of declarative knowledge
chunks =
[Chunk(;name=:Bob, department=:accounting),
Chunk(;name=:Alice, department=:HR)
]
Chunks
┌─────────────────────────────────────────┬───────┬───────┬──────────────┬──────
│ slots │ N │ L │ time_created │ rec ⋯
├─────────────────────────────────────────┼───────┼───────┼──────────────┼──────
│ (name = :Bob, department = :accounting) │ 1.00 │ 1.00 │ 0.00 │ [0. ⋯
│ (name = :Alice, department = :HR) │ 1.00 │ 1.00 │ 0.00 │ [0. ⋯
└─────────────────────────────────────────┴───────┴───────┴──────────────┴──────
8 columns omitted
Create a Model
After creating the chunks, the next step is to pass them to the constructor Declarative
to create a declarative memory object. In the next line, we specify a NamedTuple
of parameters. Finally, the declarative memory object and the parameters are passed to the ACTR
constructor to generate an ACT-R model object.
# initialize declarative memory
declarative = Declarative(memory=chunks)
# specify model parameters: partial matching, noise, mismatch penalty, activation noise
Θ = (mmp=true, noise=true, δ=1.0, s=.20)
# create an ACT-R object with activation noise and partial matching
actr = ACTR(;declarative, Θ...)
ACTR{String, Declarative{Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}, Tuple{Symbol, Symbol}, BufferState}, Imaginal{Chunk, Float64, BufferState}, Nothing, Nothing, Goal{Chunk, BufferState}, Nothing, Nothing, Dict{String, VisualObject}, Parms{Float64, typeof(ACTRModels.default_dissim_func), typeof(ACTRModels.spreading_activation!), typeof(ACTRModels.utility_match), NamedTuple{(), Tuple{}}}, ACTRModels.Scheduler, Random.TaskLocalRNG}("model1", Declarative{Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}, Tuple{Symbol, Symbol}, BufferState}(Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}[Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}(1, 1.0, 0.0, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, (name = :Bob, department = :accounting), 0, [0.0], Float64[], 0.0), Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}(1, 1.0, 0.0, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, (name = :Alice, department = :HR), 0, [0.0], Float64[], 0.0)], (:isa, :retrieved), Chunk{NamedTuple{(:name, :department), Tuple{Symbol, Symbol}}, Float64}[#undef], BufferState(false, false, true)), Imaginal{Chunk, Float64, BufferState}(Chunk[], BufferState(false, false, true), 1.0, Int64[]), nothing, nothing, Goal{Chunk, BufferState}(Chunk[], BufferState(false, false, true)), nothing, nothing, Dict{String, VisualObject}(), Parms{Float64, typeof(ACTRModels.default_dissim_func), typeof(ACTRModels.spreading_activation!), typeof(ACTRModels.utility_match), NamedTuple{(), Tuple{}}}(0.5, 0.0, 0.2, 0.0, 1.0, 1.0, 0.0, 0.0, ACTRModels.default_dissim_func, ACTRModels.spreading_activation!, ACTRModels.utility_match, 1.0, 0.0, 0.0, 0.2, 1.0, -100.0, -100.0, 1.0, 1.0, 1.0, 1.0, false, true, false, true, false, false, 0.28284271247461906, NamedTuple()), ACTRModels.Scheduler(0.0), Random.TaskLocalRNG())
Retrieve Chunk
To retrieve a chunk, pass the ACT-R model objec to the function retrieve
along with keyword arguments for the retrieval request. retrieve
will return a vector containing a chunk or an empty vector indicating a retrieval failure.
# retrieve a chunk associated with accounting
chunk = retrieve(actr; department=:accounting)
Chunks
┌───────────────────────────────────┬───────┬───────┬──────────────┬────────┬───
│ slots │ N │ L │ time_created │ recent │ ⋯
├───────────────────────────────────┼───────┼───────┼──────────────┼────────┼───
│ (name = :Alice, department = :HR) │ 1.00 │ 1.00 │ 0.00 │ [0.0] │ ⋯
└───────────────────────────────────┴───────┴───────┴──────────────┴────────┴───
7 columns omitted
Compute Retrieval Time
Retrieval time is computed by passing the ACT-R model object and the retried vector to the function compute_RT
. If the vector chunk
is empty, the retrieval failure time will be based on the retrieval threshold, τ
.
rt = compute_RT(actr, chunk)
1.4156841175710067
References
Anderson, J. R., Bothell, D., Byrne, M. D., Douglass, S., Lebiere, C., & Qin, Y. (2004). An integrated theory of the mind. Psychological review, 111(4), 1036.