-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hamming distance starting node labels (#47)
Refactor and add original method to find initial node labels from paper
- Loading branch information
Showing
16 changed files
with
492 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
function select_bandwidth(A::Array{T, 2}; type = "degs", alpha = 1, c = 1)::Int where {T} | ||
h = oracle_bandwidth(A, type, alpha, c) | ||
return max(2, min(size(A)[1], round(Int, h))) | ||
end | ||
|
||
function select_bandwidth(A::Array{T, 3}; type = "degs", alpha = 1, c = 1)::Int where {T} | ||
hs = [select_bandwidth(A[:, :, i]; type, alpha, c) for i in 1:size(A, 3)] | ||
@warn "Naive bandwidth selection for multilayer graph histogram: using minimum over layers" | ||
h = max(2, min(size(A, 1), round(Int, minimum(hs)))) | ||
return h | ||
end | ||
|
||
""" | ||
oracle_bandwidth(A, type = "degs", alpha = 1, c = min(4, sqrt(size(A, 1)) / 8)) | ||
Oracle bandwidth selection for graph histogram, using | ||
```math | ||
\\widehat{h^*}=\\left(2\\left(\\left(d^T d\\right)^{+}\\right)^2 d^T A d \\cdot \\hat{m} \\hat{b}\\right)^{-\\frac{1}{2}} \\hat{\\rho}_n^{\\frac{1}{4}}, | ||
``` | ||
where ``d`` is the vector of degree sorted in increasing order,``\\hat{\\rho}_n`` is the empirical edge density, and ``m``, ``b`` are the slope and intercept fitted on ``d[n/2-c\\sqrt{n}:n/2+c\\sqrt{n}]`` for some ``c``. | ||
""" | ||
function oracle_bandwidth(A, type = "degs", alpha = 1, c = min(4, sqrt(size(A, 1)) / 8)) | ||
if type ∉ ["eigs", "degs"] | ||
error("Invalid input type $(type)") | ||
end | ||
|
||
if alpha != 1 | ||
error("Currently only supports alpha = 1") | ||
end | ||
|
||
n = size(A, 1) | ||
midPt = collect(max(1, round(Int, (n ÷ 2 - c * sqrt(n)))):round(Int, | ||
(n ÷ 2 + c * sqrt(n)))) | ||
rhoHat_inv = inv(sum(A) / (n * (n - 1))) | ||
|
||
# Rank-1 graphon estimate via fhat(x,y) = mult*u(x)*u(y)*pinv(rhoHat); | ||
if type == "eigs" | ||
eig_res = eigs(A, nev = 1, which = :LM) | ||
u = eig_res.vectors | ||
mult = eig_res.values[1] | ||
elseif type == "degs" | ||
u = sum(A, dims = 2) | ||
mult = (u' * A * u) / (sum(u .^ 2))^2 | ||
else | ||
error("Invalid input type $(type)") | ||
end | ||
|
||
# Calculation bandwidth | ||
u = sort(u, dims = 1) | ||
uMid = u[midPt] | ||
lmfit_coef = hcat(ones(length(uMid)), 1:length(uMid)) \ uMid | ||
|
||
h = (2^(alpha + 1) * alpha * mult^2 * | ||
(lmfit_coef[2] * length(uMid) / 2 + lmfit_coef[1])^2 * lmfit_coef[2]^2 * | ||
rhoHat_inv)^(-1 / (2 * (alpha + 1))) | ||
#estMSqrd = 2*mult^2*(lmfit_coef[2]*length(uMid)/2+lmfit_coef[1])^2*lmfit_coef[2]^2*rhoHat_inv^2*(n+1)^2 | ||
return h[1] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f6c7982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
f6c7982
There was a problem hiding this comment.
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/96057
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
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: