diff --git a/src/algorithms/conductance.jl b/src/algorithms/conductance.jl index 8e49907..680849b 100644 --- a/src/algorithms/conductance.jl +++ b/src/algorithms/conductance.jl @@ -5,20 +5,21 @@ Calculate unweighted hypergraph conductance of `subset`. note: ∅ ⊊ `subset` ⊊ `1:nhv(h)` For more information see `1. Introduction` at: -Generalizing the Hypergraph Laplacian via a Diffusion Processwith Mediators, -auhtors: T-H. Hubert Chan, Xhibin Liang. +Spectral Properties of Hypergraph Laplacian and Approximation Algorithms +auhtors: T-H. Hubert Chan, Anand Louis, Zhihao Gavin Tang, and Chenzi Zhang """ function conductance(h::Hypergraph, subset::Set{Int})::Float64 if isempty(subset) error("`subset` is not allowed empty.") end if subset == Set(1:nhv(h)) error("`subset` is not allowed true subset of `h`.") end subset2 = setdiff(Set(1:nhv(h)), subset) - wₛ = sum([length(gethyperedges(h, node)) for node in subset]) - w∂s = 0 + volS = sum([sum(values(gethyperedges(h, node))) for node in subset]) + volV_S = sum([sum(values(gethyperedges(h, node))) for node in subset2]) + cutS = 0 for he in 1:nhe(h) he_vertices = keys(getvertices(h, he)) if isempty(intersect(he_vertices, subset)) continue end if isempty(intersect(he_vertices, subset2)) continue end - w∂s += length(getvertices(h, he)) + cutS += 1 end - return w∂s / wₛ + return cutS / min(volS, volV_S) end diff --git a/test/runtests.jl b/test/runtests.jl index e41b4cb..f85c2c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -311,7 +311,7 @@ end; @test typeof(randompartition(hg, 2)) == Vector{Set{Int}} @test length(randompartition(hg, 2)) == 2 @test sort(vcat(collect.(randompartition(hg, 2))...))==1:nhv(hg) - + hh = Hypergraph{Bool}(7,4) hh[1,1] = true hh[2,1:2] .= true @@ -476,10 +476,10 @@ end; h[4,3:4] .= 1 h[5,4] = 1 h[5,2] = 1 - @test SimpleHypergraphs.conductance(h, Set(1:3)) == 5 / 5 - @test SimpleHypergraphs.conductance(h, Set(1)) == 3 / 1 - @test SimpleHypergraphs.conductance(h, Set([1, 4])) == 8 / 3 - @test SimpleHypergraphs.conductance(h, Set(2:5)) == 3 / 8 + @test SimpleHypergraphs.conductance(h, Set(1:3)) == 2 / 4 + @test SimpleHypergraphs.conductance(h, Set(1)) == 1 / 1 + @test SimpleHypergraphs.conductance(h, Set([1, 4])) == 3 / 3 + @test SimpleHypergraphs.conductance(h, Set(2:5)) == SimpleHypergraphs.conductance(h, Set(1)) h = Hypergraph{Int}(6, 7) h[1:3, 1] .= 1 h[1:2, 2] .= 1 @@ -489,8 +489,8 @@ end; h[4:6, 5] .= 1 h[4:5, 6] .= 1 h[5:6, 7] .= 1 - @test SimpleHypergraphs.conductance(h, Set(1:3)) == 2 / 8 - @test SimpleHypergraphs.conductance(h, Set([1, 4])) == 14 / 6 + @test SimpleHypergraphs.conductance(h, Set(1:3)) == 1 / 8 + @test SimpleHypergraphs.conductance(h, Set([1, 4])) == 6 / 6 @test_throws ErrorException SimpleHypergraphs.conductance(h, Set{Int}()) @test_throws ErrorException SimpleHypergraphs.conductance(h, Set(1:nhv(h))) end;