Improve random vector generator
This commit is contained in:
parent
abc53b4705
commit
7e94fef19e
@ -8,13 +8,28 @@ export rand_on_shell, Q, DescentHistory, realize_gram
|
|||||||
|
|
||||||
# === guessing ===
|
# === guessing ===
|
||||||
|
|
||||||
##[TO DO] write a test to confirm that the outputs are on the correct shells
|
sconh(t, u) = 0.5*(exp(t) + u*exp(-t))
|
||||||
##[TO DO] this can fail at generating spacelike vectors
|
|
||||||
function rand_on_shell(rng::AbstractRNG, shells::Array{T}) where T <: Number
|
function rand_on_sphere(rng::AbstractRNG, ::Type{T}, n) where T
|
||||||
space_parts = randn(rng, T, 4, size(shells, 1))
|
out = randn(rng, T, n)
|
||||||
space_self_prods = [dot(x, x) for x in eachcol(space_parts)]
|
tries_left = 2
|
||||||
return [space_parts; sqrt.(space_self_prods .- shells)']
|
while dot(out, out) < 1e-6 && tries_left > 0
|
||||||
|
out = randn(rng, T, n)
|
||||||
|
tries_left -= 1
|
||||||
end
|
end
|
||||||
|
normalize(out)
|
||||||
|
end
|
||||||
|
|
||||||
|
##[TO DO] write a test to confirm that the outputs are on the correct shells
|
||||||
|
function rand_on_shell(rng::AbstractRNG, shell::T) where T <: Number
|
||||||
|
space_part = rand_on_sphere(rng, T, 4)
|
||||||
|
rapidity = randn(rng, T)
|
||||||
|
sig = sign(shell)
|
||||||
|
[sconh(rapidity, sig)*space_part; sconh(rapidity, -sig)]
|
||||||
|
end
|
||||||
|
|
||||||
|
rand_on_shell(rng::AbstractRNG, shells::Array{T}) where T <: Number =
|
||||||
|
hcat([rand_on_shell(rng, sh) for sh in shells]...)
|
||||||
|
|
||||||
rand_on_shell(shells::Array{<:Number}) = rand_on_shell(Random.default_rng(), shells)
|
rand_on_shell(shells::Array{<:Number}) = rand_on_shell(Random.default_rng(), shells)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user