Skip to content

Commit

Permalink
Merge pull request #74 from itsdfish/auto-juliaformatter-pr
Browse files Browse the repository at this point in the history
Automatic JuliaFormatter.jl run
  • Loading branch information
itsdfish authored Nov 25, 2024
2 parents 130dce5 + 96227ad commit 0d9c5d7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 40 deletions.
25 changes: 21 additions & 4 deletions src/MemoryFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ with `get_time`.
- `request...`: optional keywords for the retrieval request
"""
function compute_activation!(actr::AbstractACTR, chunk::AbstractChunk; funs = (), request...)
function compute_activation!(
actr::AbstractACTR,
chunk::AbstractChunk;
funs = (),
request...
)
return compute_activation!(actr, chunk, get_time(actr); funs, request...)
end

Expand Down Expand Up @@ -208,7 +213,13 @@ Computes the activation of a chunk
- `request...`: optional keywords for the retrieval request
"""
function activation!(actr::AbstractACTR, chunk::AbstractChunk, cur_time = 0.0; funs = (), request...)
function activation!(
actr::AbstractACTR,
chunk::AbstractChunk,
cur_time = 0.0;
funs = (),
request...
)
memory = actr.declarative
(; sa_fun, bll, mmp, sa, noise, blc, τ) = actr.parms
reset_activation!(chunk)
Expand Down Expand Up @@ -508,7 +519,13 @@ Uses the softmax approximation to compute the retrieval probability of retrievin
- `request...`: optional keyword pairs representing a retrieval request
"""
function retrieval_prob(actr::AbstractACTR, chunk::AbstractChunk, cur_time; funs = (), request...)
function retrieval_prob(
actr::AbstractACTR,
chunk::AbstractChunk,
cur_time;
funs = (),
request...
)
(; τ, s, noise) = actr.parms
σ = s * sqrt(2)
_funs = isempty(funs) ? fill(==, length(request)) : funs
Expand Down Expand Up @@ -1272,7 +1289,7 @@ function blend_slots(
actr::AbstractACTR,
chunks::Vector{<:AbstractChunk},
probs::Vector{<:Real},
blended_slots,
blended_slots
)
return map(s -> blend_slots(actr, chunks, probs, s), blended_slots)
end
Expand Down
73 changes: 37 additions & 36 deletions test/Memory_Tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ using SafeTestsets
import ACTRModels: blend_slots

function dissim_func(s, x, y, f)
if (f(x,:a1) && f(y, :a2)) || (f(y, :a1) && f(x, :a2))
if (f(x, :a1) && f(y, :a2)) || (f(y, :a1) && f(x, :a2))
return 0.1
elseif (f(x, :a1) && f(y, :a3)) || (f(y, :a1) && f(x, :a3))
return 0.2
Expand Down Expand Up @@ -613,7 +613,7 @@ using SafeTestsets
using Test

function dissim_func(s, x, y, f)
if (f(x,:a1) && f(y, :a2)) || (f(y, :a1) && f(x, :a2))
if (f(x, :a1) && f(y, :a2)) || (f(y, :a1) && f(x, :a2))
return 0.1
elseif (f(x, :a1) && f(y, :a3)) || (f(y, :a1) && f(x, :a3))
return 0.2
Expand Down Expand Up @@ -702,21 +702,21 @@ using SafeTestsets
@test isempty(result)
end

@safetestset "negation" begin
@safetestset "with negation" begin
@safetestset "negation" begin
@safetestset "with negation" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = true,
mmp = true,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -726,24 +726,24 @@ using SafeTestsets
chunk = retrieve(actr; funs = (,), a = 1)

@test chunks[1].act_mean -1
@test chunks[2].act_mean 0
@test chunks[3].act_mean 0
@test chunks[2].act_mean 0
@test chunks[3].act_mean 0
end

@safetestset "no negation" begin
@safetestset "no negation" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = true,
mmp = true,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -752,25 +752,25 @@ using SafeTestsets

chunk = retrieve(actr; a = 1)

@test chunks[1].act_mean 0
@test chunks[1].act_mean 0
@test chunks[2].act_mean -1
@test chunks[3].act_mean -1
end

@safetestset "no negation requested" begin
@safetestset "no negation requested" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = true,
mmp = true,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -782,20 +782,20 @@ using SafeTestsets
@test length(requested) == 3
end

@safetestset "negation requested" begin
@safetestset "negation requested" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = true,
mmp = true,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -807,20 +807,20 @@ using SafeTestsets
@test length(requested) == 3
end

@safetestset "no negation requested mmp false" begin
@safetestset "no negation requested mmp false" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = false,
mmp = false,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -833,20 +833,20 @@ using SafeTestsets
@test requested[1].slots.a == 1
end

@safetestset "negation requested mmp false" begin
@safetestset "negation requested mmp false" begin
using ACTRModels
using Test

chunks = [
Chunk(; a = 1, b = 2),
Chunk(; a = 2, b = 2),
Chunk(; a = 3, b = 2)
]
]

parms = (
mmp = false,
mmp = false,
δ = 1,
noise = false,
noise = false,
τ = -10
)

Expand All @@ -860,20 +860,21 @@ using SafeTestsets
@test requested[2].slots.a == 3
end

@safetestset "blending" begin
@safetestset "blending" begin
using ACTRModels, Test, Random, Distributions
Random.seed!(652)
chunks = [Chunk(; a = 2, b = 0), Chunk(; a = 1, b = 3)]
parms = (mmp = true, δ = 1.0, noise = true, s = 0.2)
declarative = Declarative(; memory = chunks)
actr = ACTR(; declarative, parms...)

request = (a = 2,)
funs = (,)
blended_slots = :b
n_sim = 10_000
mean_value1 =
map(_ -> blend_chunks(actr, blended_slots; funs, request...), 1:n_sim) |> mean
map(_ -> blend_chunks(actr, blended_slots; funs, request...), 1:n_sim) |>
mean
# should be weighted more towards 3 than 0
@test mean_value1 2.75 atol = 0.01
end
Expand All @@ -885,15 +886,15 @@ using SafeTestsets
parms = (mmp = true, δ = 1.0, noise = true, s = 0.2)
declarative = Declarative(; memory = chunks)
actr = ACTR(; declarative, parms...)

request = (a = :a,)
funs = (,)
blended_slots = [:a,:b]
blended_slots = [:a, :b]
n_sim = 10_000
blended_values =
map(_ -> blend_chunks(actr, blended_slots; funs, request...), 1:n_sim)
# should be weighted more towards 3 than 0
@test mean(map(x -> x[1] == :c, blended_values)) .90
@test mean(map(x -> x[1] == :c, blended_values)) 0.90
@test mean(map(x -> x[2], blended_values)) 1.5
end
end
Expand Down

0 comments on commit 0d9c5d7

Please sign in to comment.