Skip to content

Commit

Permalink
Remove MLJ dependency, redefine performance, bump
Browse files Browse the repository at this point in the history
  • Loading branch information
AP6YC committed Jul 2, 2021
1 parent 28af78d commit c2ba44c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 37 deletions.
6 changes: 2 additions & 4 deletions Project.toml
Expand Up @@ -2,14 +2,13 @@ name = "AdaptiveResonance"
uuid = "3d72adc0-63d3-4141-bf9b-84450dd0395b"
authors = ["Sasha Petrenko"]
description = "A Julia package for Adaptive Resonance Theory (ART) algorithms."
version = "0.3.0"
version = "0.3.1"

[deps]
ClusterValidityIndices = "2fefd308-f647-4698-a2f0-e90cfcbca9ad"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
Expand All @@ -18,9 +17,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
ClusterValidityIndices = "0.1"
MLJ = "0.14, 0.15, 0.16"
Parameters = "0.12.1"
ProgressBars = "0.7, 0.8, 1.0"
ProgressBars = "0.7, 0.8, 1.0, 1.3"
julia = "1"

[extras]
Expand Down
7 changes: 3 additions & 4 deletions src/ARTMAP/ARTSCENE.jl
Expand Up @@ -178,7 +178,7 @@ function contrast_sensitive_oriented_filtering(image::RealArray, x::RealArray ;
y[:,:,:,k] = deepcopy(x)
end

for i = 1:n_iterations
for _ = 1:n_iterations
y += ddt_y(y, X_plus, X_minus, alpha, distributed)
end

Expand Down Expand Up @@ -223,7 +223,7 @@ end # competition_kernel(l::Integer, k::Integer ; sign::String="plus")
Time rate of change for ARTSCENE: Stage 5.
"""
function ddt_z(z::RealArray ; distributed=true)
function ddt_z(z::RealArray ; distributed::Bool=true)
n_row, n_column, n_g, n_k = size(z)
kernel_r = 5

Expand Down Expand Up @@ -266,8 +266,7 @@ function orientation_competition(z::RealArray)
# Z[:,:,:,k] = deepcopy(z)
# end

for i = 1:n_iterations
# Z += ddt_z(z)
for _ = 1:n_iterations
z += ddt_z(z)
end

Expand Down
3 changes: 1 addition & 2 deletions src/AdaptiveResonance.jl
Expand Up @@ -5,8 +5,7 @@ using Parameters # ARTopts are parameters (@with_kw)
using Logging # Logging utils used as main method of terminal reporting
using ProgressBars # Provides progress bars for training and inference
using Printf # Used for printing formatted progress bars
using MLJ: confusion_matrix, coerce, OrderedFactor
using LinearAlgebra: tr, norm # Trace and norms
using LinearAlgebra: norm # Trace and norms
using Statistics: median, mean # Medians and mean for linkage methods

# Abstract types
Expand Down
24 changes: 10 additions & 14 deletions src/common.jl
Expand Up @@ -117,27 +117,23 @@ end # element_min(x::RealVector, W::RealVector)
Returns the categorization performance of y_hat against y.
"""
function performance(y_hat::IntegerVector, y::IntegerVector)
# Get the number of labels
n_y = length(y)

# Check lengths
if length(y_hat) != length(y)
if length(y_hat) != n_y
error("Label vectors must be the same length")
end

# Clean up the vectors
n_mismatch = 0
y_hat_local = Integer[]
y_local = Integer[]
for ix = 1:length(y_hat)
if y_hat[ix] != -1
push!(y_hat_local, y_hat[ix])
push!(y_local, y[ix])
else
n_mismatch += 1
# Get the number of correct classifications
n_correct = 0
for ix = 1:n_y
if y_hat[ix] == y[ix]
n_correct += 1
end
end

# Compute the confusion matrix and calculate performance as trace/sum
conf = confusion_matrix(coerce(y_hat_local, OrderedFactor), coerce(y_local, OrderedFactor))
return tr(conf.mat)/(sum(conf.mat) + n_mismatch)
return n_correct/n_y
end # performance(y_hat::IntegerVector, y::IntegerVector)

"""
Expand Down
40 changes: 27 additions & 13 deletions test/test_ddvfa.jl
Expand Up @@ -160,19 +160,33 @@ end # @testset "DDVFA"
# Compute the local activation and match
AdaptiveResonance.activation_match!(my_gnfa, local_sample)

truth = Dict("single" => Dict("T" => 0.9988445088278305,
"M" => 2.591300556893253),
"average" => Dict("T" => 0.41577750468594143,
"M" => 1.322517210029363),
"complete" => Dict("T" => 0.04556971777638373,
"M" => 0.13166315262229716),
"median" => Dict("T" => 0.3312241307874298,
"M" => 1.3248965231497192),
"weighted" => Dict("T" => 0.533208585217186,
"M" => 1.3855766656866793),
"centroid" => Dict("T" => 0.0,
"M" => 0.0)
)
# Declare the true activation and match magnitudes
truth = Dict(
"single" => Dict(
"T" => 0.9988445088278305,
"M" => 2.591300556893253
),
"average" => Dict(
"T" => 0.41577750468594143,
"M" => 1.322517210029363
),
"complete" => Dict(
"T" => 0.04556971777638373,
"M" => 0.13166315262229716
),
"median" => Dict(
"T" => 0.3312241307874298,
"M" => 1.3248965231497192
),
"weighted" => Dict(
"T" => 0.533208585217186,
"M" => 1.3855766656866793
),
"centroid" => Dict(
"T" => 0.0,
"M" => 0.0
)
)

# Test every method and field name
for method in methods
Expand Down

2 comments on commit c2ba44c

@AP6YC
Copy link
Owner Author

@AP6YC AP6YC commented on c2ba44c Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Removed the MLJ requirement, redefining performance() more simply.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40091

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" c2ba44c82f863231beb9c9ae2919a2515763fdc5
git push origin v0.3.1

Please sign in to comment.