Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for laplace #428

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CounterfactualExplanations"
uuid = "2f13d31b-18db-44c1-bc43-ebaf2cff0be0"
authors = ["Patrick Altmeyer <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
47 changes: 26 additions & 21 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ version = "0.10.14"

[[deps.CUDA]]
deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CUDA_Driver_jll", "CUDA_Runtime_Discovery", "CUDA_Runtime_jll", "Crayons", "DataFrames", "ExprTools", "GPUArrays", "GPUCompiler", "KernelAbstractions", "LLVM", "LLVMLoopInfo", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "NVTX", "Preferences", "PrettyTables", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "StaticArrays", "Statistics"]
git-tree-sha1 = "baa8ea7a1ea63316fa3feb454635215773c9c845"
git-tree-sha1 = "3dcab8a2c18ca319ea15a41d90e9528b8e93894a"
uuid = "052768ef-5323-5732-b1bb-66c8b64840ba"
version = "5.2.0"
version = "5.3.0"
weakdeps = ["ChainRulesCore", "SpecialFunctions"]

[deps.CUDA.extensions]
Expand All @@ -145,9 +145,9 @@ weakdeps = ["ChainRulesCore", "SpecialFunctions"]

[[deps.CUDA_Driver_jll]]
deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "d01bfc999768f0a31ed36f5d22a76161fc63079c"
git-tree-sha1 = "dc172b558adbf17952001e15cf0d6364e6d78c2f"
uuid = "4ee394cb-3365-5eb0-8335-949819d2adfc"
version = "0.7.0+1"
version = "0.8.1+0"

[[deps.CUDA_Runtime_Discovery]]
deps = ["Libdl"]
Expand All @@ -157,9 +157,9 @@ version = "0.2.4"

[[deps.CUDA_Runtime_jll]]
deps = ["Artifacts", "CUDA_Driver_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"]
git-tree-sha1 = "8e25c009d2bf16c2c31a70a6e9e8939f7325cc84"
git-tree-sha1 = "4ca7d6d92075906c2ce871ea8bba971fff20d00c"
uuid = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"
version = "0.11.1+0"
version = "0.12.1+0"

[[deps.Calculus]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -340,14 +340,19 @@ version = "0.1.3"

[[deps.CounterfactualExplanations]]
deps = ["CUDA", "CategoricalArrays", "ChainRulesCore", "DataFrames", "DecisionTree", "Distributions", "Flux", "LazyArtifacts", "LinearAlgebra", "Logging", "MLJBase", "MLJDecisionTreeInterface", "MLUtils", "MultivariateStats", "PackageExtensionCompat", "Parameters", "ProgressMeter", "Random", "Serialization", "Statistics", "StatsBase", "Tables", "TaijaBase", "UUIDs"]
git-tree-sha1 = "c384305a71c143a862cf0fc09d79ff3ed6b7a5fc"
git-tree-sha1 = "bc266bfcad331f7fd27b831011574e8e8ee351e4"
uuid = "2f13d31b-18db-44c1-bc43-ebaf2cff0be0"
version = "1.0.0"
weakdeps = ["EvoTrees", "LaplaceRedux"]
version = "1.1.0"

[deps.CounterfactualExplanations.extensions]
EvoTreesExt = "EvoTrees"
LaplaceReduxExt = "LaplaceRedux"
NeuroTreeExt = "NeuroTreeModels"

[deps.CounterfactualExplanations.weakdeps]
EvoTrees = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5"
LaplaceRedux = "c52c1a26-f7c5-402b-80be-ba1e638ad478"
NeuroTreeModels = "1db4e0a5-a364-4b0c-897c-2bd5a4a3a1f2"

[[deps.Crayons]]
git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
Expand All @@ -373,9 +378,9 @@ version = "1.6.1"

[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "0f4b5d62a88d8f59003e43c25a8a90de9eb76317"
git-tree-sha1 = "97d79461925cdb635ee32116978fc735b9463a39"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.18"
version = "0.18.19"

[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand Down Expand Up @@ -592,9 +597,9 @@ version = "0.1.6"

[[deps.GPUCompiler]]
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"]
git-tree-sha1 = "a846f297ce9d09ccba02ead0cae70690e072a119"
git-tree-sha1 = "1600477fba37c9fc067b9be21f5e8101f24a8865"
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
version = "0.25.0"
version = "0.26.4"

[[deps.GZip]]
deps = ["Libdl", "Zlib_jll"]
Expand All @@ -604,9 +609,9 @@ version = "0.6.2"

[[deps.GeoInterface]]
deps = ["Extents"]
git-tree-sha1 = "d4f85701f569584f2cff7ba67a137d03f0cfb7d0"
git-tree-sha1 = "801aef8228f7f04972e596b09d4dba481807c913"
uuid = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
version = "1.3.3"
version = "1.3.4"

[[deps.GeometryBasics]]
deps = ["EarCut_jll", "Extents", "GeoInterface", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
Expand Down Expand Up @@ -802,9 +807,9 @@ version = "1.3.1"

[[deps.LaplaceRedux]]
deps = ["ChainRulesCore", "Compat", "ComputationalResources", "Flux", "LinearAlgebra", "MLJFlux", "MLJModelInterface", "MLUtils", "Parameters", "ProgressMeter", "Random", "Statistics", "Tables", "Tullio", "Zygote"]
git-tree-sha1 = "7baad6315a4027403cfb6fb75d16feb047d9022e"
git-tree-sha1 = "9ccffc199b1344d35fc41f39b59f36dc84ed590d"
uuid = "c52c1a26-f7c5-402b-80be-ba1e638ad478"
version = "0.1.7"
version = "0.1.8"

[[deps.LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
Expand Down Expand Up @@ -927,9 +932,9 @@ version = "1.9.6"

[[deps.MLJModels]]
deps = ["CategoricalArrays", "CategoricalDistributions", "Combinatorics", "Dates", "Distances", "Distributions", "InteractiveUtils", "LinearAlgebra", "MLJModelInterface", "Markdown", "OrderedCollections", "Parameters", "Pkg", "PrettyPrinting", "REPL", "Random", "RelocatableFolders", "ScientificTypes", "StatisticalTraits", "Statistics", "StatsBase", "Tables"]
git-tree-sha1 = "dd99a80f39cae8b112823d279dfa08ae872b4f3e"
git-tree-sha1 = "410da88e0e6ece5467293d2c76b51b7c6df7d072"
uuid = "d491faf4-2d78-11e9-2867-c94bc002c0b7"
version = "0.16.16"
version = "0.16.17"

[[deps.MLStyle]]
git-tree-sha1 = "bc38dff0548128765760c79eb7388a4b37fae2c8"
Expand Down Expand Up @@ -1098,9 +1103,9 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.OffsetArrays]]
git-tree-sha1 = "6a731f2b5c03157418a20c12195eb4b74c8f8621"
git-tree-sha1 = "e64b4f5ea6b7389f6f046d13d4896a8f9c1ba71e"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.13.0"
version = "1.14.0"
weakdeps = ["Adapt"]

[deps.OffsetArrays.extensions]
Expand Down
25 changes: 25 additions & 0 deletions test/models/laplace_redux/laplace_redux.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CounterfactualExplanations
using CounterfactualExplanations.Models
using LaplaceRedux
using TaijaData

@testset "LaplaceRedux" begin
counterfactual_data =
TaijaData.load_linearly_separable() |>
x -> (Float32.(x[1]), x[2]) |> x -> CounterfactualData(x...)
M = Models.fit_model(counterfactual_data, :LaplaceRedux)

# Select a factual instance:
target = 2
factual = 1
chosen = rand(findall(predict_label(M, counterfactual_data) .== factual))
x = select_factual(counterfactual_data, chosen)

# Search:
generator = GenericGenerator()
ce = generate_counterfactual(x, target, counterfactual_data, M, generator)
@test typeof(ce) <: CounterfactualExplanation
@test CounterfactualExplanations.counterfactual_label(ce) == [target]
end


Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

1 change: 1 addition & 0 deletions test/models/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if VERSION >= v"1.9"
# Extension currently only works with Julia 1.9 and above (https://github.com/Evovest/NeuroTreeModels.jl/pull/7)
include("neurotree/neurotree.jl")
end
include("laplace_redux/laplace_redux.jl")
include("utils.jl")

@testset "Standard models for synthetic data" begin
Expand Down
Loading