FrechetDist.jl / Low level details

Miscellaneous

  • We cover here a few low level internal functions. This is probably

only of interest if you are trying to understand the source coe of the package.

Functions documentation

FrechetDist.extract_param_inner — Function
extract_param_inner

Takes the sequence of events (i.e., sequence of points along the curve), and outputs a corresponding sequence of real numbers, where the ith number is the distance of the ith point in sequence from the beginning of the curve. Here, distance means the total distance of the subcurve from the start point, to the current point.

source
FrechetDist.extract_refined_polygon — Function
extract_refined_polygon( poly, s, points_to_add = 1, delta = 0.0 )

Refine edges along which s (the sequence of matching points
along P) is not monotone, so that the returned polygon has
vertices that hopefully force the Frechet morphing computed in
the next iteration to be monotone.

Arguments

poly: the polygon s: Sequence of events along the polygon poly points_to_add: how many points to add between points of non-monotonicity. The default is 1. Having a larger value speeds up the process of getting rid of non-monotonicity, but the polygons grow faster. delta: if positive, edges shorter than delta / 2 are not refined, and an edge of length l gets round(l / delta) points, clamped to 1..3, instead of points_to_add.

source
FrechetDist.frechet_c_mono_approx_subcurve — Function
frechet_c_mono_approx_subcurve

Approximates the Frechet distance between a curve (P) and a subcurve (Q). Here, Q vertices are the vertices of P specified by pindices. That is, Q[ i ] = P[ pindices[ i ]].

source
FrechetDist.add_points_along_seg! — Function
add_points_along_seg!( pout, times, s_p, s_q, n_mid_points = 1 )

Arguments

sp, sq: the segment; t[1], t[2], .... , t[end]

 t[...]: Time stamps for points on the segment (all between 0 and 1)

Details

Add points along the segment sp sq at time stamps specified by t, and add points in the middle between them (i.e., refining segment). These new points are added to the output polygon pout. times is sorted and deduplicated in place.

Note that one can set nmidpoints to be larger than 1, but it does not seem to be necessary or beneficial in the experiments we did.

Output: Sorted( t[1]/2, t[1], (t[1]+t[2])/2, t[2],...)

source
FrechetDist.SweepDist_segs — Function
SweepDist_segs( p_a, p_b, q_a, q_b )

The sweep distance (continuous dynamic time warping) between the segments $p_a p_b$ and $q_a q_b$: the sum of the two oriented integrals of the distance.

source
FrechetDist.frechet_offsets — Function
frechet_offsets( P, p_indices )

Given P and the increasing indices p_indices of a subcurve of P, returns, for every edge p_indices[i] p_indices[i+1] of the subcurve, a fast upper estimate (frechet_width_approx) of the Frechet distance between that edge and the portion of P it replaces: one value per edge.

source
FrechetDist.SweepDist_segs_p — Function
SweepDist_segs_p( p_a, p_b, q_a, q_b )

The oriented sweep distance (continuous dynamic time warping) between the oriented segments p_a p_b and q_a q_b: the integral, over the arc length of p_a p_b, of the distance between the point on p_a p_b and the corresponding point (at the same fraction of the way) on q_a q_b.

source
FrechetDist.SweepDist_lb_compute — Function
SweepDist_lb_compute

Compute a lower bound on the Sweep distance between the two curves P and Q. The current implementation is naive, and very similar to the discrete Frechet calculation.

source
FrechetDist.frechet_width_exceeds — Function
frechet_width_exceeds( P, rng, w )

Whether frechet_width_approx(P, rng) > w, computed with the same arithmetic but stopping as soon as the answer is known.

source
FrechetDist.max_leash — Function
max_leash

Gets a segment on one polygon s_a s_b, and a chain P[low:hi]. Updates the
min/max estimates from the leash length. The lower bound is simply the distance
to the nearest point on the segment. The max is the result of brute force
monotonization.
source
FrechetDist.get_point — Function
get_point

Returns the point along P that is at distance pos from the beginning of P. This is the inner function, where we also provide the edge it lies on, and the prefix sums (lens) of the lengths of the edges of P.

source
FrechetDist.sqrt_quad_integral — Function
sqrt_quad_integral( u1, u2, k )

The integral of sqrt(u^2 + k^2) over u in [u1, u2], for k >= 0 and an interval of width one (u2 - u1 == 1 is used exactly). The antiderivative is (u s + k^2 asinh(u / k)) / 2 with s = sqrt(u^2 + k^2); it is odd, so an interval around 0 adds two positive terms, and an interval on one side is rewritten so that no two nearly equal terms are subtracted.

source
FrechetDist.PrevMap — Type
PrevMap

The predecessor map of the VE search: event id => id of the event it was reached from. It starts as a Dict, which is cheap when the search explores few events (similar curves), and moves once to a dense array indexed by (i, j, status) when it holds more than limit entries, which is faster and smaller when the search explores most of the 4 np nq events. Only lookups are used, so the representation does not affect results.

source
FrechetDist.check_events — Function
check_events( C, V, name )

Throws an ArgumentError unless the event sequence V runs from the first to the last vertex of the curve C, every index is a vertex (or, for an edge event, the start of an edge) of C, and every location agrees with its index and coefficient.

source

Argument validation

FrechetDist.MAX_REFINEMENT_ROUNDS — Constant

Largest number of refinement rounds the iterative algorithms (frechet_c_compute, frechet_c_approx, frechet_mono_via_refinement) may run before giving up with an error instead of looping forever. At most 17 rounds were observed in about 10,000 runs. It is a Ref so that tests can lower it.

source
FrechetDist.MAX_VERTICES — Constant

Largest number of vertices: event ids pack a vertex index into 30 bits, and the search forms ids for index n + 1 (one past the last vertex), which must still fit.

source
FrechetDist.check_approx — Method
check_approx( approx, who; exceed_one = true )

Returns approx as a Float64; throws unless it is finite, and larger than 1 when exceed_one.

source
FrechetDist.check_coordinate_type — Method
check_coordinate_type( P, who, name = "the curve" )

Throws an ArgumentError mentioning who unless the coordinates of P are Float64. Constant time: for entry points called once per edge, where check_curve would be quadratic overall.

source
FrechetDist.check_curve — Method
check_curve( P, who, name; min_vertices = 2 )

Throws an ArgumentError mentioning who unless the curve P has Float64 coordinates, between min_vertices and MAX_VERTICES vertices, and all coordinates finite with magnitude at most MAX_COORDINATE.

source
FrechetDist.check_indices — Method
check_indices( indices, n, who )

Throws an ArgumentError unless indices are vertex indices in 1:n in non-decreasing order.

source
FrechetDist.check_quadratic_size — Method
check_quadratic_size( n, m, bytes_per_cell, who )

Throws an ArgumentError when an algorithm that allocates bytes_per_cell bytes for each of the n * m vertex pairs needs more than the total memory of the machine, instead of failing with an out-of-memory error after a long allocation.

source
FrechetDist.common_curves — Method
common_curves( P, Q )

P and Q as two curves of one type that the algorithms take, or nothing when the coordinate types differ or the points are static of different dimensions. Static points stay static. Otherwise (a MatVecPntSeq, a matrix column view, or static and Vector points mixed) both are copied into GPntSeq{AnyDim,T,Vector{T}}.

source