-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a numerical checks for retractions and their inverses (#187)
* Initial implementation, moving several methods over form Manopt * Unify loading and move. the last common type to the utils module. * Add documentation. * Update paper badge. * add vector check. * update News.md. * Apply suggestions from code review --------- Co-authored-by: Mateusz Baran <[email protected]>
- Loading branch information
1 parent
830c5a1
commit 9d1af44
Showing
23 changed files
with
1,435 additions
and
631 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,54 @@ | ||
name = "ManifoldsBase" | ||
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb" | ||
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"] | ||
version = "0.15.8" | ||
version = "0.15.9" | ||
|
||
[deps] | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" | ||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
Requires = "ae029012-a4dd-5104-9daa-d747884805df" | ||
|
||
[weakdeps] | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
|
||
[extensions] | ||
ManifoldsBasePlotsExt = "Plots" | ||
ManifoldsBaseRecursiveArrayToolsExt = "RecursiveArrayTools" | ||
ManifoldsBaseStatisticsExt = "Statistics" | ||
|
||
[compat] | ||
Aqua = "0.8" | ||
DoubleFloats = ">= 0.9.2" | ||
ForwardDiff = "0.10" | ||
julia = "1.6" | ||
LinearAlgebra = "1.6" | ||
Markdown = "1.6" | ||
OrdinaryDiffEq = "6" | ||
Plots = "1" | ||
Printf = "1.6" | ||
Random = "1.6" | ||
RecursiveArrayTools = "2, 3" | ||
Requires = "1" | ||
ReverseDiff = "1" | ||
StaticArrays = "1" | ||
Statistics = "1.6" | ||
Test = "1.6" | ||
julia = "1.6" | ||
|
||
[extras] | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78" | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" | ||
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "Aqua", "DoubleFloats", "ForwardDiff", "OrdinaryDiffEq", "ReverseDiff", "StaticArrays", "RecursiveArrayTools"] | ||
test = ["Test", "Aqua", "DoubleFloats", "ForwardDiff", "OrdinaryDiffEq", "Plots", "ReverseDiff", "StaticArrays", "Statistics", "RecursiveArrayTools"] |
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,23 @@ | ||
# Numerical Verification | ||
|
||
```@autodocs | ||
Modules = [ManifoldsBase] | ||
Pages = ["src/numerical_checks.jl"] | ||
Order = [:macro, :type, :function] | ||
Private = false | ||
Public = true | ||
``` | ||
|
||
## Internal functions | ||
|
||
The following functions split the check into several parts, for | ||
example looking for the best fitting window and finding out the best slope, | ||
or plotting the slope. | ||
|
||
```@autodocs | ||
Modules = [ManifoldsBase] | ||
Pages = ["src/numerical_checks.jl"] | ||
Order = [:macro, :type, :function] | ||
Private = true | ||
Public = false | ||
``` |
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,62 @@ | ||
module ManifoldsBasePlotsExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using ManifoldsBase | ||
using Plots | ||
using Printf: @sprintf | ||
import ManifoldsBase: plot_slope | ||
else | ||
# imports need to be relative for Requires.jl-based workflows: | ||
# https://github.com/JuliaArrays/ArrayInterface.jl/pull/387 | ||
using ..ManifoldsBase | ||
using ..Plots | ||
using ..ManifoldsBase: @sprintf # is from Printf, but loaded in ManifoldsBase, and since Printf loading works here only on full moon days between 12 and noon, this trick might do it? | ||
import ..ManifoldsBase: plot_slope | ||
end | ||
|
||
function ManifoldsBase.plot_slope( | ||
x, | ||
y; | ||
slope = 2, | ||
line_base = 0, | ||
a = 0, | ||
b = 2.0, | ||
i = 1, | ||
j = length(x), | ||
) | ||
fig = plot( | ||
x, | ||
y; | ||
xaxis = :log, | ||
yaxis = :log, | ||
label = "\$E(t)\$", | ||
linewidth = 3, | ||
legend = :topleft, | ||
color = :lightblue, | ||
) | ||
s_line = [exp10(line_base + t * slope) for t in log10.(x)] | ||
plot!( | ||
fig, | ||
x, | ||
s_line; | ||
label = "slope s=$slope", | ||
linestyle = :dash, | ||
color = :black, | ||
linewidth = 2, | ||
) | ||
if (i != 0) && (j != 0) | ||
best_line = [exp10(a + t * b) for t in log10.(x[i:j])] | ||
plot!( | ||
fig, | ||
x[i:j], | ||
best_line; | ||
label = "best slope $(@sprintf("%.4f", b))", | ||
color = :blue, | ||
linestyle = :dot, | ||
linewidth = 2, | ||
) | ||
end | ||
return fig | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module ManifoldsBaseStatisticsExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using Statistics | ||
using ManifoldsBase | ||
import ManifoldsBase: find_best_slope_window | ||
else | ||
# imports need to be relative for Requires.jl-based workflows: | ||
# https://github.com/JuliaArrays/ArrayInterface.jl/pull/387 | ||
using ..Statistics | ||
using ..ManifoldsBase | ||
import ..ManifoldsBase: find_best_slope_window | ||
end | ||
|
||
function ManifoldsBase.find_best_slope_window( | ||
X, | ||
Y, | ||
window = nothing; | ||
slope::Real = 2.0, | ||
slope_tol::Real = 0.1, | ||
) | ||
n = length(X) | ||
if window !== nothing && (any(window .> n)) | ||
error( | ||
"One of the window sizes ($(window)) is larger than the length of the signal (n=$n).", | ||
) | ||
end | ||
a_best = 0 | ||
b_best = -Inf | ||
i_best = 0 | ||
j_best = 0 | ||
r_best = 0 # longest interval | ||
for w in (window === nothing ? (2:n) : [window...]) | ||
for j in 1:(n - w + 1) | ||
x = X[j:(j + w - 1)] | ||
y = Y[j:(j + w - 1)] | ||
# fit a line a + bx | ||
c = cor(x, y) | ||
b = std(y) / std(x) * c | ||
a = mean(y) - b * mean(x) | ||
# look for the largest interval where b is within slope tolerance | ||
r = (maximum(x) - minimum(x)) | ||
if (r > r_best) && abs(b - slope) < slope_tol #longer interval found. | ||
r_best = r | ||
a_best = a | ||
b_best = b | ||
i_best = j | ||
j_best = j + w - 1 #last index (see x and y from before) | ||
end | ||
# not best interval - maybe it is still the (first) best slope? | ||
if r_best == 0 && abs(b - slope) < abs(b_best - slope) | ||
# but do not update `r` since this indicates only a best r | ||
a_best = a | ||
b_best = b | ||
i_best = j | ||
j_best = j + w - 1 #last index (see x and y from before) | ||
end | ||
end | ||
end | ||
return (a_best, b_best, i_best, j_best) | ||
end | ||
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
Oops, something went wrong.