Skip to content

Commit 794fb77

Browse files
committed
Update circular.jl
1 parent 8b2b26e commit 794fb77

File tree

1 file changed

+164
-12
lines changed

1 file changed

+164
-12
lines changed

notebooks/circular.jl

+164-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ macro bind(def, element)
1515
end
1616

1717
# ╔═╡ 6486e004-c95b-4fcd-936e-6508a0e0283c
18-
using LinearAlgebra, StatsBase, PlutoUI
18+
using LinearAlgebra, StatsBase, PlutoUI, GenericLinearAlgebra
1919

2020
# ╔═╡ fab8681e-0be3-4d97-a0cb-2ad57472282a
2121
using Plots
2222

23+
# ╔═╡ 5fcb9846-0a0d-4517-8eff-90f580172b82
24+
using Quaternions
25+
2326
# ╔═╡ 5455f492-7c41-11ef-3315-19809ebaffc3
2427
function circular(n,β)
2528

@@ -41,6 +44,9 @@ UpperHessenberg(z)
4144
end
4245

4346

47+
# ╔═╡ db8c16a0-79df-4cc0-9c69-a6bcfcd23a1c
48+
circular(3,2)
49+
4450
# ╔═╡ f9f00c9d-633a-4734-838f-3ffdcef6efe0
4551
@bind β Slider([.5,1,4,10,100,1000,1e10]; default=1, show_value=true)
4652

@@ -68,53 +74,163 @@ function circular2(n)
6874
end
6975

7076
# ╔═╡ 148317c1-e48f-4d39-833c-b51d2c43e5fd
71-
function circular1(n)
77+
function circular1(n) #β=1
7278
A = randn(n,n) .+ im * randn(n,n)
7379
U = qr(A).Q * transpose( Matrix(qr(A).Q ))
7480
end
7581

76-
# ╔═╡ e14122da-9861-401c-bb56-3693b25e6e15
77-
circular2(5)
78-
7982
# ╔═╡ 5cd13d1b-9bb4-4a19-9e6a-07e214572639
83+
# ╠═╡ disabled = true
84+
#=╠═╡
8085
let
8186
n = 5
82-
t = 50_000
87+
t = 50
8388
m = [ smallabs(circular2(n)) for i=1:t]
8489
display((mean(m),var(m)))
8590
stephist(m,normalize=true,label="dense")
8691
mh = [ smallabs(circular(n,2)) for i=1:t]
8792
display((mean(mh),var(mh)))
88-
stephist!(mh,normalize=true,label="Hessenberg")
89-
93+
title!("β=2 n=$n t=$t")
94+
stephist!(mh,normalize=true,label="Hessenberg")
9095
end
96+
╠═╡ =#
9197

9298
# ╔═╡ 63bf73bf-b312-49cc-a909-c043bfc80fd1
9399
circular1(5)
94100

95101
# ╔═╡ 82ce98e9-37a9-4023-ac62-5c092a8fa932
102+
# ╠═╡ disabled = true
103+
#=╠═╡
96104
let
97-
n = 5
98-
t = 50_000
105+
n = 10
106+
t = 50
99107
m = [ smallabs(circular1(n)) for i=1:t]
100108
display((mean(m),var(m)))
101109
stephist(m,normalize=true,label="dense")
102110
mh = [ smallabs(circular(n,1)) for i=1:t]
103111
display((mean(mh),var(mh)))
112+
title!("β=1 n=$n t=$t")
113+
stephist!(mh,normalize=true,label="Hessenberg")
114+
end
115+
╠═╡ =#
116+
117+
# ╔═╡ 686fae20-6ed7-444c-9085-0f97d8432303
118+
function circularm(n,β)
119+
e = eigvals(circular(n,β))
120+
m2 = sum(e.^2)
121+
m11 = (sum(e)^2-m2)/2
122+
(m2,m11)
123+
end
124+
125+
# ╔═╡ 5ede4dd3-c432-4108-b22d-ab72200f91f1
126+
127+
128+
# ╔═╡ aaa6835c-7d8f-4208-ab5d-0b06de61dbb8
129+
let
130+
n = 3
131+
t = 10000
132+
β = 5 #-4/5
133+
# β = 1 # -1
134+
# β = 2 # -1
135+
v = [ circularm(n,β) for i=1:t]
136+
# m2 = mean(first.(v))
137+
# m11 = mean(last.(v))
138+
# mean( first.(v) .* conj.(last.(v)))
139+
# 3/mean(abs.(last.(v)).^2) - 1 # 3/|m11|²-1 = β
140+
141+
mean(first.(v).*conj(last.(v))) , -6β/( (β+1)*+2))
142+
end
143+
144+
# ╔═╡ dd7e4afa-323e-4287-a8a0-f1448fb669ac
145+
5/7
146+
147+
# ╔═╡ fb3ec55c-db9f-4897-b4d0-3a07a3ba859c
148+
# ╠═╡ disabled = true
149+
#=╠═╡
150+
let
151+
n = 5
152+
β = 50000
153+
t = 50
154+
mh = [ smallabs(circular(n,β)) for i=1:t] * 180/π
155+
display((mean(mh),var(mh)))
156+
stephist(mh,normalize=true,label="Hessenberg")
157+
title!("β=$β n=$n t=$t")
158+
end
159+
╠═╡ =#
160+
161+
# ╔═╡ 37236855-5f7d-4d4a-8046-116a51dbae7f
162+
function circular4(n) #β=4
163+
A = randn(2n,2n) + im * randn(2n, 2n)
164+
U = Matrix(qr(A).Q).* cis.(2π*rand(2n))
165+
Z = kron( [0 -1;1 0], Matrix(I,n,n) )
166+
-Z * transpose(U) * Z * U
167+
end
168+
169+
# ╔═╡ 2443d72e-42f4-4f66-8170-04633f9b9031
170+
M = circular4(2)
171+
172+
# ╔═╡ 662e1079-13d9-4c26-b359-96556bbf75ee
173+
ℍ2ℂ(q::Quaternion) = [q.s+im*q.v1 q.v2+im*q.v3
174+
-q.v2+im*q.v3 q.s-im*q.v1 ]
175+
176+
# ╔═╡ b11d81bd-b6d7-4325-9012-c65efb859d02
177+
ℍ2ℂ(M::Matrix) = hvcat(size(M,1),ℍ2ℂ.(M)...)
178+
179+
# ╔═╡ a173bcd2-c02a-4897-9fbe-b7bde52f354b
180+
negatej(q::Quaternion) = Quaternion(q.s,q.v1,-q.v2,q.v3)
181+
182+
# ╔═╡ 61e9b1b5-95c5-4974-83b6-53387e93ded6
183+
function jdual(M)
184+
negatej.(transpose(M))
185+
end
186+
187+
# ╔═╡ b58a06f2-ad63-4742-abf8-bf491842b1f2
188+
function circular4q(n) #β=4
189+
A = quat.( randn(n,n), randn(n,n), randn(n,n), randn(n,n))
190+
U = quat(0,0,1,0) * Matrix(qr(A).Q) * quat(0,0,1,0) * jdual(Matrix(qr(A).Q)) #<-- this might be right
191+
end
192+
193+
# ╔═╡ 5e4d9a97-db38-445e-8982-7813b9656546
194+
let
195+
n = 5
196+
t = 5000
197+
m = [ smallabs(circular4(n)) for i=1:t]
198+
199+
stephist(m,normalize=true,label="dense")
200+
mh = [ smallabs(circular(n,4)) for i=1:t]
201+
mq = [ smallabs(ℍ2ℂ(circular4q(n))) for i=1:t]
202+
title!("β=4 n=$n t=$t")
104203
stephist!(mh,normalize=true,label="Hessenberg")
204+
stephist!(mq,normalize=true,label="Quaternionic Way")
105205
end
106206

207+
# ╔═╡ d426a597-d198-4d16-9ca1-4600c84d968f
208+
Z = circular4q(3)
209+
210+
# ╔═╡ b17edbda-3a23-48a1-8413-2a5350a29e86
211+
eigvals(ℍ2ℂ(Z))
212+
213+
# ╔═╡ 228f2a0c-2a52-432d-9dda-45f22dda4a4a
214+
A = [quat( [rand(1:5) for i=1:4]...) for i=1:2,j=1:2]
215+
216+
# ╔═╡ bc6bb958-7b18-4324-bc1d-644d543f9842
217+
jdual(A)
218+
107219
# ╔═╡ 00000000-0000-0000-0000-000000000001
108220
PLUTO_PROJECT_TOML_CONTENTS = """
109221
[deps]
222+
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
110223
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
111224
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
112225
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
226+
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
113227
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
114228
115229
[compat]
230+
GenericLinearAlgebra = "~0.3.13"
116231
Plots = "~1.40.8"
117232
PlutoUI = "~0.7.60"
233+
Quaternions = "~0.7.5"
118234
StatsBase = "~0.34.3"
119235
"""
120236

@@ -124,7 +240,7 @@ PLUTO_MANIFEST_TOML_CONTENTS = """
124240
125241
julia_version = "1.10.4"
126242
manifest_format = "2.0"
127-
project_hash = "7b8203dbbe986d66cb4ddfe6db1b6ccaff902edb"
243+
project_hash = "d5477210c2247950b3cde5a6471f10197fb68f21"
128244
129245
[[deps.AbstractPlutoDingetjes]]
130246
deps = ["Pkg"]
@@ -339,6 +455,12 @@ git-tree-sha1 = "a8863b69c2a0859f2c2c87ebdc4c6712e88bdf0d"
339455
uuid = "d2c73de3-f751-5644-a686-071e5b155ba9"
340456
version = "0.73.7+0"
341457
458+
[[deps.GenericLinearAlgebra]]
459+
deps = ["LinearAlgebra", "Printf", "Random", "libblastrampoline_jll"]
460+
git-tree-sha1 = "f47136cac29a9b7a8a88dbce1195394978091edb"
461+
uuid = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
462+
version = "0.3.13"
463+
342464
[[deps.Gettext_jll]]
343465
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
344466
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
@@ -778,6 +900,12 @@ git-tree-sha1 = "729927532d48cf79f49070341e1d918a65aba6b0"
778900
uuid = "e99dba38-086e-5de3-a5b1-6e4c66e897c3"
779901
version = "6.7.1+1"
780902
903+
[[deps.Quaternions]]
904+
deps = ["LinearAlgebra", "Random", "RealDot"]
905+
git-tree-sha1 = "9a46862d248ea548e340e30e2894118749dc7f51"
906+
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
907+
version = "0.7.5"
908+
781909
[[deps.REPL]]
782910
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
783911
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
@@ -786,6 +914,12 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
786914
deps = ["SHA"]
787915
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
788916
917+
[[deps.RealDot]]
918+
deps = ["LinearAlgebra"]
919+
git-tree-sha1 = "9f0a1b71baaf7650f4fa8a1d168c7fb6ee41f0c9"
920+
uuid = "c1ae055f-0cd5-4b69-90a6-9a35b1a98df9"
921+
version = "0.1.0"
922+
789923
[[deps.RecipesBase]]
790924
deps = ["PrecompileTools"]
791925
git-tree-sha1 = "5c3d09cc4f31f5fc6af001c250bf1278733100ff"
@@ -1249,15 +1383,33 @@ version = "1.4.1+1"
12491383
# ╠═6486e004-c95b-4fcd-936e-6508a0e0283c
12501384
# ╠═fab8681e-0be3-4d97-a0cb-2ad57472282a
12511385
# ╠═5455f492-7c41-11ef-3315-19809ebaffc3
1386+
# ╠═db8c16a0-79df-4cc0-9c69-a6bcfcd23a1c
12521387
# ╠═f9f00c9d-633a-4734-838f-3ffdcef6efe0
12531388
# ╠═e4418523-234c-4faa-a29b-43484013b322
12541389
# ╠═63cd9672-d3d2-4b2a-8076-f98b60dc11e6
12551390
# ╠═02db4122-8e3c-477c-b1ef-d9c236787910
12561391
# ╠═14b4a088-ff74-43f3-b301-4057593c0447
12571392
# ╠═148317c1-e48f-4d39-833c-b51d2c43e5fd
1258-
# ╠═e14122da-9861-401c-bb56-3693b25e6e15
1393+
# ╠═2443d72e-42f4-4f66-8170-04633f9b9031
12591394
# ╠═5cd13d1b-9bb4-4a19-9e6a-07e214572639
12601395
# ╠═63bf73bf-b312-49cc-a909-c043bfc80fd1
12611396
# ╠═82ce98e9-37a9-4023-ac62-5c092a8fa932
1397+
# ╠═5e4d9a97-db38-445e-8982-7813b9656546
1398+
# ╠═d426a597-d198-4d16-9ca1-4600c84d968f
1399+
# ╠═b17edbda-3a23-48a1-8413-2a5350a29e86
1400+
# ╠═686fae20-6ed7-444c-9085-0f97d8432303
1401+
# ╠═5ede4dd3-c432-4108-b22d-ab72200f91f1
1402+
# ╠═aaa6835c-7d8f-4208-ab5d-0b06de61dbb8
1403+
# ╠═dd7e4afa-323e-4287-a8a0-f1448fb669ac
1404+
# ╠═5fcb9846-0a0d-4517-8eff-90f580172b82
1405+
# ╠═fb3ec55c-db9f-4897-b4d0-3a07a3ba859c
1406+
# ╠═37236855-5f7d-4d4a-8046-116a51dbae7f
1407+
# ╠═662e1079-13d9-4c26-b359-96556bbf75ee
1408+
# ╠═b11d81bd-b6d7-4325-9012-c65efb859d02
1409+
# ╠═a173bcd2-c02a-4897-9fbe-b7bde52f354b
1410+
# ╠═61e9b1b5-95c5-4974-83b6-53387e93ded6
1411+
# ╠═b58a06f2-ad63-4742-abf8-bf491842b1f2
1412+
# ╠═228f2a0c-2a52-432d-9dda-45f22dda4a4a
1413+
# ╠═bc6bb958-7b18-4324-bc1d-644d543f9842
12621414
# ╟─00000000-0000-0000-0000-000000000001
12631415
# ╟─00000000-0000-0000-0000-000000000002

0 commit comments

Comments
 (0)