exploring the diagonality score of square matrices
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
### A Pluto.jl notebook ### | |
# v0.12.4 | |
using Markdown | |
using InteractiveUtils | |
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). | |
macro bind(def, element) | |
quote | |
local el = $(esc(element)) | |
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing | |
el | |
end | |
end | |
# ╔═╡ 2dcd4186-1fd3-11eb-30e6-9bc12560044e | |
begin | |
using Pkg | |
for package in ["LinearAlgebra", "StatsBase", "Statistics", "Plots", "PlutoUI"] | |
package ∉ keys(Pkg.project().dependencies) && Pkg.add(package) | |
end | |
using LinearAlgebra, Statistics | |
using StatsBase | |
using Plots | |
using PlutoUI | |
end | |
# ╔═╡ fe42c2d0-1fd3-11eb-3fc6-ab63568843e1 | |
md""" | |
We set the parameters for both our network (it's row and column dimension) and the rectangular distance function | |
- Richness of web = $(@bind Size NumberField(10:200)) | |
- α = $(@bind α Slider(0.1:0.1:0.9)) | |
- k = $(@bind k Slider(1:1:20)) | |
Your choices: | |
$(Size, α, k) | |
""" | |
# ╔═╡ 10954948-22d2-11eb-16c5-497f13dfc359 | |
md""" | |
Then we define a function distance however we want: | |
""" | |
# ╔═╡ ca3dd95c-1fd3-11eb-3935-131c0a463f48 | |
diag_dist = (x,y) -> abs.(x .- y) | |
# ╔═╡ de5026de-1fd3-11eb-33b9-172e25478a8c | |
function diagonal_scores(Msize::T, α::F = 0.25, k::T = 3) where {T <: Int, F <: Number} | |
Mdists = Array{Float64}(undef, Msize, Msize) | |
for i in 1:Msize | |
Mdists[i,:] .= α .^ diag_dist(i,1:Msize) | |
end | |
Mdists[Mdists .< α^k] .= 0 | |
return Mdists | |
end | |
# ╔═╡ c57f9ef0-1fd5-11eb-1314-d1fc09203626 | |
heatmap(diagonal_scores(Size, α, k)) | |
# ╔═╡ Cell order: | |
# ╟─fe42c2d0-1fd3-11eb-3fc6-ab63568843e1 | |
# ╟─10954948-22d2-11eb-16c5-497f13dfc359 | |
# ╠═ca3dd95c-1fd3-11eb-3935-131c0a463f48 | |
# ╠═c57f9ef0-1fd5-11eb-1314-d1fc09203626 | |
# ╠═de5026de-1fd3-11eb-33b9-172e25478a8c | |
# ╠═2dcd4186-1fd3-11eb-30e6-9bc12560044e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment