From c45fec98849870fd3251028010ad2b0de88bebab Mon Sep 17 00:00:00 2001 From: itsdfish <9677184+itsdfish@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:51:33 +0000 Subject: [PATCH 1/2] Format .jl files --- docs/make.jl | 12 +++---- src/MemoryFunctions.jl | 27 +++++++------- src/Structs.jl | 73 ++++++++++++++++++-------------------- src/Utilities/Utilities.jl | 8 ++--- test/Memory_Tests.jl | 20 +++++------ test/Utility Tests.jl | 3 +- test/Utility_Functions.jl | 10 +++--- test/Utility_Tests.jl | 3 +- test/memory.jl | 2 +- 9 files changed, 73 insertions(+), 85 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 2d28e3e..8b4fd49 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -8,10 +8,10 @@ makedocs( assets = [ asset( "https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", - class = :css, - ), + class = :css + ) ], - collapselevel = 1, + collapselevel = 1 ), modules = [ACTRModels], pages = [ @@ -19,10 +19,10 @@ makedocs( "examples" => [ "example 1" => "example1.md", "example 2" => "example2.md", - "example 3" => "example3.md", + "example 3" => "example3.md" ], - "api" => "api.md", - ], + "api" => "api.md" + ] ) deploydocs(repo = "github.com/itsdfish/ACTRModels.jl.git") diff --git a/src/MemoryFunctions.jl b/src/MemoryFunctions.jl index 05f13d3..4fada30 100644 --- a/src/MemoryFunctions.jl +++ b/src/MemoryFunctions.jl @@ -86,7 +86,7 @@ Computes the activation of a vector of chunks. By default, current time is compu function compute_activation!( actr::AbstractACTR, chunks::Vector{<:AbstractChunk}; - request..., + request... ) return compute_activation!(actr, chunks, get_time(actr); request...) end @@ -110,7 +110,7 @@ function compute_activation!( actr::AbstractACTR, chunks::Vector{<:AbstractChunk}, cur_time::Float64; - request..., + request... ) (; sa) = actr.parms sa ? cache_denomitors(actr) : nothing @@ -374,7 +374,6 @@ function count_values(chunk, value) return count(x -> x == value, values(chunk.slots)) end - """ update_recent!(actr, chunk) @@ -425,7 +424,7 @@ By default, current time is computed from `get_time`. - `request...`: optional keyword pairs representing a retrieval request """ -function retrieval_prob(actr::AbstractACTR, target::Array{<:AbstractChunk,1}; request...) +function retrieval_prob(actr::AbstractACTR, target::Array{<:AbstractChunk, 1}; request...) return retrieval_prob(actr, target, get_time(actr); request...) end @@ -447,9 +446,9 @@ Retrieval probability is computed with the softmax approximation. """ function retrieval_prob( actr::AbstractACTR, - target::Array{<:AbstractChunk,1}, + target::Array{<:AbstractChunk, 1}, cur_time; - request..., + request... ) (; τ, s, noise) = actr.parms σ = s * sqrt(2) @@ -559,7 +558,7 @@ function retrieval_probs(actr::AbstractACTR, cur_time; request...) set_noise!(actr, false) compute_activation!(actr, chunks, cur_time; request...) set_noise!(actr, noise) - v = Array{typeof(chunks[1].act),1}(undef, length(chunks) + 1) + v = Array{typeof(chunks[1].act), 1}(undef, length(chunks) + 1) map!(x -> exp(x.act_mean / σ), v, chunks) v[end] = exp(τ / σ) p = v ./ sum(v) @@ -663,7 +662,7 @@ function add_chunk!(memory::Declarative, cur_time = 0.0; bl::T = 0.0, slots...) bl, time_created = cur_time, recent = [cur_time], - slots..., + slots... ) push!(memory.memory, c) else @@ -689,7 +688,6 @@ Adds new chunk to declarative memory or updates existing chunk with new use add_chunk!(actr::AbstractACTR, cur_time; slots...) = add_chunk!(actr.declarative, cur_time; slots...) - """ get_chunks_exact(memory::Vector{<:Chunk}; criteria...) @@ -761,7 +759,7 @@ function get_chunks( memory::Vector{<:AbstractChunk}, funs...; check_value = true, - criteria..., + criteria... ) c = filter(x -> _match(x, funs, criteria; check_value), memory) return c @@ -857,7 +855,7 @@ Returns the first chunk in memory that matches a set of criteria - `criteria...`: optional keyword arguments corresponding to critiria for matching chunk """ function first_chunk(memory::Vector{<:AbstractChunk}; check_value = true, criteria...) - chunk = Array{eltype(memory),1}() + chunk = Array{eltype(memory), 1}() for m in memory if _match(m, criteria; check_value) push!(chunk, m) @@ -1123,7 +1121,7 @@ Retrieves a chunk given a retrieval request """ function retrieve(actr::AbstractACTR, cur_time; request...) (; declarative, parms) = actr - arr = Array{eltype(declarative.memory),1}() + arr = Array{eltype(declarative.memory), 1}() chunks = retrieval_request(actr; request...) # add noise to threshold even if result of request is empty actr.parms.noise ? add_noise!(actr) : (parms.τ′ = parms.τ) @@ -1177,7 +1175,6 @@ function compute_RT(actr::AbstractACTR, chunk) return lf * exp(-chunk[1].act) end - """ compute_RT(actr, chunk) @@ -1281,8 +1278,8 @@ Computes an expected value over numerical values. function blend_slots( actr::AbstractACTR, probs, - values::AbstractArray{T}, -)::Float64 where {T<:Number} + values::AbstractArray{T} +)::Float64 where {T <: Number} return probs' * values end diff --git a/src/Structs.jl b/src/Structs.jl index 908c02d..ed566a1 100644 --- a/src/Structs.jl +++ b/src/Structs.jl @@ -60,7 +60,7 @@ ACT-R parameters with default values. Default values are overwritten with keywor - `filtered:` a list of slots that must absolutely match with mismatch penalty. `isa` and `retrieval` are included by default """ -@concrete mutable struct Parms{T<:Real} <: AbstractParms +@concrete mutable struct Parms{T <: Real} <: AbstractParms d::T τ::T s::T @@ -123,9 +123,8 @@ function Parms(; mmp_utility = false, utility_noise = false, tmp = s * sqrt(2), - kwargs..., + kwargs... ) - d, τ, s, @@ -165,7 +164,7 @@ function Parms(; τuΔ, utility_decrement, threshold_decrement, - tmp, + tmp ) Parms( @@ -198,7 +197,7 @@ function Parms(; mmp_utility, utility_noise, tmp, - NamedTuple(kwargs), + NamedTuple(kwargs) ) end @@ -215,7 +214,7 @@ function Base.show(io::IO, ::MIME"text/plain", parms::Parms) row_label_alignment = :l, row_labels = [fieldnames(Parms)...], formatters = ft_printf("%5.2f"), - alignment = :l, + alignment = :l ) end @@ -244,7 +243,7 @@ An object representing a declarative memory chunk. - `lags=Float64[]`: lags for recent retrievals (L - recent) - `bl=0.0`: baselevel constant added to chunks activation """ -mutable struct Chunk{T1,T2} <: AbstractChunk +mutable struct Chunk{T1, T2} <: AbstractChunk N::Int L::Float64 time_created::Float64 @@ -258,8 +257,8 @@ mutable struct Chunk{T1,T2} <: AbstractChunk act_noise::T2 slots::T1 reps::Int64 - recent::Array{Float64,1} - lags::Array{Float64,1} + recent::Array{Float64, 1} + lags::Array{Float64, 1} bl::T2 end @@ -314,9 +313,8 @@ function Chunk(; reps = 0, lags = Float64[], bl = zero(typeof(act)), - slots..., + slots... ) - T = typeof(act) act_mean = zero(T) act_pm = zero(T) @@ -340,7 +338,7 @@ function Chunk(; reps, recent, lags, - bl, + bl ) end @@ -390,9 +388,8 @@ function Chunk( reps = 0, lags = Float64[], bl = zero(typeof(act)), - slots..., + slots... ) - T = typeof(act) act_mean = zero(T) act_pm = zero(T) @@ -417,7 +414,7 @@ function Chunk( reps, recent, lags, - bl, + bl ) end @@ -435,7 +432,7 @@ const chunk_fields = ( :bl, :act_bll, :act_pm, - :act_noise, + :act_noise ) function chunk_values(chunk) @@ -455,7 +452,7 @@ function Base.show(io::IO, ::MIME"text/plain", chunk::AbstractChunk) row_label_alignment = :l, row_labels = [chunk_fields...], formatters = ft_printf("%5.2f"), - alignment = :l, + alignment = :l ) end @@ -474,7 +471,7 @@ function Base.show(io::IO, ::MIME"text/plain", chunks::Vector{<:Chunk}) header = [chunk_fields...], row_label_alignment = :l, formatters = ft_printf("%5.2f"), - alignment = :l, + alignment = :l ) end @@ -493,10 +490,10 @@ Declarative memory module - `buffer`: an array containing one chunk - `state`: buffer state """ -mutable struct Declarative{T1,T2,B} <: Mod - memory::Array{T1,1} +mutable struct Declarative{T1, T2, B} <: Mod + memory::Array{T1, 1} filtered::T2 - buffer::Array{T1,1} + buffer::Array{T1, 1} state::B end @@ -532,8 +529,8 @@ Imaginal Module. - `ω=1.0`: fan weight. Default is 1. - `denoms=Int64[]`: cached value for the denominator of the fan calculation """ -mutable struct Imaginal{T1,T2,B} <: Mod - buffer::Array{T1,1} +mutable struct Imaginal{T1, T2, B} <: Mod + buffer::Array{T1, 1} state::B ω::T2 denoms::Vector{Int64} @@ -558,8 +555,8 @@ Visual Module. - `state`: buffer state - `focus`: coordinates of visual attention """ -mutable struct Visual{T1,B} <: Mod - buffer::Array{T1,1} +mutable struct Visual{T1, B} <: Mod + buffer::Array{T1, 1} state::B focus::Vector{Float64} end @@ -568,7 +565,6 @@ Visual(; buffer = Chunk[]) = Visual(buffer, BufferState(), fill(0.0, 2)) Visual(chunk::AbstractChunk, state, focus) = Visual([chunk], state, focus) Visual(T::DataType, state, focus) = Visual(T(undef, 1), state, focus) - abstract type AbstractVisualObject end """ VisualObject(;x=300.0, y=300.0, color=:black, text="", shape=:_, width=30.0, height=30.0) @@ -602,7 +598,7 @@ function VisualObject(; text = "", shape = :_, width = 30.0, - height = 30.0, + height = 30.0 ) return VisualObject(x, y, color, shape, text, width, height) end @@ -618,10 +614,10 @@ Visual Location Module. - `state::B`: buffer state - `iconic_memory::Array{T1,1}`: a temporary memory store for visible objects """ -mutable struct VisualLocation{T1,B} <: Mod - buffer::Array{T1,1} +mutable struct VisualLocation{T1, B} <: Mod + buffer::Array{T1, 1} state::B - iconic_memory::Array{T1,1} + iconic_memory::Array{T1, 1} end function VisualLocation(; buffer = Chunk[]) @@ -682,7 +678,7 @@ Procedural Memory Module object. - `buffer`: an array holding up to one chunk - `state`: buffer state """ -mutable struct Procedural{R,B} <: Mod +mutable struct Procedural{R, B} <: Mod id::String rules::R state::B @@ -714,8 +710,8 @@ Goal Module. - `buffer`: an array holding up to one chunk - `state`: buffer state """ -mutable struct Goal{T1,B} <: Mod - buffer::Array{T1,1} +mutable struct Goal{T1, B} <: Mod + buffer::Array{T1, 1} state::B end @@ -742,8 +738,8 @@ Motor Module. - `state`: buffer state - `mouse_position`: x,y coordinates of mouse position on screen """ -mutable struct Motor{T1,B} <: Mod - buffer::Array{T1,1} +mutable struct Motor{T1, B} <: Mod + buffer::Array{T1, 1} state::B mouse_position::Vector{Float64} end @@ -858,9 +854,8 @@ function ACTR(; visicon = init_visicon(), parm_type = Parms, rng = Random.default_rng(), - parms..., + parms... ) - parms′ = parm_type(; parms...) ACTR( @@ -875,10 +870,10 @@ function ACTR(; visicon, parms′, scheduler, - rng, + rng ) end function init_visicon() - Dict{String,VisualObject}() + Dict{String, VisualObject}() end diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index f40d598..971f07d 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -52,7 +52,7 @@ chunks = [Chunk(animal=:dog), Chunk(animal=cat)] find_index(chunks; animal=:dog) ``` """ -function find_index(chunks::Array{<:Chunk,1}; check_value = true, criteria...) +function find_index(chunks::Array{<:Chunk, 1}; check_value = true, criteria...) for (i, c) in enumerate(chunks) match(c; check_value, criteria...) ? (return i) : nothing end @@ -105,7 +105,7 @@ chunks = [Chunk(animal=:dog), Chunk(animal=cat)] find_index(chunks; animal=:dog) ``` """ -function find_index(chunks::Array{<:Chunk,1}, funs...; check_value = true, criteria...) +function find_index(chunks::Array{<:Chunk, 1}, funs...; check_value = true, criteria...) for (i, c) in enumerate(chunks) match(c, funs...; check_value, criteria...) ? (return i) : nothing end @@ -152,7 +152,7 @@ chunks = [Chunk(animal=:dog), Chunk(animal=:dog), Chunk(animal=cat)] find_indices(chunks; animal=:dog) ``` """ -function find_indices(chunks::Array{<:Chunk,1}; check_value = true, criteria...) +function find_indices(chunks::Array{<:Chunk, 1}; check_value = true, criteria...) idx = Int64[] for (i, c) in enumerate(chunks) match(c; check_value, criteria...) ? push!(idx, i) : nothing @@ -206,7 +206,7 @@ chunks = [Chunk(animal=:dog), Chunk(animal=:dog), Chunk(animal=cat)] find_indices(chunks; animal=:dog) ``` """ -function find_indices(chunks::Array{<:Chunk,1}, funs...; check_value = true, criteria...) +function find_indices(chunks::Array{<:Chunk, 1}, funs...; check_value = true, criteria...) idx = Int64[] for (i, c) in enumerate(chunks) match(c, funs...; check_value, criteria...) ? push!(idx, i) : nothing diff --git a/test/Memory_Tests.jl b/test/Memory_Tests.jl index 9a9b909..efd7278 100644 --- a/test/Memory_Tests.jl +++ b/test/Memory_Tests.jl @@ -1,7 +1,6 @@ using SafeTestsets @safetestset "Memory Tests" begin - @safetestset "baselevel" begin using ACTRModels, Test import ACTRModels: baselevel, baselevel! @@ -155,7 +154,7 @@ using SafeTestsets using ACTRModels, Test chunks = Chunk[ Chunk(; isa = :bafoon, animal = :dog, name = :Sigma, retrieved = [false]), - Chunk(; isa = :mammal, animal = :cat, name = :Butters, retrieved = [false]), + Chunk(; isa = :mammal, animal = :cat, name = :Butters, retrieved = [false]) ] memory = Declarative(; memory = chunks) actr = ACTR(; declarative = memory) @@ -167,7 +166,7 @@ using SafeTestsets using ACTRModels, Test chunks = Chunk[ Chunk(; isa = :bafoon, animal = :dog, name = :Sigma, retrieved = [false]), - Chunk(; isa = :mammal, animal = :cat, name = :Butters, retrieved = [false]), + Chunk(; isa = :mammal, animal = :cat, name = :Butters, retrieved = [false]) ] memory = Declarative(; memory = chunks) actr = ACTR(; declarative = memory, mmp = true) @@ -242,7 +241,7 @@ using SafeTestsets using ACTRModels, Test chunks = [ Chunk(; isa = :mammal, animal = :dog, name = :Sigma), - Chunk(; isa = :mammal, animal = :cat, name = :Butters), + Chunk(; isa = :mammal, animal = :cat, name = :Butters) ] memory = Declarative(; memory = chunks) actr = ACTR(; declarative = memory, sa = true, γ = 1.0) @@ -354,7 +353,7 @@ using SafeTestsets bll = true, sa = true, γ = 1.6, - δ = 1.0, + δ = 1.0 ) compute_activation!(actr, 3.0; a = :b) @test chunk.act_bll != 0 @@ -394,7 +393,7 @@ using SafeTestsets sa = true, γ = 1.6, δ = 1.0, - Σ = 0.3, + Σ = 0.3 ) @test get_parm(actr, :δ) ≈ 1.0 atol = 1e-5 @test get_parm(actr, :Σ) ≈ 0.3 atol = 1e-5 @@ -451,7 +450,7 @@ using SafeTestsets Random.seed!(41140) chunks = [ Chunk(a = :a, b = :b, c = :c, bl = -1.0), - Chunk(a = :a, b = :b, c = :a, bl = -1.0), + Chunk(a = :a, b = :b, c = :a, bl = -1.0) ] memory = Declarative(memory = chunks) τ = 0.0 @@ -581,7 +580,7 @@ using SafeTestsets Chunk(; a = :a1, b = :b1, v = 0.3, bl = 1.0), Chunk(; a = :a1, b = :b1, v = 0.2, bl = 1.0), Chunk(; a = :a2, b = :b2, v = 0.2, bl = 1.5), - Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5), + Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5) ] declarative = Declarative(memory = chunks) @@ -606,7 +605,6 @@ using SafeTestsets blended_value = blend_slots(actr, probs, values) @test blended_value == :a2 - end @safetestset "custom dissim_func" begin @@ -627,7 +625,7 @@ using SafeTestsets chunks = [ Chunk(; a = :a1, b = :b1, v = 0.3, bl = 1.0), Chunk(; a = :a2, b = :b2, v = 0.2, bl = 1.5), - Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5), + Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5) ] declarative = Declarative(memory = chunks) @@ -662,7 +660,7 @@ using SafeTestsets chunks = [ Chunk(; a = :a1, b = :b1, v = 0.3, bl = 1.0), Chunk(; a = :a2, b = :b2, v = 0.2, bl = 1.5), - Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5), + Chunk(; a = :a3, b = :b3, v = 0.1, bl = 0.5) ] declarative = Declarative(memory = chunks) diff --git a/test/Utility Tests.jl b/test/Utility Tests.jl index ddd669c..ce817dd 100644 --- a/test/Utility Tests.jl +++ b/test/Utility Tests.jl @@ -1,7 +1,6 @@ using SafeTestsets @safetestset "Utility Tests" begin - @safetestset "find_index" begin using ACTRModels, Test include("Utility_Functions.jl") @@ -28,7 +27,7 @@ using SafeTestsets chunk_set = chunks[idx] @test all( x -> x.slots.attribute == :locomotion && x.slots.value == :swimming, - chunk_set, + chunk_set ) idx = find_indices(actr, ==, !=; attribute = :category, value = :bird) diff --git a/test/Utility_Functions.jl b/test/Utility_Functions.jl index 3c91bab..a9289a0 100644 --- a/test/Utility_Functions.jl +++ b/test/Utility_Functions.jl @@ -2,19 +2,19 @@ function populateMemory(act = 0.0) chunks = [Chunk(object = :shark, attribute = :dangerous, value = :True, act = act)] push!( chunks, - Chunk(object = :shark, attribute = :locomotion, value = :swimming, act = act), + Chunk(object = :shark, attribute = :locomotion, value = :swimming, act = act) ) push!(chunks, Chunk(object = :shark, attribute = :category, value = :fish, act = act)) push!(chunks, Chunk(object = :salmon, attribute = :edible, value = :True, act = act)) push!( chunks, - Chunk(object = :salmon, attribute = :locomotion, value = :swimming, act = act), + Chunk(object = :salmon, attribute = :locomotion, value = :swimming, act = act) ) push!(chunks, Chunk(object = :salmon, attribute = :category, value = :fish, act = act)) push!(chunks, Chunk(object = :fish, attribute = :breath, value = :gills, act = act)) push!( chunks, - Chunk(object = :fish, attribute = :locomotion, value = :swimming, act = act), + Chunk(object = :fish, attribute = :locomotion, value = :swimming, act = act) ) push!(chunks, Chunk(object = :fish, attribute = :category, value = :animal, act = act)) push!(chunks, Chunk(object = :animal, attribute = :moves, value = :True, act = act)) @@ -26,12 +26,12 @@ function populateMemory(act = 0.0) push!(chunks, Chunk(object = :ostritch, attribute = :height, value = :tall, act = act)) push!( chunks, - Chunk(object = :ostritch, attribute = :category, value = :bird, act = act), + Chunk(object = :ostritch, attribute = :category, value = :bird, act = act) ) push!(chunks, Chunk(object = :bird, attribute = :wings, value = :True, act = act)) push!( chunks, - Chunk(object = :bird, attribute = :locomotion, value = :flying, act = act), + Chunk(object = :bird, attribute = :locomotion, value = :flying, act = act) ) push!(chunks, Chunk(object = :bird, attribute = :category, value = :animal, act = act)) return chunks diff --git a/test/Utility_Tests.jl b/test/Utility_Tests.jl index 24e7a92..f93c0d8 100644 --- a/test/Utility_Tests.jl +++ b/test/Utility_Tests.jl @@ -1,7 +1,6 @@ using SafeTestsets @safetestset "Utility Tests" begin - @safetestset "find_index" begin using ACTRModels, Test include("Utility_Functions.jl") @@ -32,7 +31,7 @@ using SafeTestsets chunk_set = chunks[idx] @test all( x -> x.slots.attribute == :locomotion && x.slots.value == :swimming, - chunk_set, + chunk_set ) idx = find_indices(actr, ==, !=; attribute = :category, value = :bird) diff --git a/test/memory.jl b/test/memory.jl index dd370cf..b0c73b4 100644 --- a/test/memory.jl +++ b/test/memory.jl @@ -4,7 +4,7 @@ function initializeACTR(; parms...) Chunk(; isa = :bafoon, animal = :dog, name = :Sigma), Chunk(; isa = :mammal, animal = :cat, name = :Butters), Chunk(; isa = :mammal, animal = :rat, name = :Joy), - Chunk(; isa = :mammal, animal = :rat, name = :Bernice), + Chunk(; isa = :mammal, animal = :rat, name = :Bernice) ] memory = Declarative(; memory = chunks) imaginal = Imaginal(buffer = typeof(chunks)(undef, 1)) From f924e23f0b3bbdc2a3a567f2d7ad3e503315eaf4 Mon Sep 17 00:00:00 2001 From: itsdfish <9677184+itsdfish@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:56:48 +0000 Subject: [PATCH 2/2] Format .jl files --- docs/make.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 8b4fd49..bfe1a19 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,9 +7,9 @@ makedocs( format = Documenter.HTML( assets = [ asset( - "https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", - class = :css - ) + "https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", + class = :css + ) ], collapselevel = 1 ),