From c87a7fae58287b0cb5c3b45167ecbc67fe2f6c0d Mon Sep 17 00:00:00 2001 From: "Eric S. Tellez" Date: Mon, 1 Aug 2022 09:18:44 -0500 Subject: [PATCH] adds Aqua checks; fixes some issues highlighted by Aqua --- .github/workflows/ci.yml | 22 ---------------------- .github/workflows/documentation.yml | 24 ++++++++++++++++++++++++ Project.toml | 10 ++++++---- src/KNearestCenters.jl | 2 +- src/criterions.jl | 2 +- src/knn.jl | 11 ++++------- src/knnopt.jl | 2 +- test/runtests.jl | 11 +++++++---- 8 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/documentation.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8a949f..ae34598 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,25 +51,3 @@ jobs: - uses: codecov/codecov-action@v1 with: file: lcov.info - docs: - name: Documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: julia-actions/setup-julia@v1 - with: - version: '1' - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: | - julia --project=docs -e ' - using Documenter: doctest - using KNearestCenters - doctest(KNearestCenters)' - - run: julia --project=docs docs/make.jl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 0000000..8ddb2d3 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,24 @@ +name: Documentation + +on: + push: + branches: + - main + tags: '*' + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@latest + with: + version: '1.6' + - name: Install dependencies + run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' + - name: Build and deploy + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key + run: julia --project=docs/ docs/make.jl \ No newline at end of file diff --git a/Project.toml b/Project.toml index 04b1219..44abb21 100644 --- a/Project.toml +++ b/Project.toml @@ -5,12 +5,9 @@ version = "0.7.2" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" -Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" -Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" KCenters = "5d8de97f-65f8-4dd6-a15b-0f89c36a43ce" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LossFunctions = "30fc2ffe-d236-52d8-8643-a9d8f7c094a7" -MLLabelUtils = "66a33bbf-0c2b-5fc8-a008-9da813334f0a" MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SearchModels = "0e966ebe-b704-4a65-8279-db954bfe5da0" @@ -20,16 +17,21 @@ StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] +Aqua = "0.5" CategoricalArrays = "0.8, 0.9, 0.10" KCenters = "0.7" +LossFunctions = "0.8" +MLUtils = "0.2.9" SearchModels = "0.3" SimilaritySearch = "0.8, 0.9" +StatsAPI = "1.4" StatsBase = "0.32, 0.33" julia = "1.6" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "CSV"] +test = ["Aqua", "Test", "CSV"] diff --git a/src/KNearestCenters.jl b/src/KNearestCenters.jl index 43a2c39..dd28537 100644 --- a/src/KNearestCenters.jl +++ b/src/KNearestCenters.jl @@ -9,7 +9,7 @@ import SearchModels: combine, mutate import StatsAPI: predict, fit using MLUtils -export Knc, KncConfig, KncConfigSpace, KncProto, KncProtoConfig, KncProtoConfigSpace, KncPerClassConfigSpace, KncGlobalConfigSpace +export Knc, KncConfig, KncConfigSpace, KncProto, KncProtoConfig, KncProtoConfigSpace export transform, predict, fit, categorical include("scores.jl") diff --git a/src/criterions.jl b/src/criterions.jl index 80c1975..8cff320 100644 --- a/src/criterions.jl +++ b/src/criterions.jl @@ -1,6 +1,6 @@ # This file is a part of KNearestCenters.jl -export size_criterion, sqrt_criterion, change_criterion, fun_criterion, log_criterion, epsilon_criterion, salesman_criterion +export size_criterion, sqrt_criterion, change_criterion, fun_criterion, epsilon_criterion, salesman_criterion """ diff --git a/src/knn.jl b/src/knn.jl index bd366e1..b515486 100644 --- a/src/knn.jl +++ b/src/knn.jl @@ -124,14 +124,11 @@ function fit(::Type{KnnModel}, index::AbstractSearchIndex, labels::CategoricalAr KnnModel(k, 1, KnnSingleLabelPrediction(imap), weight, index, meta_) end -function fit(::Type{KnnModel}, examples, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance()) - meta_, imap = onehotenc(labels) - if examples isa AbstractArray - db = MatrixDatabase(examples) - else - db = examples - end +fit(::Type{KnnModel}, examples::AbstractMatrix, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance()) = + fit(KnnModel, MatrixDatabase(examples), labels; k, weight, dist) +function fit(::Type{KnnModel}, db::AbstractDatabase, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance()) + meta_, imap = onehotenc(labels) index = ParallelExhaustiveSearch(; db, dist) KnnModel(k, 1, KnnSingleLabelPrediction(imap), weight, index, meta_) end diff --git a/src/knnopt.jl b/src/knnopt.jl index 20c3e47..5722aed 100644 --- a/src/knnopt.jl +++ b/src/knnopt.jl @@ -31,7 +31,7 @@ function optimize!( ] ) optimize!(model, klist, wlist) do - predict.(model, Xtest) + ypred = predict.(model, Xtest) value(loss, ytest, ypred) end end diff --git a/test/runtests.jl b/test/runtests.jl index c99c5e6..128a08c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,10 @@ # This file is a part of KCenters.jl -using Test -using KNearestCenters +using Test, KNearestCenters + +using Aqua +Aqua.test_all(KNearestCenters, ambiguities=false) +Aqua.test_ambiguities([KNearestCenters, Core]) @testset "Scores" begin @test accuracy_score([1,1,1,1,1], [1,1,1,1,1]) == 1.0 @@ -16,6 +19,6 @@ using KNearestCenters @test f1_score([0,1,1,1,0,1], [0,1,1,1,1,1], weight=:macro) ≈ (2 * 0.5 / 1.5 + 2 * 0.8 / 1.8) / 2 end -#include("knc.jl") +include("knc.jl") include("kncproto.jl") -#include("knn.jl") +include("knn.jl")