Documentation
Documentation for SymplecticMapTools.jl
Contents
Index
SymplecticMapTools.BRREsolution
SymplecticMapTools.ConnectingOrbit
SymplecticMapTools.ContFrac
SymplecticMapTools.FourierCircle
SymplecticMapTools.FourierTorus
SymplecticMapTools.InvariantCircle
SymplecticMapTools.KernelLabel
Base.getindex
Base.getindex
Base.length
Base.setindex!
Base.setindex!
MakieCore.lines!
RecipesBase.plot
RecipesBase.plot
RecipesBase.plot!
RecipesBase.plot!
SymplecticMapTools.BFGS_periodic
SymplecticMapTools.adaptive_birkhoff_extrapolation
SymplecticMapTools.adaptive_get_torus!
SymplecticMapTools.area
SymplecticMapTools.area
SymplecticMapTools.average_radius
SymplecticMapTools.big_cont_frac_eval
SymplecticMapTools.big_denoms
SymplecticMapTools.big_partial_frac
SymplecticMapTools.birkhoff_extrapolation
SymplecticMapTools.circle_linear!
SymplecticMapTools.denoms
SymplecticMapTools.deriv
SymplecticMapTools.deval
SymplecticMapTools.deval
SymplecticMapTools.deval
SymplecticMapTools.doubling_birkhoff_average
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate
SymplecticMapTools.evaluate_on_grid
SymplecticMapTools.get_Am
SymplecticMapTools.get_Na
SymplecticMapTools.get_Na
SymplecticMapTools.get_a0
SymplecticMapTools.get_am
SymplecticMapTools.get_circle_residual
SymplecticMapTools.get_energies
SymplecticMapTools.get_matrix
SymplecticMapTools.get_p
SymplecticMapTools.get_p
SymplecticMapTools.get_sum_ave
SymplecticMapTools.get_w0!
SymplecticMapTools.get_τ
SymplecticMapTools.gn_circle
SymplecticMapTools.gn_connecting!
SymplecticMapTools.kam_residual
SymplecticMapTools.kam_residual_rnorm
SymplecticMapTools.kernel_birkhoff
SymplecticMapTools.kernel_bvp
SymplecticMapTools.kernel_eigs
SymplecticMapTools.kernel_sample_F
SymplecticMapTools.linear_initial_connecting_orbit
SymplecticMapTools.lines_periodic!
SymplecticMapTools.load_rre
SymplecticMapTools.lyapunov_exponent
SymplecticMapTools.lyapunov_exponents
SymplecticMapTools.newton_periodic
SymplecticMapTools.parametric_plot
SymplecticMapTools.partial_frac
SymplecticMapTools.plot_on_grid
SymplecticMapTools.poincare_plot
SymplecticMapTools.polar_map
SymplecticMapTools.rectangular_window_weight
SymplecticMapTools.save_rre
SymplecticMapTools.set_Am!
SymplecticMapTools.set_a0!
SymplecticMapTools.set_am!
SymplecticMapTools.set_τ!
SymplecticMapTools.shifted_eval
SymplecticMapTools.standard_map_F
SymplecticMapTools.standard_map_FJ
SymplecticMapTools.sum_stats
SymplecticMapTools.vector_rre_backslash
SymplecticMapTools.wba_weight
SymplecticMapTools.weighted_birkhoff_average
SymplecticMapTools.window_weight
Periodic Orbits
SymplecticMapTools.BFGS_periodic
— MethodBFGS_periodic(FJ::Function, x::AbstractVector, q::Integer;
maxiter::Integer=50)
Find a periodic orbit using BFGS from the Optim package.
Arguments:
FJ
: A function that returns the map and its derivativeF, dFdx = FJ(x)
x
: An initial point to find the orbit fromq
: The period of the orbitmaxiter=50
: The maximum number of optimization steps allows
Output:
xs
: A periodic trajectory of lengthd
res
: An Optim return object, (can check convergence withOptim.converged(res)
)
SymplecticMapTools.newton_periodic
— Methodnewton_periodic(FJ::Function, x::AbstractVector, q::Integer;
maxiter::Integer=50, rtol::Number=1e-8, verbose::Bool=false)
Find a periodic orbit using Newton's method with line search
Arguments:
FJ
: A function that returns the map and its derivativeF, dFdx = FJ(x)
x
: An initial point to find the orbit fromq
: The period of the orbitmaxiter=50
: The maximum number of optimization steps allowsrtol=1e-8
: The residual tolerance requiredverbose=false
: If true, outputs information about convergence
Output:
xs
: A periodic trajectory of lengthd
converged
: A flag that indicates whether the orbit converged inmaxiter
steps
Invariant Circles
SymplecticMapTools.InvariantCircle
— Typeabstract type InvariantCircle
An abstract type representing a chain of invariant circles zᵢ where zᵢ₊₁ = F(zᵢ) for i<=p and z₀ = F(zₚ₋₁). The main implementation of this type of FourierCircle, but other potential implementations of circles could exist.
Implementations should have the following functions for immediate portability:
Basic stuff
- Initializer
InvariantCircleImplementation(stuff)
- Similar
Base.similar(z::InvariantCircle)
Getters and Setters
- Get number of unknown variables per circle get_N(z::InvariantCircle)
- Get period of circle get_p(z::InvariantCircle)
- Get parameters (except τ)
get_a(z::InvariantCircle)
- Set parameters (except τ)
set_a!(z::InvariantCircle, a::AbstractArray)
- Get rotation number τ in [0,2π)
get_τ(z::InvariantCircle)
- Set τ
set_τ!(z::InvariantCircle, τ::Number)
Evaluation related routines
- Evaluate the circle (see
(z::InvariantCircle)(θ, i_circle)
)evaluate(z::InvariantCircle, θ::AbstractVector; i_circle::Integer=1)
- Evaluate the derivative of the circle w.r.t. θ
deval(z::InvariantCircle, θ::AbstractVector; i_circle::Integer=1)
- Get a basis Φ for z evaluated at Nθ equispaced points (requires linearity)
get_Φ(z::InvariantCircle, Nθ::Integer; τ::Number=0.0)
- Evaluate the invariant circle on Φ
function grid_eval!(x::AbstractArray, z::InvariantCircle, Φ::AbstractArray;
i_circle=0)
- Evaluate the derivative of the invariant circle on Φ
grid_deval!(dx::AbstractArray, z::InvariantCircle, Φ::AbstractArray;
i_circle=0)
Constraints (for Newton iteration)
- Constrain the value at 0
fixed_θ0_constraint(z::InvariantCircle)
Other routines (useful for continuation)
- Get average radius
LinearAlgebra.average_radius(z::InvariantCircle)
- Get the area of the invariant circle
area(z::InvariantCircle; i_circle=1, Ns = 100)
SymplecticMapTools.evaluate
— Methodevaluate(z::InvariantCircle, θ::Number; i_circle::Integer=1)
Evaluate the i_circle
th circle in z
at the point θ
SymplecticMapTools.deval
— Methoddeval(z::InvariantCircle, θ::Number; i_circle::Integer=1)
Evaluate the derivative of the i_circle
th circle in z
at the point θ
SymplecticMapTools.shifted_eval
— Functionshifted_eval(z::InvariantCircle, θ::AbstractVector; i_circle::Integer=1)
Evaluate the i_circle
th circle in z
at the point θ
, shifted by τ
SymplecticMapTools.get_circle_residual
— Functionget_circle_residual(F::Function, z::InvariantCircle, Nθ::Integer)
Get the KAM-like residual of a chain of p invariant circles.
> Rᵢ₁ = z₁(θᵢ+τ) - F(z_p(θᵢ))
> Rᵢⱼ = zⱼ(θᵢ) - F(zⱼ₋₁(θᵢ)) for 2<=j<=p
Arguments:
F
: Symplectic mapz
: Invariant circleNθ
: Number of θ points where the residual is taken
SymplecticMapTools.gn_circle
— Functiongn_circle(FJ::Function, z::InvariantCircle, Nθ::Integer;
maxiter::Integer=10, rtol::Number=1e-8, verbose::Bool=false,
monitor::Function=(z, rnorm) -> nothing,
constraint::Function=fixed_θ0_constraint, λ::Number=0)
Find an invariant circle using Gauss-Newton with linesearch. Implemented with dense linear algebra (no FFTs yet). Returns the number of iterations taken to converge. If an evaluation fails, returns -1
. If the routine fails to converge, returns -2
Arguments:
z::InvariantCircle
: An initial connecting orbit guess, seelinear_initial_connecting_orbit
FJ::Function
: Function defined on R² with signatureF(x), J(x) = FJ(x)
whereF
is the symplectic map andJ = dF/dx
Nθ
: Number of quadrature nodes for the least squaresmaxiter = 10
: Maximum number of Gauss Newton stepsrtol = 1e-8
: Stopping tolerance
Fourier Circles
SymplecticMapTools.FourierCircle
— TypeFourierCircle <: InvariantCircle
Constructors:
FourierCircle(Na::Integer; a::AbstractArray=[], τ::Number=0., p::Integer=1)
Fourier invariant circle data structure (see InvariantCircle), used to compute a circle z that is invariant of a map Fᵖ(z), where p is the period. This is done by storing all of the circles Fⁱ(z) for 0<=i<p. The circles are stored as Fourier series, i.e. z(θ) = a₀ + ∑₁ᴺᵃ Aⱼ [cos(jθ), sin(jθ)]ᵀ The coefficients of the invariant circle can be accessed and set in chunks via array indexing. That is, You can get and set a₀ of the ith circle using z[0, i]
You can get and set Aⱼ of the ith circle using z[j, i]
SymplecticMapTools.get_Na
— Methodget_Na(z::FourierCircle)
Get number of Fourier modes
SymplecticMapTools.get_p
— Methodget_p(z::FourierCircle)
Get number of islands
Base.length
— MethodBase.length(z::FourierCircle)
Get total number of parameters, excluding τ
SymplecticMapTools.get_a0
— Functionget_a0(z::FourierCircle; i_circle::Integer=1)
Get constant term of Fourier series of the i_circle
th circle in island chain
SymplecticMapTools.set_a0!
— Functionset_a0!(z::FourierCircle, a0::AbstractArray; i_circle::Integer=1)
Set constant term of Fourier series of the i_circle
th circle in island chain
SymplecticMapTools.get_Am
— Functionget_Am(z::FourierCircle, m::Integer; i_circle::Integer=1)
Get m
th Fourier coefficients of the i_circle
th circle in island chain
SymplecticMapTools.set_Am!
— Functionset_Am!(z::FourierCircle, m::Integer, a::AbstractArray; i_circle::Integer=1)
Set m
th Fourier coefficients of the i_circle
th circle in island chain
Base.getindex
— MethodBase.getindex(z::FourierCircle, i_A::Integer, i_circle::Integer)
Get the coefficients of z. z[0, i_circle]
gets the constant term. z[i_A, i_circle]
gets higher coefficients
Base.setindex!
— MethodBase.setindex!(z::FourierCircle, X::AbstractArray, i_A::Integer,
i_circle::Integer)
Set the coefficients of z. z[0, i_circle]
sets the constant term. z[i_A, i_circle]
sets higher coefficients
SymplecticMapTools.get_τ
— Functionget_τ(z::FourierCircle)
Get the rotation number (the circle is 2π periodic)
SymplecticMapTools.set_τ!
— Functionset_τ!(z::FourierCircle, τ::Number)
Set the rotation number (the circle is 2π periodic)
SymplecticMapTools.average_radius
— Methodaverage_radius(z::FourierCircle)
Norm defined as the L2 norm of the radius, i.e. ‖z‖² = 1/2πp ∫ ||z(θ) - a₀||^2 dθ = 1/2p ∑ₖ Tr(AₖᵀAₖ) If i_circle = 0
, takes the norm over all circles. If i_circle != 0
, finds the average radius of a single circle.
SymplecticMapTools.evaluate
— Methodevaluate(z::FourierCircle, θ::AbstractVector{T}; i_circle::Integer=1) where {T}
Evaluate the i_circle
th circle in the chain at a vector of points θ
SymplecticMapTools.deval
— Methoddeval(z::FourierCircle, θ::AbstractVector; i_circle::Integer=1)
Evaluate the derivative of the i_circle
th circle in the chain at a vector of points θ
SymplecticMapTools.deriv
— Methodderiv(z::FourierCircle)
Return the derivative of the FourierCircle, wrapped in a circle object
SymplecticMapTools.area
— Functionarea(z::FourierCircle; i_circle=1)
Get the area of the circle.
area(c::ConnectingOrbit; origin::AbstractArray=[0.0,0.0],
i_p::Integer=1, rtol=1e-8)
Get the "area" of a connecting orbit ∫₋₁¹ (x dy/ds - y dy/ds) ds
SymplecticMapTools.circle_linear!
— Functioncircle_linear!(z::FourierCircle, FJ::Function, x::AbstractArray, h::Number)
Fill z
's Fourier coefficients using a linearization about a stable periodic orbit. Useful for seeding continuation.
Arguments:
z
: An invariant circleFJ
: A function that returns the map and its derivativeF, dFdx = FJ(x)
x
: A periodic orbit ofF
h
: The average radius of the first linearized invariant circle
Fourier Tori
SymplecticMapTools.FourierTorus
— TypeFourierTorus <: InvariantTorus
Constructors:
FourierTorus(d::Integer, Na::Vector{<:Integer}; a::AbstractArray=[], τ::AbstractVector=[0.], p::Integer=1)
Fourier invariant torus data structure (see InvariantTorus), used to compute a torus z that is invariant of a map Fᵖ(z), where p is the period. This is done by storing all of the tori Fⁱ(z) for 0<=i<p. The tori are stored as Fourier series, i.e. z(θ) = a₀ + ∑₁ᴺᵃ Aⱼ [cos(jθ), sin(jθ)]ᵀ The coefficients of the invariant torus can be accessed and set in chunks via array indexing. That is, You can get and set a₀ of the ith torus using z[0, i]
You can get and set Aⱼ of the ith torus using z[j, i]
SymplecticMapTools.evaluate_on_grid
— Functionevaluate_on_grid(tor::FourierTorus, thetavecs::AbstractVector)
Evaluate the torus on a grid defined by the vector-of-vectors thetavecs
.
SymplecticMapTools.kam_residual
— Functionkam_residual(tor::FourierTorus, F::Function, thetavecs::AbstractVector)
Compute the function F(tor(θ))-tor(θ+τ)
on the grid defined by the vector-of-vectors thetavecs
. If the invariant torus was computed with a non-identity observable h
, then F
needs to be given by h ∘ F ∘ h^-1
.
SymplecticMapTools.kam_residual_rnorm
— Functionkam_residual_rnorm(tor::FourierTorus, F::Function, thetavecs::AbstractVector)
Compute a relative error of the KAM residual |F(tor(θ))-tor(θ+τ)|/|tor|
. If the invariant torus was computed with a non-identity observable h
, then F
needs to be given by h ∘ F ∘ h^-1
.
Connecting Orbits
SymplecticMapTools.ConnectingOrbit
— TypeConnectingOrbit(Na::Integer, p::Integer)
Initialize a connecting orbit consisting of p
segments cⱼ : [0,1] -> R². The endpoints cⱼ(0) and cⱼ(1) are both hyperbolic perodic orbits. The connecting orbits connect these, acting as the outer boundary of an island. The connecting orbits are parameterized by Chebyshev polynomials of degree Na
.
See linear_initial_connecting_orbit
and gn_connecting!
for functions to initialize and compute a connecting orbit.
SymplecticMapTools.get_Na
— Methodget_Na(c::ConnectingOrbit)
Get the polynomial degree of the connecting orbit.
SymplecticMapTools.get_p
— Methodget_p(c::ConnectingOrbit)
Get the period of the connecting orbit
SymplecticMapTools.get_am
— Methodget_am(c::ConnectingOrbit, m::Integer; i_p::Integer=1)
Get the m
th Chebyshev coefficient of the i_p
th connecting orbit
SymplecticMapTools.set_am!
— Methodset_am!(c::ConnectingOrbit, m::Integer, am::AbstractArray; i_p::Integer=1)
Set the m
th Chebyshev coefficient of the i_p
th connecting orbit
Base.getindex
— MethodBase.getindex(c::ConnectingOrbit, i_A::Integer, i_p::Integer)
Wrapper for get_am
.
Base.setindex!
— MethodBase.setindex!(c::ConnectingOrbit, X::AbstractArray, i_A::Integer, i_p::Integer)
Wrapper for set_am!
SymplecticMapTools.evaluate
— Methodevaluate(c::ConnectingOrbit, x::AbstractArray; i_p::Integer=1)
Evaluate the i_p
th connecting orbit at a set of points x[j]
in [0,1]
SymplecticMapTools.evaluate
— Methodevaluate(c::ConnectingOrbit, x::Number; i_p::Integer=1)
Evaluate the i_p
th connecting orbit at a point x
in [0,1]
SymplecticMapTools.deval
— Methoddeval(c::ConnectingOrbit, x::Number; i_p::Integer=1)
Evaluate the derivative of the i_p
th connecting orbit at a point x
in [0,1]
SymplecticMapTools.area
— Methodarea(c::ConnectingOrbit; origin::AbstractArray=[0.0,0.0],
i_p::Integer=1, rtol=1e-8)
Get the "area" of a connecting orbit ∫₋₁¹ (x dy/ds - y dy/ds) ds
SymplecticMapTools.linear_initial_connecting_orbit
— Functionlinear_initial_connecting_orbit(x0, x1, Na::Integer)
Initialize a ConnectingOrbit of degree Na
using the two hyperbolic orbits x0
and x1
of the form xn = [xn0, F(xn0), ..., F^(p-1)(xn0)]
.
SymplecticMapTools.gn_connecting!
— Functiongn_connecting!(c::ConnectingOrbit, FJ::Function, ends::AbstractArray;
Ns = 100, maxiters = 10, rtol = 1e-8, verbose=false)
Find a connecting orbit using Gauss Newton with linesearch.
Arguments:
c::ConnectingOrbit
: An initial connecting orbit guess, seelinear_initial_connecting_orbit
FJ::Function
: Function defined on R² with signatureF(x), J(x) = FJ(x)
whereF
is the symplectic map andJ = dF/dx
ends::AbstractArray
: A 2p × 2 matrix containing the end periodic orbits[x00, x10; F(x00), F(x10); ... ; F^(p-1)(x00), F^(p-1)(x10)]
Ns = 100
: Number of quadrature nodes for the least squaresmaxiters = 10
: Maximum number of Gauss Newton stepsrtol = 1e-8
: Stopping tolerance
Kernel Labels
SymplecticMapTools.KernelLabel
— TypeKernelLabel
Constructors:
KernelLabel(x::AbstractArray, c::AbstractVector, σ::Number;
kernel::Symbol=:SquaredExponential)
KernelLabel(x::AbstractArray, c::AbstractVector, σ::AbstractArray;
kernel::Symbol=:SquaredExponential)
An approximately invariant kernel label function.
Constructor elements:
x
: Thed
×2N
array of interpolating points, wherex[:, n+N] = F(x[:, n])
forn<=N
and some symplectic mapF
.c
: The length2N
vector of coefficients of the kernel functionσ
: The length scale of the kernel (if a vector, length scale is different in different directions)kernel
: The type of kernel used
The current supported kernels are:
:SquaredExponential
: The squared exponential kernel K(x, y) = exp(-|x-y|²):InverseMultiquadric
: The β=1 Inverse Multiquadric kernel K(x, y) = (1+|x-y|²)^(-1/2):FourierSE
: The Fourier × Cartesian squared exponential kernel K(x, y) = exp(-sin²(x₁-y₁) - (x₂-y₂)²):Fourier
: The Fourier × Fourier squared exponential kernel K(x, y) = exp(-sin²(x₁-y₁) - sin²(x₂-y₂))
SymplecticMapTools.get_matrix
— Methodget_matrix(k::KernelLabel, x::AbstractArray)
Get the kernel matrix K[i,j] = K(k.x[:,i], x[:,j])
SymplecticMapTools.evaluate
— Methodevaluate(k::KernelLabel, x::AbstractArray)
Evaluate the kernel matrix at the columns of x
SymplecticMapTools.window_weight
— Functionwindow_weight(xs::AbstractArray, lims::AbstractVector, α::Number;
ind::Integer=2)
A simple boundary weighting function for kernel_eigs
and kernel_bvp
. Returns a weight that is approximately 1 outside of lims
and 0 inside via the sum of two logistic functions.
Arguments:
xs
: Ad
×N
array of points, whered
is the size of the phase space andN
is the number of points.lims
: A 2-vector giving the interval where the weight is approximately 0α
: The length scale of the logistic functions (typically small relative to the size of the domain)ind=2
: The index over which the window is applied. Defaults to2
for maps on T×R (such as the standard map)
Output:
w
: AN
-vector with the window weights
SymplecticMapTools.rectangular_window_weight
— Functionrectangular_window_weight(xs::AbstractArray, xlims::AbstractVector,
ylims::AbstractVector, α::Number)
A simple boundary weighting function for kernel_eigs
and kernel_bvp
. Returns a weight that is approximately 1 outside of xlims
× ylims
and 0 inside via the a function of logistic functions.
Arguments:
xs
: Ad
×N
array of points, whered
is the size of the phase space andN
is the number of points.xlims
andylims
: 2-vectors giving the rectangle where the weight is approximately 0α
: The length scale of the logistic functions (typically small relative to the size of the domain)
Output:
w
: AN
-vector with the window weights
SymplecticMapTools.kernel_sample_F
— Functionkernel_sample_F(F::Function, N::Integer, xb::AbstractVector,
yb::AbstractVector)
Sobol sample N
points in the rectangle xb
× yb
. Then, evaluate F
at each point. Input can be used for kernel_eigs
and kernel_bvp
Arguments:
F
: The symplectic map from the state space to itselfN
: The number of points to be sampledxb
×yb
: The 2-vector bounds of the rectangle to be sampled
Output:
xs
: A2
×2N
array of samples compatable withkernel_eigs
andkernel_bvp
, of the form[x_1, F(x_1), x_2, F(x_2), ...]
SymplecticMapTools.kernel_eigs
— Functionkernel_eigs(xs::AbstractArray, ϵ::Number, nev::Integer, σ::Number,
boundary_weights::Vector; kernel::Symbol=:SquaredExponential,
zero_mean = false, check = 1)
Solve the the invariant eigenvalue problem, given by the Rayleigh quotient
> min_c (‖GKc‖² + ‖Kc‖²_bd + ϵ‖c‖²_k)/‖Kc‖²
where
‖GKc‖²
is a norm penalizing invariance (and possible a non-zero mean)‖Kc‖²_bd
is a norm penalizing boundary violation‖c‖²_k
is the smoothing kernel norm‖Kc‖²
is the ℓ² norm of the points
The eigenvalue problem is solved via Arpack.jl
Arguments:
xs
: interpolation points of size d × 2N, where xs[:, N+1:2N] = F.(xs[:, 1:N])ϵ
: Amount of regularizationnev
: Number of eigenvalues to findσ
: Kernel widthboundary_weights
: Boundary weighting vector, should be positive and O(1) at pointsx
where one wants |k(x)| << 1kernel
: Type of kernel to interpolate (seeKernelLabel
)zero_mean = false
: Set to true to add a constraint that encouragesk
to have a zero mean. Useful whenxs
are sampled on an invariant set and boundary_weights=0check = 1
: SeeArpack.eigs
. If 1, return all of the converged eigenvectors and eigenvalues. If 0, throw an error instead.
Output:
λs
: The eigenvaluesvs
: The eigenvectorsk
: The kernel label. Useset_c!(k, vs[:,n])
to load then
th eigenvector intok
. By default,k
stores the lowest order eigenvector.
SymplecticMapTools.kernel_bvp
— Functionkernel_bvp(xs::AbstractArray, ϵ::Number, σ::Number,
boundary_weights::AbstractVector,
boundary_values::AbstractVector;
kernel::Symbol=:SquaredExponential, residuals::Bool=true)
Solve the the invariant boundary value least-squares problem
> min_c ‖GKc‖² + ‖Kc - h_{bd}‖²_bd + ϵ‖c‖²_k = R_inv + R_bd + R_eps
where
‖GKc‖²
is a norm penalizing invariance (and possible a non-zero mean)‖Kc - h_{bd}‖²_bd
is a norm penalizing the function from violating the boundary condition‖c‖²_k
is the smoothing kernel norm
Arguments:
xs
: interpolation points of size d × 2N, where xs[:, N+1:2N] = F.(xs[:, 1:N])ϵ
: Amount of regularizationσ
: Kernel widthboundary_weights
: Length2N
boundary weighting vector, should be positive and O(1) at pointsx
where one wants |k(x)| << 1boundary_values
: Length2N
boundary value vector, indicating the value the function should take at each pointkernel=:SquaredExponential
: Type of kernel to interpolate (seeKernelLabel
)residuals=true
: True if you want the problem to return residuals.
Output:
k
: The kernel function
(if residuals=true
)
R
: The total residualR_bd
: The boundary condition residualR_inv
: The invariance residualR_eps
: The smoothness residual
SymplecticMapTools.get_energies
— Functionget_energies(k::KernelLabel; W = 0. * I)
Get the relevant energies of a kernel label k
with boundary weighting matrix W
.
Output energies:
EK = ‖c‖²_k
is the smoothing kernel normEInv = ‖GKc‖²
is a norm penalizing invarianceEbd = ‖Kc‖²_W
is a norm penalizing boundary violationEL2 = ‖Kc‖²
is the ℓ² norm of the points
SymplecticMapTools.kernel_birkhoff
— Functionkernel_birkhoff(xs::AbstractArray, fs::AbstractVector, ϵ::Number, μ::Number;
σ::Number=0., kernel::Symbol=:SquaredExponential,
boundary_points::AbstractVector = [])
This function is mostly deprecated. The solutions to the infinitely discretized limit of this problem (the Birkhoff average) don't live in the native space. So, the results can be odd, hard to interpret, and wiggly. Use at your own risk.
Find the "Birkhoff average" of a function using the kernel approach. Solves the least-squares problem
> min_c μ⁻¹(‖GKc‖² + ‖Kc‖²_bd) + ϵ‖c‖²_k + ‖Kc - f‖²
where
‖GKc‖²
is a norm penalizing invariance‖c‖²_k
is the smoothing kernel norm‖Kc - f‖²
is a least-squares fit norm‖Kc‖²_bd
is a norm penalizing boundary violation
Arguments:
xs
: interpolation points of size d × 2N, where xs[:, N+1:2N] = F.(xs[:, 1:N])fs
: function values at points of size Nϵ
: Amount of regularization (can be set to zero)μ
: Weighting of invariance penalization to fit (should be small, e.g. 1e-6)σ
: Scale of the problemkernel
: Type of kernel to interpolate (seeKernelLabel
)boundary_points
: A list of indices of points on the boundary
Output:
k
: A KernelLabel object
Continued Fractions
SymplecticMapTools.ContFrac
— TypeContFrac(a::AbstractArray)
A continued fraction in (0,1]. The member a
is a vector of the continued fraction coefficients so that ω = 1/(a[1] + 1/(a[2] + ...))
SymplecticMapTools.big_cont_frac_eval
— Functionbig_cont_frac_eval(c::ContFrac)
Find a high precision representation of the continued fraction as a BigFloat
. To set the precision, use precision
.
SymplecticMapTools.evaluate
— Methodevaluate(c::ContFrac)
Find a floating point representation of the continued fraction.
SymplecticMapTools.partial_frac
— Functionpartial_frac(c::ContFrac, n::Integer)
Find the n
th convergent of the continued fraction c
as a rational number.
SymplecticMapTools.denoms
— Functiondenoms(c::ContFrac)
Return a list of the denominators of the continued fractions of c
SymplecticMapTools.big_partial_frac
— Functionbig_partial_frac(c::ContFrac, n::Integer)
Find the n
th convergent of the continued fraction c
as a rational number as BigInt
s. Set the precision with precision
.
SymplecticMapTools.big_denoms
— Functionbig_denoms(c::ContFrac)
Return a list of the denominators of the continued fractions of c
as BigInt
s. Set the precision with precision
.
Birkhoff Extrapolation
SymplecticMapTools.wba_weight
— Functionwba_weight(d, N)
Weights used in the weighted Birkhoff average, returned as a diagonal matrix. Returns as Diagonal([w_1, ..., w_1, ..., w_N, ..., w_N])
, where each coefficient is repeated d
times (this is used for vector MPE and RRE as a least-squares weighting)
SymplecticMapTools.weighted_birkhoff_average
— Functionweighted_birkhoff_average(hs::AbstractMatrix)
Finds a weighted Birkhoff average of a sequence of vector observations. The array input is assumed to be of size d × N, where the average is performed over the second index.
weighted_birkhoff_average(hs::AbstractVector)
Finds a weighted Birkhoff average of a sequence of scalar observations.
SymplecticMapTools.doubling_birkhoff_average
— Functiondoubling_birkhoff_average(h::Function, F::Function, x0::AbstractVector;
tol::Number = 1e-10, T_init::Integer=10,
T_max::Integer=320)
Find the weighted Birkhoff ergodic average of an observable function h
over a trajectory of the map F
adaptively.
Arguments:
h
: A function from Rᵈ to Rⁿ, where d is the dimension of the state space and n is the dimension of the observationF
: The (symplectic) map: a function from Rᵈ to Rᵈx0
: The initial point of the trajectory in Rᵈtol
: The tolerance by which convergence is judged. If the average does not change by more thantol
over a doubling, the function returnsT_init
: The initial length of the trajectory consideredT_max
: The maximum trajectory length considered
Output:
ave
: The average ofh
over the trajectoryxs
: The trajectoryhs
: The value ofh
on the trajectoryconv_flag
:true
iff the averages converged
SymplecticMapTools.BRREsolution
— Typemutable struct BRREsolution
See also: adaptive_birkhoff_extrapolation
), birkhoff_extrapolation
, get_w0!
, adaptive_get_torus!
, save_rre
, load_rre
The solution object for the Birkhoff RRE Framework. Contains:
adaptive_birkhoff_extrapolation
) and birkhoff_extrapolation
output: - h
: Observable function (not included in save and load) - F
: Symplectic map, assumed to act from R^n -> R^n for some n (not included in save and load) - D
: Output dimension of observable - xs
: Trajectory used of points in phase space - hs
: Trajectory of observables - K
: Number of Birkhoff RRE filter unknowns - c
: Filter coefficients - h_ave
: Birkhoff average - resid_rre
: Reduced Rank Extrapolation residual
get_w0!
output: - d
: Torus dimension - w0
: Rotation vector (of form [1//p, w1, ..., wd]
, where p is the island period) - resid_w0
: Log posterior residual for rotation vector
adaptive_get_torus!
output: - tor
: The output FourierTorus
object - resid_tor
: The validation residual for the torus
SymplecticMapTools.save_rre
— Functionsave_rre(file::AbstractString, sol::BRREsolution)
Save an RRE solution object to a file (not including the evaluation and observation function F
and h
). Currently only saves to JLD2 files.
SymplecticMapTools.load_rre
— Functionload_rre(file::AbstractString)
Load an RRE solution object from a file (saved by save_rre
).
SymplecticMapTools.vector_rre_backslash
— Functionvector_rre_backslash(x::AbstractArray, K::Integer; ϵ=0.0)
Applies Birkhoff vector RRE to a sequence x_n = x[:, n]
Arguments:
x
: The sequenceK
: The number of unknowns in the filterϵ
: A regularization parameter (typically zero gives best results)
Output:
c
: The learned filtersums
: The partial sums (Birkhoff averages) obtained by applyingc
to the sequenceresid
: The residuals of the least-squares problem. Taking the norm gives an overall measure of the fit.
SymplecticMapTools.birkhoff_extrapolation
— Functionbirkhoff_extrapolation(h::Function, F::Function, x0::AbstractVector,
N::Integer, K::Integer;
x_prev::Union{AbstractArray,Nothing}=nothing,
weighted::Bool=false)
As input, takes an initial point x0
, a symplectic map F
, and an observable h
(can choose the identity as a default h = (x)->x
). Then, the method
- Computes a time series xs[:,n+1] = Fⁿ(x0)
- Computes observable series hs[:,n] = h(xs[:,n])
- Performs sequence extrapolation (RRE or MPE) on hs to obtain a model
c
of length2K+1
(withK
unknowns), the extrapolated value applied to each window, and a residual - Returns a
BRREsolution
object
Use x_prev
if you already know part of the sequence, but do not know the whole thing.
SymplecticMapTools.adaptive_birkhoff_extrapolation
— Functionadaptive_birkhoff_extrapolation(h::Function, F::Function,
x0::AbstractVector; rtol::Number=1e-10, Kinit = 20,
Kmax = 100, Kstride=20, Nfactor::Integer=5)
Adaptively applies birkhoff_extrapolation
to find a good enough filter length K
, where "good enough" is defined by the rtol
optional argument.
Arguments:
h
: The observable function (often the identity functionh = (x)->x
works)F
: The symplectic mapx0
: The initial point of the trajectoryKinit
,Kmax
,Kstride
: Increases filter sizeK
asKinit:Kstride:Kmax
. For more complicated and higher dimensional tori, typically it is better to increase these values.rtol
: Required tolerance for convergence (lower is better; inexact maps often require a looser tolerance)Nfactor
: How rectangular the extrapolation least-squares problem is. Must be >=1.
Outputs:
sol
: ABRREsolution
object
SymplecticMapTools.get_w0!
— Functionget_w0!(sol::BRREsolution, Nw0::Integer; Nsearch::Integer=30, Nsearchcutoff::Number=1e-6,
gridratio::Number=0., Nkz::Integer=50, sigma_w::Number = 1e-10, rattol::Number = 1e-8,
maxNisland::Number = 10)
Find the rotation vector from an output of Birkhoff RRE. Stores the output in the input sol
object.
Input:
sol
: The output of a Birkhoff RRE extrapolationNw0
: The dimension of the torus(Nsearch,gridratio)
:Nsearch
is the number of independent roots ofc
(i.e. ±ω are the same root) that we consider for choosing ω0.gridratio
gives the size of grid we use for the discrete optimization to find ω0. If the torus is dominated by higher harmonics, then one or both of these parameters may need to be increased. The default values (chosen bygridratio==0.
) are2
for the 1D case and5
for greater than 1D.sigma_w
: Frequency accuracy used in the Bayesian inferenceNsearchcutoff
: The cutoff prominence of the Fourier modes used to put a maximum onNsearch
. Lowering this value may result in a rotation vector when otherwise it was not found, but it may reduce accuracy.Nkz=50
: Number of frequencies to use for finding the KZ basis. This value likely does not need to be tuned by the user.
SymplecticMapTools.adaptive_get_torus!
— Functionadaptive_get_torus!(sol::BRREsolution; max_size::Number=2000, validation_fraction::Number=0.05,
ridge_factor::Number=10)
Fit an invariant torus from a trajectory. The output is saved to the sol
input. See kam_residual
for an a posteriori validation of the circle.
Inputs:
sol
: An inputBRREsolution
object. It is assumed that the rotation vector has already been computed usingget_w0!
.max_size
: Maximum number of Fourier modes to use for the torus parameterizationvalidation_fraction
: Fraction of the trajectory which is used for computing the validation error of the trajectory.ridge_factor
: Height of the ridges that the discrete gradient descent optimization can traverse.
SymplecticMapTools.sum_stats
— Functionsum_stats(sums)
Given a sequence of sums applied to a filter (an output of Birkhoff RRE extrapolation), find the average and standard deviation of the sums. Can be used as a measure of how "good" the filter is.
SymplecticMapTools.get_sum_ave
— Functionget_sum_ave(hs, c)
Given a signal hs
(of size either d×N or N×1) and a filter c
of size M×1, compute the average of the M-N windows of the filter applied to the signal.
Lyapunov Exponents
SymplecticMapTools.lyapunov_exponent
— Functionlyapunov_exponent(x0::AbstractVector, FJ::Function, N::Integer)
Compute the lyapunov exponent of the map FJ
after N
iterates of the map.
Input:
x0
: Initial pointFJ
: Returns the symplectic map evaluationF
and JacobianJ = dF/dx
, i.e. has the function signatureF, J = FJ(x)
N
: The number of iterations of the map to be used
Output:
λ
: The Lyapunov exponentλ = 1/N * log(σ_max(dF^N(x)/dx))
SymplecticMapTools.lyapunov_exponents
— Functionlyapunov_exponents(x0::AbstractVector, FJ::Function, N::Integer)
Compute the lyapunov exponents of the map FJ
over N
iterates of the map.
Input:
x0
: Initial pointFJ
: Returns the symplectic map evaluationF
and JacobianJ = dF/dx
, i.e. has the function signatureF, J = FJ(x)
N
: The number of iterations of the map to be used
Output:
λs
: The Lyapunov exponentλ = 1/n * log(σ_max(dF^n(x)/dx))
for1<=n<=N
Example Maps
SymplecticMapTools.standard_map_F
— Functionstandard_map_F(k)
Returns the Chirikov standard map with parameter k
.
standard_map_F(K::AbstractMatrix, delta::AbstractVector)
Returns the a higher dimensional standard map with matrix K
and offset delta
,i.e. y+ = y - (K/(2π))*sin(2π(x+δ)) x+ = x + y+ where (x,y) take up the (1:d,d+1:2d) entries of the input.
SymplecticMapTools.standard_map_FJ
— Functionstandard_map_FJ(k)
Returns a function FJ
that returns the Chirikov standard map and its derivative (i.e. F, dFdx = FJ(x)
) with parameter k
.
standard_map_FJ(K::AbstractMatrix, delta::AbstractVector)
Returns a function FJ
that returns the higher dimensional standard map and its derivative (i.e. F, dFdx = FJ(x)
) with parameter k
(see standard_map_F(::AbstractMatrix,::AbstractVector)
).
SymplecticMapTools.polar_map
— Functionpolar_map(d, z0)
Returns the d-dimensional polar map
> h:(θ,z)->((z-z0)cos(2πθ), (z-z0)sin(2πθ))
as well as its derivative HJ
, its inverse hinv
, and its inverse derivative HJinv
. Useful for applying extrapolation methods to maps on Tᵈ×Rᵈ.
polar_map([d];z0 = -0.5)
Returns the polar map
> h:(θ,z)->((z-z0)cos(2πθ), (z-z0)sin(2πθ))
as well as its derivative HJ
, its inverse hinv
, and its inverse derivative HJinv
. Useful for applying extrapolation methods to maps on T×R. Default value of z0
is useful for the standard map on T×[0,1] with k=0.7.
Plotting Routines: Plots
RecipesBase.plot
— MethodPlots.plot(z::InvariantCircle; kwargs...)
Creates a plot of the invariant circle z
. See Plots.plot!(z::InvariantCircle)
for a list of keyword arguments.
RecipesBase.plot!
— MethodPlots.plot(p::Plots.Plot, z::InvariantCircle; kwargs...)
Plots the invariant circle z on p.
kwargs:
N::Integer
: Number of θ points used to plot each circlei_circle::Integer
: Which period of an island chain to plot. Default value of0
plots all circles of an island chain.label
,color
,linewidth
,linestyle
: see Plots.jl
SymplecticMapTools.parametric_plot
— Functionparametric_plot(z::InvariantCircle; N::Integer=200, i_circle::Integer=1,
linewidth=1, linestyle=:solid, label1="x", label2="y",
xlabel="θ", plot_min_dθs=true, markersize=5)
Parametric plot of an invariant circle.
kwargs:
N::Integer
: Number of θ points used to plot each circlei_circle::Integer
: Which period of an island chain to plot
RecipesBase.plot
— MethodPlots.plot(c::ConnectingOrbit; kwargs...)
Creates a plot of the connecting orbit c
. See Plots.plot!(c::ConnectingOrbit)
for a list of keyword arguments.
RecipesBase.plot!
— MethodPlots.plot!(p::Plots.Plot, c::ConnectingOrbit; kwargs...)
Creates a plot of the connecting orbit c
.
kwargs:
N::Integer
: Number of points used to plot each orbiti_circle::Integer
: Which period of a connecting orbit chain to plot. Default value of0
plots all connecting orbits of a island chain.label
,color
,linewidth
: see Plots.jl
Plotting Routines: CairoMakie
MakieCore.lines!
— MethodCairoMakie.lines!(ax, z::InvariantCircle; N::Integer=100, color=nothing, i_circle::Integer=0, linewidth=1)
Plot the invariant circle z
on the CairoMakie axis ax
.
Arguments:
ax
: CairoMakie Axis objectz
: The circle in R² to be plottedN
: Number of points to ploti_circle
: Which invariant circle of an island to plot. If 0, plot allcolor
,linewidth
: seeCairoMakie.lines!
SymplecticMapTools.lines_periodic!
— Methodlines_periodic!(ax, z::InvariantCircle, hinv::Function; N::Integer=100,
color=nothing, i_circle::Integer=0, linewidth=1)
Useful for plotting with invariant circles on the torus. I.e., if F : T×R→T×R, and one finds an invariant circle of z(θ+τ) = (h∘F)(z(θ)) where h : T×R→R², this plots h⁻¹∘z, the original invariant circle.
Arguments:
ax
: CairoMakie Axis objectz
: The circle in R² to be plottedhinv
: The map to the torus by the real numbers h⁻¹ : R²→T×RN
: Number of points to ploti_circle
: Which invariant circle of an island to plot. If 0, plot allcolor
,linewidth
,label
: seeCairoMakie.lines!
SymplecticMapTools.plot_on_grid
— Methodplot_on_grid(x::AbstractVector, y::AbstractVector, k::KernelLabel;
kwargs...)
Create a filled contour plot of the kernel label k
on the x
× y
grid.
kwargs:
balance=true
: If true, makes the maximum value of the color scale equal to the minimumsize
,fontsize
: SeeCairoMakie.Figure
xlabel
,ylabel
,title
: SeeCairoMakie.Axis
levels
,linewidth
: SeeCairoMakie.contour!
clabel
: SeeCairoMakie.Colorbar
Output:
f
: The CairoMakie Figuref_grid
: The data used to make the figure
SymplecticMapTools.poincare_plot
— Methodpoincare_plot(xb::AbstractVector, yb::AbstractVector, F::Function,
Ninit::Integer, Niter::Integer; size=(800, 800),
fontsize=25, xlabel="x", ylabel="y", xlims = nothing,
ylims=nothing, markersize=3, title="Poincare Plot")
Create a Poincare plot of a 2D map F
in a rectangular region xb
×yb
. The Poincare plot uses Ninit
trajectories of length Niter
.
Output:
f
: The figurexs
: The trajectories used to make the figure