Skip to content

Commit

Permalink
added more debug info & updated mdl precision, drop dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed Jul 22, 2020
1 parent 7cf38b7 commit b2d53cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions Project.toml
@@ -1,5 +1,5 @@
name = "LMCLUS"
version="0.4.1"
version="0.4.2"
uuid = "173e3a66-dd8a-5f2e-8a96-8b7ddc4d534d"

[deps]
Expand All @@ -13,14 +13,15 @@ MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"

[compat]
MultivariateStats = ">= 0.6.0"
Clustering = "^0.14"
MultivariateStats = "^0.7"
StatsBase = "^0.33"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[targets]
test = ["Test", "DelimitedFiles", "Combinatorics", "Distributions", "Serialization"]
test = ["Test", "DelimitedFiles", "Distributions", "Serialization"]
6 changes: 3 additions & 3 deletions src/LMCLUS.jl
Expand Up @@ -140,7 +140,7 @@ function find_manifold(X::AbstractMatrix{T}, index::Vector{Int},
filtered = Int[]
selected = copy(index)
N = size(X,1) # full space dimension
best_manifold = Manifold{T}(params.max_dim, index)
best_manifold = Manifold{T}(params.min_dim, index)
best_separation = Separation()

sep_dim = params.min_dim
Expand All @@ -166,14 +166,14 @@ function find_manifold(X::AbstractMatrix{T}, index::Vector{Int},
# check if the adjusted basis provides better separation
previous_outdim = outdim(best_manifold)
adjustbasis!(best_manifold, X, adjust_dim=params.dim_adjustment, adjust_dim_ratio=params.dim_adjustment_ratio)
@debug "manifold: perform basis adjustment..." outdim=outdim(best_manifold) previous_outdim
origin, basis = mean(best_manifold), projection(best_manifold)
@debug "manifold: perform basis adjustment..." outdim=outdim(best_manifold) previous_outdim origin basis
idxs = points(best_manifold)
sep = find_separation(view(X, :, idxs), origin, basis, params, prngs[1])
elseif state == :BOUND && params.bounded_cluster && size(best_manifold) > 0
# check if the bounded cluster provides better separation
@debug "manifold: separating within manifold subspace..."
origin, basis = mean(best_manifold), projection(best_manifold)
@debug "manifold: separating within manifold subspace..." origin basis
idxs = points(best_manifold)
sep = find_separation(view(X, :, idxs), origin, basis, params, prngs[1], ocss = true)
else
Expand Down
8 changes: 4 additions & 4 deletions src/mdl.jl
Expand Up @@ -331,28 +331,28 @@ end

"Calculate MDL for the manifold"
function calculate(::Type{MT}, M::Manifold{T}, X::AbstractMatrix{T}, Pm::Int, Pd::Int;
ɛ::T = 1e-2, tot::Int = 1000, tol = 1e-8) where {MT<:MethodType, T<:AbstractFloat}
ɛ::T = 1e-3, tot::Int = 1000, tol = 1e-18) where {MT<:MethodType, T<:AbstractFloat}
return modeldl(MT, M, X, Pm) + datadl(MT, M, X, Pd, ɛ, tot, tol)
end

"Calculate MDL for the clustering"
function calculate(::Type{MT}, Ms::Vector{Manifold}, X::AbstractMatrix{T}, Pm::Int, Pd::Int;
ɛ::T=1e-2, tot::Int = 1000, tol = 1e-8) where {MT<:MethodType, T<:AbstractFloat}
ɛ::T=1e-3, tot::Int = 1000, tol = 1e-18) where {MT<:MethodType, T<:AbstractFloat}
return sum(calculate(MT, m, X[:,points(m)], Pm, Pd, ɛ=ɛ, tot=tot, tol=tol) for m in Ms)
end

end

# Compatibility
function mdl(M::Manifold{T}, X::AbstractMatrix{T}, Pm::Int, Pd::Int;
dist::Symbol = :OptimalQuant, ɛ::T = 1e-2,
dist::Symbol = :OptimalQuant, ɛ::T = 1e-3,
tot::Int = 1000, tol = 1e-8) where T<:AbstractFloat
mdltype = Core.eval(MDL, dist)
return MDL.calculate(mdltype, M, X, Pm, Pd, ɛ=ɛ)
end

function mdl(Ms::Vector{Manifold}, X::AbstractMatrix{T}, Pm::Int, Pd::Int;
dist::Symbol = :OptimalQuant, ɛ::T = 1e-2,
dist::Symbol = :OptimalQuant, ɛ::T = 1e-3,
tot::Int = 1000, tol = 1e-8) where T<:AbstractFloat
return sum(mdl(m,X,Pm,Pd,dist=dist,ɛ=ɛ,tot=tot,tol=tol) for m in Ms)
end
6 changes: 3 additions & 3 deletions test/lmclus_test.jl
@@ -1,9 +1,8 @@
using LMCLUS
using Combinatorics
using Test
using Statistics
using DelimitedFiles
import Random
using Random

@testset "Clustering" begin

Expand Down Expand Up @@ -54,7 +53,8 @@ import Random
@test sum(counts(res)) == size(ds, 1)

cnts = counts(res)
@testset "Label Match" for idxs in combinations(1:nclusters(res),2)
nc = nclusters(res)
@testset "Label Match" for idxs in [(i,j) for i in 1:nc, j in 1:nc if i < j]
i = idxs[1]
j = idxs[2]
@test length(symdiff(points(manifold(res,i)), points(manifold(res, j)))) == cnts[i] + cnts[j]
Expand Down

0 comments on commit b2d53cb

Please sign in to comment.