Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Oct 27, 2022
1 parent 564f4a1 commit 2715ac7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 37 deletions.
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Expand Down
25 changes: 15 additions & 10 deletions test/examples/fmnist.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
using MLDatasets: FashionMNIST

function test_fmnist::Float64 = 0.75)
function test_fmnist::Float64 = 0.75, δ::Float64 = 1E-2, k::Integer = 5)
trainset = FashionMNIST(Int, :train)
testset = FashionMNIST(Int, :test)

n = length(trainset)
x = [trainset[i][:features] for i = 1:n]
y = [trainset[i][:targets] for i = 1:n]
y = [trainset[i][:targets] for i = 1:n]

= length(testset)
= [testset[i][:features] for i = 1:n̂]
= [testset[i][:targets] for i = 1:n̂]
= [testset[i][:targets] for i = 1:n̂]

@testset "FashionMNIST ≥" begin
wnn = WNN{Int,UInt64}(28, 28)
α⃗ = Vector{Float64}(undef, k)

WiSARD.classhint!(wnn, collect(0:9))
for j = 1:k
wnn = WNN{Int,UInt64}(28, 28)

train!.(wnn, x, y)
train!.(wnn, x, y)

= classify.(wnn, x̂)
ᾱ = WiSARD.accuracy(ŷ, ȳ)

@info "ᾱ = $ᾱ @ FashionMNIST"
= classify.(wnn, x̂)
α⃗[j] = WiSARD.accuracy(ŷ, ȳ)
end

ᾱ, δ̄ = mean(α⃗), std(α⃗)

@info @sprintf("ᾱ = %.2f ± %.2f @ FashionMNIST", ᾱ, δ̄)
@test ᾱ >= α
@test δ̄ <= δ
end

return nothing
Expand Down
28 changes: 16 additions & 12 deletions test/examples/iris.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using DataFrames
using MLDatasets: Iris

function test_iris::Float64 = 0.85, β::Float64 = 6/7)
dataset = Iris(; as_df=true)
function test_iris::Float64 = 0.85, β::Float64 = 6 / 7, δ::Float64 = 1E-1, k::Integer = 10)
dataset = Iris(; as_df = true)
N, M = size(dataset.features)
a = [minimum(dataset.features[!, i]) for i = 1:M]
b = [maximum(dataset.features[!, i]) for i = 1:M]
n = trunc(Int, N * β)
= N - n
i = shuffle(1:N)

trainset = dataset[i[begin:n]]
testset = dataset[i[n+1:end]]
trainset = dataset[+1:N]
testset = dataset[1:]

x = [collect(Float64, trainset[:features][i, :]) for i = 1:n]
y = collect(String, trainset[:targets][!, 1])
Expand All @@ -27,17 +26,22 @@ function test_iris(α::Float64 = 0.85, β::Float64 = 6/7)
= τ.(x̂)

@testset "Iris ≥" begin
wnn = WNN{String,UInt64}(8, 4)
α⃗ = Vector{Float64}(undef, k)

# WiSARD.classhint!(wnn, collect(0:9))
for j = 1:k
wnn = WNN{String,UInt64}(8, 4; seed=j)

train!.(wnn, z, y)
train!.(wnn, z, y)

= classify.(wnn, ẑ)
ᾱ = WiSARD.accuracy(ŷ, ȳ)

@info "ᾱ = $ᾱ @ Iris"
= classify.(wnn, ẑ)
α⃗[j] = WiSARD.accuracy(ŷ, ȳ)
end

ᾱ, δ̄ = mean(α⃗), std(α⃗)

@info @sprintf("ᾱ = %.2f ± %.2f @ Iris", ᾱ, δ̄)
@test ᾱ >= α
@test δ̄ <= δ
end

return nothing
Expand Down
23 changes: 15 additions & 8 deletions test/examples/mnist.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MLDatasets: MNIST

function test_mnist::Float64 = 0.9)
function test_mnist::Float64 = 0.9, δ::Float64 = 1E-2, k::Integer = 5)
trainset = MNIST(Int, :train)
testset = MNIST(Int, :test)

Expand All @@ -13,17 +13,24 @@ function test_mnist(α::Float64 = 0.9)
= [testset[i][:targets] for i = 1:n̂]

@testset "MNIST ≥" begin
wnn = WNN{Int,UInt64}(28, 28)
α⃗ = Vector{Float64}(undef, k)

WiSARD.classhint!(wnn, collect(0:9))
for j = 1:k
wnn = WNN{Int,UInt64}(28, 28)

train!.(wnn, x, y)
WiSARD.classhint!(wnn, collect(0:9))

= classify.(wnn, x̂)
ᾱ = WiSARD.accuracy(ŷ, ȳ)

@info "ᾱ = $ᾱ @ MNIST"
train!.(wnn, x, y)

= classify.(wnn, x̂)
α⃗[j] = WiSARD.accuracy(ŷ, ȳ)
end

ᾱ, δ̄ = mean(α⃗), std(α⃗)

@info @sprintf("ᾱ = %.2f ± %.2f @ MNIST", ᾱ, δ̄)
@test ᾱ >= α
@test δ̄ <= δ
end

return nothing
Expand Down
21 changes: 14 additions & 7 deletions test/examples/xyz.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function test_xyz::Float64=1.0)
function test_xyz::Float64=1.0, δ::Float64=0.0, k::Integer = 10)
x == [
[
1 0 1
Expand All @@ -23,15 +23,22 @@ function test_xyz(α::Float64=1.0)
y == [:x, :y, :z]

@testset "XYZ ≥" begin
wnn = WNN{Symbol,UInt}(3, 4)
α⃗ = Vector{Float64}(undef, k)

train!.(wnn, x, y)
for j = 1:k
wnn = WNN{Symbol,UInt64}(3, 4; seed=j)

= classify.(wnn, x̂)
ᾱ = WiSARD.accuracy(ŷ, ȳ)
train!.(wnn, x, y)

@info "ᾱ = $ᾱ @ XYZ"
@test ᾱ >= α
= classify.(wnn, x̂)
α⃗[j] = WiSARD.accuracy(ŷ, ȳ)
end

ᾱ, δ̄ = mean(α⃗), std(α⃗)

@info @sprintf("ᾱ = %.2f ± %.2f @ XYZ", ᾱ, δ̄)
@test ᾱ >= α
@test δ̄ <= δ
end

return nothing
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Test
using Printf
using Random
using WiSARD
using Statistics

# -*- Accept MLDatasets Downloads -*- #
ENV["DATADEPS_ALWAYS_ACCEPT"] = true
Expand Down

2 comments on commit 2715ac7

@pedromxavier
Copy link
Owner Author

Choose a reason for hiding this comment

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

@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/71197

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.2 -m "<description of version>" 2715ac7be0f6e969cffdb29a2f8206e733a73628
git push origin v0.3.2

Please sign in to comment.