-
Notifications
You must be signed in to change notification settings - Fork 2
/
eval_maps.jl
84 lines (78 loc) · 2.16 KB
/
eval_maps.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using LinearAlgebra
function safer_sign(v::Vector{Float64})
sgn = sign(v[2])
if sgn == 0.0; return 1.0; end
return sgn
end
function _kth_largest_algebraic(M::Array{Float64,2}, k::Int64)
F = eigen(M)
d, V = F.values, F.vectors
j = sortperm(real.(d), rev=true)[k]
v = real.(V[:, j])
return v * safer_sign(v)
end
function kth_largest_algebraic(k::Int64)
ret(M::Array{Float64,2}) = _kth_largest_algebraic(M, k)
return ret
end
function largest_algebraic()
ret(M::Array{Float64,2}) = _kth_largest_algebraic(M, 1)
return ret
end
function _kth_smallest_algebraic(M::Array{Float64,2}, k::Int64)
F = eigen(M)
d, V = F.values, F.vectors
j = sortperm(real.(d))[k]
v = real.(V[:, j])
return v * safer_sign(v)
end
function kth_smallest_algebraic(k::Int64)
ret(M::Array{Float64,2}) = _kth_smallest_algebraic(M, k)
return ret
end
function smallest_algebraic()
ret(M::Array{Float64,2}) = _kth_smallest_algebraic(M, 1)
return ret
end
function _kth_largest_magnitude(M::Array{Float64,2}, k::Int64)
F = eigen(M)
d, V = F.values, F.vectors
j = sortperm(abs.(d), rev=true)[k]
v = real.(V[:, j])
return v * safer_sign(v)
end
function kth_largest_magnitude(k::Int64)
ret(M::Array{Float64,2}) = _kth_largest_magnitude(M, k)
return ret
end
function largest_magnitude()
ret(M::Array{Float64,2}) = _kth_largest_magnitude(M, 1)
return ret
end
function _kth_smallest_magnitude(M::Array{Float64,2}, k::Int64)
F = eigen(M)
d, V = F.values, F.vectors
j = sortperm(abs.(d))[k]
v = real.(V[:, j])
return v * safer_sign(v)
end
function kth_smallest_magnitude(k::Int64)
ret(M::Array{Float64,2}) = _kth_smallest_magnitude(M, k)
return ret
end
function smallest_magnitude()
ret(M::Array{Float64,2}) = _kth_smallest_magnitude(M, 1)
return ret
end
function _closest_in_angle(M::Array{Float64,2}, x::Vector{Float64})
V = eigen(M).vectors
angles = abs.(vec(x' * V))
j = findmax(angles)[2]
v = real.(V[:, j])
return v * safer_sign(v)
end
function closest_in_angle(x::Vector{Float64})
ret(M::Array{Float64,2}) = _closest_in_angle(M, x)
return ret
end
;