{'fraction_non_alphanumeric': 0.044109233761775814, 'fraction_numerical': 0.012166749303939892, 'mean_word_length': 4.200733908558961, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Shape Analysis of Functional Data with Elastic Partial Matching

Elastic Riemannian metrics have been used successfully in the past for statistical treatments of functional and curve shape data. However, this usage has suffered from an important restriction: the function boundaries are assumed fixed and matched. Functional data exhibiting unmatched boundaries typically arise from dynamical systems with variable evolution rates such as COVID-19 infection rate curves associated with different geographical regions. In this case, it is more natural to model such data with sliding boundaries and use partial matching, i.e., only a part of a function is matched to another function. Here, we develop a comprehensive Riemannian framework that allows for partial matching, comparing, and clustering of functions under both phase variability and uncertain boundaries. We extend past work by: (1) Forming a joint action of the time-warping and time-scaling groups; (2) Introducing a metric that is invariant to this joint action, allowing for a gradient-based approach to elastic partial matching; and (3) Presenting a modification that, while losing the metric property, allows one to control relative influence of the two groups. This framework is illustrated for registering and clustering shapes of COVID-19 rate curves, identifying essential patterns, minimizing mismatch errors, and reducing variability within clusters compared to previous methods.


INTRODUCTION
The field of functional data analysis (FDA) has seen a tremendous growth and activity over the last few years [9], [11], [15], [24], [27]. This phenomenal interest in FDA stems in part from our growing ability to record, store, and transmit data streams that are indexed over near-continuous times. A number of books and papers, including the ones mentioned above, have highlighted clear benefits of analyzing these data streams as continuous functions rather than as discrete time-series. In FDA, one treats observed functions as elements of a function space, endows a metric structure on this space, and uses the geometry of this metric space to perform statistical analyses. The main challenges in the analysis of functional data come from the infinite dimensionality of function spaces, the contamination of data due to noise, and the presence of phase variability within the data. We highlight the last, and arguably most important, of these issues next.
Data with Phase Variability: Functional data displays an interesting phenomenon that makes it unique from the perspective of statistical analysis. Real life functional data often comes with phase variability, i.e., functions are often observed with perturbations or warpings of the time axis, resulting in the horizontal movements of peaks and valleys. In other words, noise in real data manifests itself as not only vertical (or additive) but also horizontal (or compositional), reflecting an inherent lack of temporal synchronization across functions. For example, in the case of COVID-19 infection rates, the high and low points for different regions occur at different times, implying different evolution rates of the virus cycle. Several papers [19], [20], [23], [28], [29] and a book [27] have documented and formally developed the concept of phase variability in functional data with the guidance that ignoring this phase variability leads to inflated variance in the data, loss of structures, and lack of power in hypothesis testing. Indeed these papers provide ways of separating phase and amplitude components (also termed alignment or registration of functions) and then performing either individualized or joint statistical analyses [14], [17], [23], [27], [30]. The proposed methods (for phaseamplitude separation) differ in their choices of metrics, tools for optimizations, and their definitions of phase; however, all of these papers share a fundamental shortcoming. They assume that the functions are fully observed over a common interval and moreover that the endpoints match perfectly across observations. In more mathematical terms, let interior of [0, T ] but also on the boundaries, the boundary matching assumption often breaks down and presents a major limitation to the current analysis. Sometimes one can assume that the left boundaries {f i (0)} are either synchronized or can be synchronized perhaps through a simple shift. However, the right boundaries are still variable, i.e., γ i (T ) = T . This situation arises, for example, in COVID-19 data where at the end of any observed interval, the infection rate curves for different regions are at different states of evolution. Another example of uncertain boundaries arises in censored data. Censoring is a process of randomly truncating the observation interval before the scheduled end is reached. In mathematical terms, such observations with uncertain right boundaries are given by {f i : [0, T i ] → R, i = 1, 2, . . . , n} with random end times T i ∈ R + for each observation. There is a significant literature for analyzing right-censored functional data [4], [7], especially in survival analysis [13], [16], where the aim is to model censoring times as random variables and use the distribution of min(T, T i ) explicitly in the likelihood functions. However, the literature on censored data analysis does not consider the problem of phase variability and assumes that the functional data is fully registered at all time points as acquired. For this reason, the analysis naturally deteriorates when phase variability is present in the actual data. A commonly used, albeit naive, solution is to simply time scale (linearly) each observation so that they all have the same domain [0, T ]. However, this fails to address some deeper issues present in the data.

Data with Both Phase Variability and Sliding Right
Boundary: In this paper we are concerned with the situation where each observation in the data set has the following properties: (1) It contains random phase variability; and (2) It has a right endpoint located at a random time T i . The challenge here is to separate the phase from the amplitude when the right endpoints are no longer synchronized. In other words, we wish to align or register functions, essentially by matching their peaks and valleys inside the domain, while simultaneously placing their floating right boundaries correctly with respect to each other. Some researchers refer to this problem as that of elastic partial matching [6], [8], [25]. An example of this situation arises in the analysis of Berkeley growth curves [22], where the start time of growth is birth but the end of the fixed 20 year observation period may fall at a different point of the growth cycle for different subjects due to individuals' differing biological clocks. Another example, mentioned earlier, involves incidence rates of the COVID-19 virus for different geographical locations where different cities/states/countries exhibit different rates of evolution in their incidence rates. The start time of the incidence can be assumed to be synchronized to the time of the first positive case, but, due to epidemiological and demographic factors, the pandemic evolution is certainly not well synchronized across regions. Different regions experience different growths and decline rates, and one needs to perform full registration to understand these patterns.
How can we analyze such data and still preserve data structures? We illustrate this problem with a simple example. Figure 1(a) shows a pair of functions, f 1 and f 2 , where the left boundaries are matched well but the right bound-aries are different with T 1 = 2 and T 2 = 1. Furthermore, the two functions have similar shapes except that f 1 is missing a piece relative to f 2 ; thus, f 1 can only be well matched with a part of f 2 , despite T 2 < T 1 . If we simply linearly stretch f 2 to match their boundaries by time scaling (t → 2t), we obtain the result in (b). If, in addition to their boundaries being matched by linear scaling, we also time warp f 2 to match with f 1 , we get (c). Finally, if we stretch f 2 in such a way that f 1 is matched to a part of f 2 (t → 3t) and then apply time warping, we get (d). Amongst all these solutions, panel (d) provides the most satisfactory result in matching f 1 and f 2 .
In order to reach this solution, we need to infer two items: (1) which parts of the two functions match, i.e. how much time-scaling is needed, and (2) what is the timewarping that aligns the two matched parts? If we have a set of functions, each with an uncertain right boundary, then the joint registration, modeling, and analysis of this data becomes even more challenging.  The following items summarize the main challenges in developing a mathematical solutions:

1) Mathematical Representations & Metrics:
One needs mathematical representations that can account for uncertain boundaries and time-warpings of data. Specifically, we need metrics and objective functions such that partial matching of functions can be posed as binary optimization problems. Similar to past works on elastic shape analysis of functions [27], we need metrics that are invariant to actions of nuisance groups applicable here -timewarping and time-scaling.

2) Interaction of Warping & Sliding Boundaries:
While one has solutions for the individual problems -time-warping to match extrema and timescaling to match the boundaries -the combination of the two makes the problem much more difficult. The combination requires diffeomorphic trans-formations of domains but without a fixed right boundary. This, in turn, demands searching over all combinations of linear stretches and nonlinear warpings to match any two functions. One needs to exploit the geometries of these two variables to help optimize over the joint space in an efficient manner.
This formulation resembles the problem of partial matching of shapes and there are a number of papers in the literature on this topic, see [1], [5], [10], [18], [21], [32] for example. However, our focus is on Riemannian approaches as they provide a comprehensive toolbox for statistics analysis of shapes, including geodesics, proper metrics, statistical summaries, and probabilistic modeling. In this paper we develop a comprehensive Riemannian framework for elastic analysis of functional data with right floating boundaries. Similar to the past works, we develop a framework where we represent both time-warping and time-scaling as group actions on a set of functions. Any two functions are compared by optimally time-warping their domains and varying the right boundaries using a fully automated optimization procedure. The key contribution here is a metric that is invariant to the joint action of these groups and that facilitates partial matching of curves. Additionally, we include an optional modification of this metric formulation that allows one to choose a scalar weight λ that balances the dual goal of matching the interiors and matching the right boundaries; however, some of the metric properties are lost for values λ = 1.
The rest of this paper is organized as follows. We develop the mathematical framework for partially aligning functions using an elastic Riemannian metric and a square-root representation in Section 2. The process of optimizing an objective function for pairwise matching of functions is developed in Section 3. Section 4 presents a set of experimental results involving both simulated and real data (COVID-19 infection rate curves) to demonstrate the success of the proposed framework. The paper ends with a short summary and some conclusions in Section 5.

PROPOSED MATHEMATICAL FRAMEWORK
In this section, we develop an elastic Riemannian framework for representing, partially matching, and comparing functional data with phase variability and sliding right boundaries. Before we develop our approach, we summarize the past ideas for phase-amplitude separation, or registration of functions with matched boundaries. We will follow the approach presented in [27] and refer the reader to that book for more details.

Past Work in the Alignment of Functions with Fixed Boundaries
Let F = {f : [0, T ] → R|f is absolutely continuous} be the set of functions of interest. Let Γ T be the group of all diffeomorphisms from [0, T ] to itself that preserve the boundaries. For any f ∈ F and γ ∈ Γ T , the composition f • γ denotes a time warping of f while keeping the boundaries fixed (γ(0) = 0, γ(T ) = T ). In order to register functions, one represents them by their square-root velocity functions (SRVFs). For any f ∈ F, its SRVF is given by q(t) = sign(ḟ (t)) |ḟ (t)|. In fact, this mapping f → q forms a bijection between F and L 2 ([0, T ], R), up to a constant. One can reconstruct a function f from its SRVF q and f (0) For any γ ∈ Γ T , the SRVF of the time-warped function f • γ is given by (q γ) A very important property of SRVFs is that for any two functions f 1 , f 2 ∈ F, and their SRVFs q 1 , q 2 , we have q 1 − q 2 = (q 1 γ) − (q 2 γ) for all γ ∈ Γ T . (The norm here is the standard L 2 norm: q = T 0 q(t) 2 dt.) Due to this property, the L 2 norm between SRVFs is called the elastic metric. With the elastic metric, the problem of registration between functions can be solved as the following optimization: This optimization is solved either using the dynamic programming algorithm or a gradient-based approach, as needed, and the resulting registration is called dense elastic registration. For any t ∈ [0, T ], the point f 1 (t) is said to be matched to the point f 2 (γ * (t)). For alignment of multiple functions, one exploits the fact that the minimum in Eqn. 1 is actually a proper distance on the quotient space L 2 /Γ T . Using this distance, one can define a mean function under this metric and then align the given functions to this mean using Eqn. 1. For a given set of functions {f 1 , f 2 , . . . , f n }, this framework results in a set of time-warping functions (also called phases) {γ i } and the corresponding aligned functions {f i • γ i } (also called amplitudes). The full procedure for this Phase-Amplitude separation has been outlined in Chapter 8 of the textbook [27]. Figure 2 shows an example of this approachthe left panel shows the original functions {f i }, the middle panel shows the time-warped aligned functions {f i • γ i }, and the right panels shows the optimal warping functions {γ i }.
This approach has been remarkably successful in the alignment of functional data in a variety of applications. However, as mentioned earlier, this framework assumes that both the end points t = 0 and t = T are preregistered in all observations. In Fig. 2, the endpoints are kept fixed while the interior is time-warped. Next, we consider the problem of aligning functional data with a sliding right boundary. Note that one of the boundaries, say the left one, can be matched by translation, and that leaves only the other boundary to be matched algorithmically.

Joint Time-Warping and Time Scaling
Re-define the set of functions to be F = {f : [0, ∞) → R | f is absolutely continuous}. Define the space F 0 ⊂ F as the space of all absolutely continuous, right-censored functions on the non-negative reals as Let (c, q) ∈ L 2 0 be the SRVF representation of (c, f ). That is, (c, q) represents a function q ∈ L 2 ([0, ∞), R) such that q(t) = 0 for all t > c. Further, let L 2 0 be the set of SRVF representations of all elements of F 0 . Define the preshape distance between censored functions as the L 2 distance on their corresponding SRVFs. Definition 1. The preshape distance on F 0 is given by the Note that since the two functions are censored at some point, the above integral will always be finite. Also, since the preshape distance is equal to the L 2 distance on the space , it is indeed a proper distance. Now, we re-define the full diffeomorphism space Γ to be on the entire non-negative reals as such: γ abs. cont. and invertible}.
It is easy to show that Γ is a group under the binary operation of function composition and that Γ forms a right group action on the function space F 0 also by function composition with (c, f ) • γ = (γ −1 (c), f • γ). Using the definition of SRVF, one can show that the corresponding right group action of Γ on L 2 0 is given by (c, q) * γ = (γ −1 (c), (q • γ) √γ ). Furthermore, similar to previous work in elastic shape analysis of functions on a fixed and finite time interval, the group Γ acts by isometries with respect to the preshape distance d p . That is, for any γ ∈ Γ and (c 1 , f 1 ), (c 2 , f 2 ) ∈ F 0 , the distance preserving property of At this stage, one can use the past formulation to register functions according to inf γ∈Γ d p ((c 1 , f 1 ), (c 2 , f 2 ) • γ). However, since our functions are zero on the right sides, the use of full Γ is excessive. Instead, we will seek a proper subgroup of Γ that makes the optimization more efficient and the result more meaningful. We construct this new group G ⊂ Γ from a combination of the time-scaling and time-warping sets H, N ⊂ Γ, which have the following definitions. Definition 2. The time-scaling set H is given by the set of all linear functions on the non-negative reals.
Definition 3. The time-warping set N is given by H and N are both subgroups of Γ, with N being a normal subgroup, as established next.

Lemma 1. The time-scaling set H is a subgroup of Γ.
Proof: H ⊂ Γ by definition. The closure property is achieved due to linearity: Any h ∈ H has an inverse h −1 (t) = t/a, and thus h −1 ∈ H. The identity element e(t) = t is also in H.

Lemma 2.
The time-warping set N is a normal subgroup of Γ.
Proof: N ⊂ Γ by definition. To establish the closure property, note that for any n 1 , n 2 ∈ N , the compositioñ To prove that N is a normal subgroup of Γ, we need to show that γ • n • γ −1 ∈ N for all γ ∈ Γ and n ∈ N . Evaluating the composition, we get which is a member of N . We need to form a product of N and H to reach the desired joint time-warping and time-scaling subgroup. However, since N and H do not commute, we cannot simply construct G as the direct product group G = N × H. Instead, we form a semidirect product. Using the fact that N and H are both groups, and that N ∩ H = {e}, the identity element, we can construct a new subgroup G ⊂ Γ as an outer semidirect product of both N and H. As a first step, we define the following homomorphism. Before we proceed, we establish that this mapping is indeed a homomorphism.
Proof: For notational brevity in this proof, we suppress the symbol • for function composition. Since N is a normal subgroup of Γ, and H ⊂ Γ, it holds that φ h1 φ h2 and φ h1h2 are both functions from N → N . For any n ∈ N , we Now we have all the pieces to form the subgroup required for registration of functions.
Using Lemmas 1, 2, and 3 and the definition of the homomorphism φ, by definition of an outer semidirect product, we can show that G is a proper subgroup of Γ.
Remarks: By definition, any element in G can be expressed uniquely as g = n • h. (Therefore, G also contains functions g ∈ Γ that take the form g(t) = at for all t > b.) Henceforth, we will use this shorthand notation of g to indicate the time-warping and time-scaling pair (n, h).
Finally, we construct the shape distance via the following optimization over the smaller group G instead of the full space Γ: Definition 6. The shape distance on F 0 is given by We illustrate this idea using a simple example shown in Fig. 3. Here, we first compute the shape distance between a pair of censored functions (c 1 , f 1 ) and (c 2 , f 2 ) by aligning (c 2 , f 2 ) to (c 1 , f 1 ) according to Eq. 2. In the first row, the left plot shows the original function pair, the center plot shows the optimally aligned f 2 with respect to f 1 , and the right plot shows the optimal g ∈ G needed to perform the time-warping of f 2 . The second row shows the same progression of events but for when the index labeling of the two functions has been reversed. Here, since the shape distance is a proper distance and is hence symmetric, the shape distance is the same in both cases, and the optimal diffeomorphisms in G are inverses of each other. Fig. 3. Alignment of two functions using elastic partial matching. Each row shows an example with the same two functions except that the labels f 1 and f 2 have been reversed in the second case. The first column shows the original functions, the second column shows the aligned functions, and the third column shows the optimal diffeomorphismĝ ∈ G used in the alignment. The red circle on each diffeomorphism represents its pivot point, which in this case is the minimum censoring point b = min{c 1 ,ĉ 2 }.

OPTIMIZATION DETAILS FOR PAIRWISE SHAPE DISTANCE
Next we develop techniques for optimally aligning censored functions (c 1 , f 1 ) and (c 2 , f 2 ) in order to compute their shape distance as defined in Eq. 2. That is, we develop numerical recipes to find and apply a group element (n,ĥ) ∈ G to (c 2 , f 2 ) in order to optimally match a fixed (c 1 , f 1 ), minimizing the squared preshape distance. That is, we define the energy function E as and apply (ĉ 2 ,f 2 ) = (c 2 , f 2 ) • (n,ĥ).

Grid Search Algorithm
As a simpler first idea, we present a grid search approach for this optimization in the following manner. We start by defining a finite sampling, or "grid," on the time-scaling space H given by {h i (t) = a i t, i = 1, . . . , J}. Then, for each grid point i = 1, . . . , J, we fix the time-scaling group element as h i and solve for the optimal time-warping n i with the pivot b i = min(c 1 , c 2 /a i ). This value is the smaller of the two censoring points after the second function is time-scaled, which indicates the boundary of the common observation domain for both censored functions. One can solve for n i by first truncating the two functions to the common interval [0, b i ] and then performing dense elastic registration over this interval as described in Subsection 2.1. The time-warping function n i will be completed on the right with identity outside of this interval. One can perform this function registration using one of several approaches present in the literature. The most commonly used tool is the dynamic programming algorithm [27], but one can also exploit the geometry of the space Γ bi to develop a BFGSbased gradient search [12]. The pair (n i , h i ) that yields the lowest value of the energy function E in Eqn. 3 defines the optimal diffeomorphismĝ ∈ G that best matches (c 2 , f 2 ) to (c 1 , f 1 ). Algorithm 1 describes the grid search algorithm for elastic partial matching of right-censored functions. The advantages of this algorithm are that: (1) It is relatively straightforward and uses mostly existing tools from the literature, and (2) It provides global solutions depending on the grid resolution. The disadvantage is that it is computationally expensive to solve for an optimal time-warping n i for each candidate time-scaling h i . A more computationally efficient solution is to perform a gradient search over the joint domains.

Gradient-Based Joint Optimization
In order to derive a gradient-based optimization of E, we change to a more convenient mathematical representation for elements of the group G. First, notice that for h ∈ H, the mapping φ h is an automorphism from N to itself that transforms any n ∈ N by simply scaling along the diagonal. Therefore, one can use this mapping to change the location of the pivot value b without changing the overall shape of n. We can thus write any n ∈ N as n = h • n 0 • h −1 , where n 0 ∈ N has a pivot of b = 1. That is, if h(t) = bt, then n(t) can be written as n(t) = bn 0 (t/b), and the pivot value of Given: Censored function pair (c 1 , f 1 ), (c 2 , f 2 ), and time-scaling grid samples {h i = a i t, i = 1, . . . , J} ∈ H. Result: Optimally aligned censored functions with associated group element and shape distance.
Dynamic Programming, gradient descent, or BFGS; 6 Form n i by completingγ i with identity via However, as we have done in our implementation of the grid search algorithm, when registering two censored functions, we can simplify this parameter space a bit by setting the pivot value to b = min(c 1 , c 2 /a). And now since we have written g in terms of two parameters a, and γ, we can re-write the energy function in Eqn. 3 as E(a, γ | (c 1 , q 1 ), (c 2 , q 2 )) E(a, γ), where The gradient of E can then be defined for both of these variables.

New Mathematical Representation:
We will use a map M , given by M (g) = (log(a), log(b), √γ ), the logtransformations of a and b and the SRVF of γ, to reach a more convenient representation of the group G for the purpose of gradient-based optimization. Let ξ ∈ R be such that a = e ξ , let θ ∈ R be such that b = e θ , and let the space of SRVFs of Γ 1 be Ψ. It is easy to see that for any γ ∈ Γ 1 , its SRVF ψ = √γ is non-negative and has unit L 2 norm (please refer to [27]). Define the parameter space P = R 2 × Ψ as the set of all the transformed variables (ξ, θ, ψ). Now, we can express the group G as the inverse mapping G = M −1 (P), whereby any g = M −1 (ξ, θ, ψ). Note that P is a Lie group, with the group operation being (ξ 1 , θ 1 , ψ 1 ) · (ξ 2 , θ 2 , ψ 2 ) = (ξ 1 + ξ 2 , θ 1 + θ 2 , (ψ 1 • t 0 ψ 2 (s) 2 ds)ψ 2 ). For any (ξ, θ, ψ) ∈ P, its inverse is given by (−ξ, −θ, 1/ψ) ∈ P, and the identity element of P is given by (0, 0, ψ id ) ∈ P with ψ id (t) = 1 for all t ∈ [0, 1]. The group action of G = M −1 (P) on the censored SRVF space L 2 0 can be written in terms of the parameters (ξ, θ, ψ) as such: with c → (M −1 (ξ, θ, ψ)) −1 (c). Now, the energy function can be re-written as E(ξ, ψ | (c 1 , q 1 ), (c 2 , q 2 )) E(ξ, ψ) with . Note that here we have set the variable θ to be a function of ξ and c 1 , c 2 , and thus it does not appear in the argument of E. Also, this implies that with respect to the group action * , the censoring point c 2 changes to c 2 e −ξ .
The reason for changing the representation of transformations from G to P is that the Riemannian geometry of P is less complex, relatively, in that we know the expressions for tangent spaces, exponential maps and geodesics in P. An additional nice property of P that we will exploit later in our optimization algorithm is that it is a Lie group. The Lie group structure allows us to formulate update vectors at each iteration in the tangent space of the identity element and apply these updates to the current estimate in a sequential manner. For now, since in our implementation we are setting θ as a function of ξ, we remove this parameter from the explicit representation of an element in P. Definition 8. Define the tangent space of P at the identity element p id = (0, 1) as

Definition 9.
Define the exponential mapping of v = (y, z) ∈ T p id (P) as exp p id (v) ∈ P via the formula In an iterative line-search optimization method, for the iteration k, let the current estimate be p k = (ξ k , ψ k ) ∈ P, a search direction vector v k be in the tangent bundle of P, and a step size be α k > 0. If P were a vector space, the updated estimate would be given simply by p k+1 = p k + α k v k . Since P is instead a non-linear manifold, one can compute the update using the exponential mapping p k+1 = exp p k (α k v k ). However, since P is also a Lie group with an identity element and a group action, there is no need to compute search directions in any tangent space except at identity. For any k, we can compute v k ∈ T p id (P) and then apply a sequential update to p k via p k+1 = p k · exp p id (α k v k ), where · is the group operation of P.
Most often, the search direction v k is based on the gradient of the objective function, or energy function, evaluated at the current estimate. Therefore, we need to define the energy E k : P → R at step k and show how to compute its gradient as an element of T p id (P). First, define the current censored function as (c 2,k , q 2,k ) For an update (ξ, ψ) ∈ P at iteration k, define the energy of updating the current censored function (c 2,k , q 2,k ) by (ξ, ψ) as E k (ξ, ψ) .

Proof: See Appendix B.
Having obtained these useful results, we now derive the expression for gradient of E k with respect to an incremental element of P. Theorem 1. At iteration k and for (c 1 , q 1 ), (c 2,k , q 2,k ) ∈ L 2 0 , the gradient of E k at identity (ξ id , ψ id ) ∈ P is written as the pair The two terms that comprise the gradient vector are defined as follows.
Notice that F k (ψ) takes the form of F as defined in Lemma 5 with q 2 replaced with q 2,k , and by construction ∇F k (ψ id ) = ∂E k ∂ψ (ξ id , ψ id ). Thus, according to Lemma 5, the partial derivative is equal to the expression given in Eqn. 6.
In order to implement a backtracking line-search method based on the Armijo-Goldstein condition, we must first define an inner product on T p id (P).

Definition 11.
For v 1 , v 2 ∈ T p id (P) with v 1 = (y 1 , z 1 ) and v 2 = (y 2 , z 2 ), the chosen inner product on P is given by v 1 , v 2 = y 1 y 2 + z 1 , z 2 , where ·, · is the standard L 2 inner product, and the corresponding norm is given by With this inner product and norm for elements of the tangent space, we can define the Armijo-Goldstein condition for the backtracking line-search method.

Definition 12. (Armijo-Goldstein Condition)
For a candidate update p = (ξ, ψ) ∈ P, a scalar β ∈ (0, 1), a search direction v k ∈ T p id (P), and a stepsize δ > 0, the Armijo-Goldstein condition is given by E k (p) ≤ E k (p id ) + βδ v k P ∇E k (p id ), v k . One can see that in the special case of gradient descent where v k = −∇E k (p id ), the above condition simplifies to E k (p) ≤ E k (p id ) − βδ ∇E k (p id ) P . In addition to the Armijo-Goldstein condition, we also need the condition that (ψ k * ψ)(t) ≥ 0 for all t ∈ [0, 1] in order to ensure that the incremental update of ψ k remains in Ψ. If either of the two conditions are not satisfied, then one must reduce the stepsize by a factor of τ ∈ (0, 1) by updating δ → τ δ until both are satisfied or until δ becomes too small. Algorithm 2 outlines the gradient descent method for elastic partial matching of functions.

Modification of Energy Function
The energy defined above (Definition 10) depends in part on the L 2 norm of the extra portion of the longer function (the second term). Therefore, if that piece has a large L 2 norm, then it tends to dominate the total energy. In that case, an optimal alignment pushes the endpoints of the two functions to be closer together, and the results look more similar to the standard elastic registration with identical boundaries. In order to control the influence of this unmatched part, we can modify the energy function E as follows.
Multiply the second term in E by a constant λ > 0, resulting in: where b = min(c 1 , c 2 e −ξ ). The resulting gradient expressions are altered in only a minor fashion and for the sake of brevity are not repeated here. We note that for λ = 1, the energy E is no longer the square of a proper metric, and some of the nice mathematical properties of a quotient space metric are lost. The energy minimization process results in a measure of "dissimilarity" rather than a proper distance squared. One can still perform a clustering analysis with these tools, as we demonstrate in the next Section.

EXPERIMENTAL RESULTS
In this section we present some experimental results demonstrating the strengths of this framework in comparing functions with variable right boundaries. We first introduce the two functional data sets -one simulated and one real -that we use to demonstrate results and test our method against other existing methods. (2) select a ∼ U nif orm[0.9, 1.1] and apply the time-scaling function h(t) = at to f ; and (3) apply a random timewarping diffeomorphism in Γ b/a to f . Fig. 4 shows the resulting simulated data set, colored according to class label.

Dataset 2:
The real data used here comes from COVID-19 virus infection rate curves for each of the 50 United States plus the District of Columbia and Puerto Rico plus 47 European countries. The daily new case data is preprocessed via the following procedure. First, we assign the time domain to have a unit of days, and then we translate each curve so that t = 0 represents the day of the first recorded case. Thus, t ∈ [0, ∞) represents the number of days since a state or country's first case. Then, we apply a seven day moving average to smooth the data, and then we re-sample each curve via spline interpolation to have 100 uniformly spaced time sample points. Finally, we normalize the rate curve so that it has integral 1. We execute this process three times, each on raw data truncated at different ending dates -July 31, September 30, and November 30 -to create three datasets of normalized infection rate curves. Fig. 5 shows a plot of all 99 normalized infection rate curves for the United States and Europe. The first two columns separate the US and European curves, respectively, for visual purposes.  In the first and second columns, the US and European data is plotted separately for ease of visualization, and in the third column they are plotted together.

Pairwise Alignment Examples
2 and 3 in purple. In each case, the alignments are all noticeably different visually, with our elastic partial matching methodology providing a more natural registration than the standard elastic methodology. For some examples, we see that the curve with standard elastic registration is similar to our partially matched curve on a portion of the domain. However, as it approaches the endpoint of the fixed blue curve, the elastic registration tends to unnaturally compress or stretch the yellow curve in order to force the right endpoints to match. In other cases, the freedom offered by our partial matching methodology allows us to find a completely different matching across the entire domain. In particular, the elastic partial matching of North Dakota to Sweden's infection rate curve allows for a surprisingly similar shape matching that the standard elastic registration was unable to uncover.
Below each pairwise matching result, we also show the corresponding optimal diffeomorphisms for the two elastic methods. Using the same color scheme and the same domain (time axis) scale, we plot the optimalγ ∈ Γb andĝ ∈ G associated with the two elastic registrations. The circle along the purple colored diffeomorphismĝ ∈ G represents the pointĝ(b), whereb = min{c 1 ,ĉ 2 } is the pivot point. Recall that beyond this point the functionĝ is linear with slopê g(b)/b and extends to infinity. In cases where the optimally matched second function (purple) is shorter than the first (blue), we do not plotĝ(t) beyond the pivot point t =b.

Bayesian Clustering of Functional Data
Next, we perform unsupervised clustering of the data using three different pairwise distance (or dissimilarity) measures and compare the results. The three methods are : (a) the standard L 2 metric with fixed and matched right endpoints, (b) the standard elastic metric with fixed and matched right endpoints, and (c) our novel elastic partial matching of SRVFs with floating right endpoint. Note that method (a) Fig. 6. Examples of pairwise elastic function registrations. The first row shows three pairwise alignment examples for the simulated dataset. In each panel, the blue and red curves are the original censored functions (c 1 , f 1 ) and (c 2 , f 2 ), the yellow curve is the aligned version of (c 2 , f 2 ) using standard elastic registration with fixed and matched endpoints, and the purple curve is the aligned version of (c 2 , f 2 ) using our novel elastic partial matching methodology with floating right endpoint. The second row provides the associated optimal diffeomorphisms that achieve the alignments, plotted in the same color scheme and time axis scale. The third and fourth rows are the same as the first and second but instead using examples from the COVID-19 data set. Here, we restrict example pairs to be from the set of US states and European countries truncated at July 31.
operates on the function values themselves while methods (b) and (c) use SRVFs for comparison. For method (c), we use the grid search method (Algorithm 1) with J = 50 logarithmically uniformly spaced time-scaling grid samples {a i , i = 1, . . . , J} = {0.5, . . . , 2} to initialize Algorithm 2, the gradient descent method for local refinement. Here, we use a convergence tolerance of = 10 −4 , initial step size of δ = 10 −4 , and standard backtracking parameters of β = 0.1 and τ = 0.5. Finally, for method (c) we use a weighting coefficient of λ = 0.25, and thus the pairwise comparison in this method is not a proper distance but rather a more general dissimilarity measure. Methods (a) and (b) both yield proper distances; however, as described next, our chosen clustering method depends on a similarity matrix instead of a distance/dissimilarity matrix, so it is not necessary for the analysis that our method of pairwise comparison be a proper distance.
We use the clustering technique described in [33] to cluster the data for each case. This clustering method is Bayesian in nature and uses only a pairwise similarity matrix as input -not the functional data itself -to determine the optimal number of clusters and the cluster members in an MCMC approach. It assumes a Wishart prior on the similarity matrix and uses a variant of the Chinese Restaurant Process to help determine the number of clusters. In the associated clustering software there are several hyperparameters that must be set; however, we simply use all default settings provided in the code, with an initial number of clusters set to 3 for the simulated data and 10 for the real data, to collect our clustering results. Since the software takes as input a pairwise similarity matrix S instead of a distance/dissimilarity matrix D, we must compute a full pairwise dissimilarity matrix for all function pairs in the dataset and convert it to a pairwise similarity matrix before executing the clustering algorithm. Here, we use the conversion formula S ij = 1 − D ij / max{D} so that all entries of the similarity matrix S are scaled similarly between 0 and 1. Fig. 7 shows the result of the Bayesian clustering on the simulated dataset for each of the three methods: (a), (b), and (c). From left to right, we show the pairwise similarity matrices, the color-coded block diagonal class inclusion matrices, the function clusters with consistent color scheme, and the associated cluster means for each cluster. In order to form block diagonal matrices, the data set indices have been optimally permuted as a result of the clustering algorithm. One can see that the number of clusters (3) is correct only for the elastic partial matching method shown in row (c). Furthermore, the cluster labeling is 100% correct for this method. In both methods (b) and (c), the tiled cluster display shows functions that have been mutually aligned according to their respective alignment methods. For method (c), the mutual alignment is performed so that it iteratively seeks out the "longest" censored function and aligns each remaining function to it. For ease of visual display and the minimization of white-space, the vertical axis has been scaled in each cluster tile so that the maximum value is equal to the maximum function value in each cluster set. One can see that the functions align well within the clusters for our method, showcasing the three distinct classes. Since the data is partially observed, the other two methods tend to mislabel and/or divide the three classes unnecessarily into further subclasses.

Dataset 1:
The right-most panels in Fig. 7 show the cross-sectional pointwise mean for each of the clusters shown in the center. Additionally, we compute the cross-sectional variance and plot grey lines to represent plus and minus one crosssectional standard deviation from the mean. The number in the top left of each panel window here represents the average cross-sectional variance for that cluster. As is evident from these numbers, the standard L 2 analysis leads to artificially inflated variances due to lack of alignment. The standard elastic analysis helps to bring down the variance within clusters by aligning peaks and valleys, but since the data is partially observed, the restriction of identical right endpoints still drives up the variance unnecessarily. The average cross-sectional variances are 12.7 × 10 −6 for method (a), 6.58 × 10 −6 for method (b), and 3.34 × 10 −6 for method (c). Thus, our elastic partial matching method yields the lowest average cross-sectional variance of the three methods and the tightest clustering.
Dataset 2: Next, we apply the clustering algorithm on the real COVID-19 datasets. Figs. 8, 9, and 10 show the results of the Bayesian clustering using methods (a), (b), and (c), respectively. The organization of each of the three figures is the following. Each group of three consecutive rows of image panels shows results on the July 31, September 30, and November 30 datasets, respectively. The first group of three rows shows the color-coded country/state maps, the permuted pairwise similarity matrices, and the associated block-diagonal class inclusion matrices with the same color scheme as their associated maps. The next group of three rows shows the resulting function clusters, and the final group of three rows shows the cluster cross-sectional means with cross-sectional standard error bounds. Similar to Fig. 7 with methods (b) and (c), the cluster members in Figs. 9 and 10 are mutually aligned within clusters in the tiled cluster display. Also similarly, the vertical axis has been scaled in each cluster tile so that the maximum value is equal to the maximum function value in each cluster set.
There are quite a few inferences one can draw from this set of COVID-19 results. Firstly, and perhaps most notably, there is a high degree of geographical correlation of cluster members; i.e. neighboring states/countries are typically more likely to be of the same cluster member than not. Although it seems as though this geographic correlation is higher with our method (c), there are clusters present in all 9 analyses that consist of only European countries and other clusters that consist of mostly US states. A second clear inference one can draw is that method (c) yields less clusters than the other two methods on average due to its relative invariance to partial observation. Since method (c) tends to eliminate clusters with redundant shapes, it preserves true virus trajectory features, and groups states/countries more accurately compared to methods (a) and (b). Noteworthy shape-based features that discriminate between clusters present themselves as the number and relative intensity of waves of virus transmission. For example, one cluster could exhibit a small hump followed by a rapidly rising large hump, or, in the case of the July 31 data, another cluster could exhibit an initial large hump and a subsequent tapering off with little or no second wave. Finally, we can see that method (c) yields the lowest within-class crosssectional variance on average per cluster, suggesting that these clusters are the tightest overall of the three methods. The mean value over all clusters for each of the three methods are the following: (a) 6.03 × 10 −6 , (b) 7.38 × 10 −6 , and (c) 5.82 × 10 −6 .
Another important observation that we can make, and support through quantitative evidence, is that the similarity matrices in method (c) have less prominent block diagonal structures than that of methods (a) and (b). That is, although they may appear distinct and different to the naked eye, individual clusters are in reality more similar to each other with respect to method (c) than with other methods. This phenomenon is in stark contrast to that of the simulated data, where clusters were very distinct and separable both visually and with respect to the similarity measure itself. With the COVID data, it seems as though a shape model that is invariant to the large diffeomorphism space of timewarping and time-stretching allows for a homogenization Fig. 7. Simulated data set classes resulting from the implementation of the Bayesian clustering algorithm. Row (a) shows the results for the L 2 metric with fixed and identical endpoints; Row (b) shows the results for the standard elastic metric with fixed and identical endpoints; and Row (c) shows results for our novel elastic partial matching. The first two columns show the pairwise similarity matrices and the corresponding block diagonal class inclusion matrices, colorized according to class label. The center panels are the individual clusters plotted separately, with each y-axis scaled so that the maximum value is equal to that of the maximum y-value of the associated cluster. For rows (b) and (c), plots of individual classes show function members that have been mutually aligned within classes. The right-most set of panels shows the cross-sectional mean functions for each cluster with cross-sectional error bounds of ± one standard deviation. The number in the upper-left corner of each panel here represents the average cross-sectional variance for that cluster (×10 −6 ).
of infection rate shapes in function space. In other words, save for a few outliers, this analysis shows that the states and countries all have more similar virus trajectory shapes compared to the other methods. Fig. 11 provides evidence of the above claim. Here, we provide a measure of separability between within-class similarity values and across-class similarity values for each of the three methods and for both simulated and real datasets. Within-class similarity values are those that lie within the block diagonal structures on the upper triangular portion of the similarity matrix, and the across-class similarity values are those that lie outside the block diagonal structures. Each panel of Fig. 11 shows the kernel density estimated probability density functions for within-class similarity values (blue) and across-class similarity values (red) for that particular dataset and method. The top row shows the results for the simulated data, and the bottom row shows results for the COVID data. The columns left to right represent results for methods (a), (b), and (c) respectively. The number shown in the box underneath the legend is our measure of separability, which is computed as a distance measure between the two probability distributions. We use the arclength between half-densities as our distance, or separability, formula (see [27]), given by where f in is the estimated within-class similarity value density and f out is the estimated across-class similarity value density. According to Fig. 11, the separability measure for the simulated data increases from left to right, with values of 0.879, 1.13, and 1.41 for methods (a), (b), and (c), respectively. Visually, one can see that the red and the blue densities become less overlapped as we move from the left to right panels. Contrarily with the COVID data, the separability values decrease from left to right, with values of 0.875, 0.695, and 0.626 for methods (a), (b), and (c), respectively. Visually, one can see that the red and blue densities overlap more and become more similar as we move from the left to right panels. This phenomenon provides evidence that states and countries have overall more similar virus trajectories with respect to method (c) than the other methods. Since the opposite effect is observed in simulated data, this phenomenon is due to the input data and not an artifact of the methodology used.

SUMMARY & FUTURE WORK
This paper presents a novel methodology to remove an important limitation of most past works in elastic matching, comparisons, and analysis of functional data, namely that the boundaries are fixed and registered. In addition to exhibiting phase variability within the observation interval, real data often also exhibits boundary variability, and the past methods fail to account for such boundary issues. The proposed elastic partial matching method forms a joint action of time-warping and time-scaling groups and searches for an optimal nonlinear warping along with a sliding right boundary to best match functions. As seen through experiments on simulated and COVID-19 rate curves, this additional freedom allows for more natural alignments and tighter, more visually distinct clusters compared to past methods.
Although the use of Riemannian elastic framework was motivated from a statistical perspective, the subsequent statistical tools are not developed in this paper due to a lack of space. The shape distance d s defined here is a proper distance on the quotient space F 0 /G and can be used to define sample means, sample covariance, and tangent PCA based statistical models. These models can be used further for testing and classification of functional data.
This framework can easily be applied to the problem of partially matching shapes of curves in Euclidean spaces [10], [18], [26], [32]. Very often, planar curves extracted from image data suffer from partial obscuration and missing parts. The proposed elastic partial framework naturally extends to curves in R n and can be very useful in matching partially observed shapes in that context. Another important application of our elastic partial matching framework is human activity analysis [2], [3], [31]. As stated in these papers, classification of observed activities requires temporal
Thus, since the expression is the same for both cases t ≤ b(ξ) and t > b(ξ), the above expression holds for all t ≥ 0.

APPENDIX B PROOF OF LEMMA 5
According to the Lemma, for (c 1 , q 1 ), (c 2 , q 2 ) ∈ L 2 0 and b = min(c 1 , c 2 ), define the function F : Ψ → R as In order to compute the gradient of this function at identity, we first need to write an expression for the directional derivative in the direction of a tangent vector z ∈ T ψ id (Ψ). Using a variational approach, define a path α : (− , ) → Ψ such that α(0) = ψ id and ∂α ∂τ (0) = z. The directional derivative of F at identity in the direction of z is defined as D z F (ψ id ) = ∂ ∂τ F (α(τ ))| τ =0 . Before computing the full directional derivative, we first define the functioñ and compute the derivative ofq 2 with respect to τ as If we define the variable change x = t/b and the functioñ z(x) = x 0 z(s)ds, then the above expression evaluated at τ = 0 becomes ∂q 2 ∂τ | τ =0 = 2bz(x)q 2 (bx) + q 2 (bx)c(x).
In order to compute the gradient of F , we must first express the directional derivative in the form D z F (ψ id ) = w, z for some function w ∈ L 2 ([0, 1], R). In order to do so, we make use of integration by parts to rewrite the above integral via the following procedure. First rewrite the directional derivative as D z F (ψ id ) = −4b 2 1 0 (q 1 (bx) − q 2 (bx))q 2 (bx)z(x)dx − 2b 1 0 (q 1 (bx) − q 2 (bx))q 2 (bx)z(x)dx. Now, we can use integration by parts to rewrite the first integral above by setting u(x) =z(x), v (x) = (q 1 (bx) − q 2 (bx))q 2 (bx), and then letting (q 1 (bs) − q 2 (bs))q 2 (bs)ds)z(x)dx Therefore, if we define the function w as w(x) = 4b 2 x 0 (q 1 (bs) − q 2 (bs))q 2 (bs)ds − 2b(q 1 (bx) − q 2 (bx))q 2 (bx), then we can write the directional derivative in the form D z F (ψ id ) = w, z . Finally, the Riemannian gradient of F at identity is given by the projection of w to the tangent space T ψ id (Ψ). This projection, and thus the gradient, is computed as ∇F (ψ id ) = w(x) − 1 0 w(x)dx. Fig. 8. Clustering results on the COVID-19 data set for the L 2 metric, method (a). Each group of three consecutive rows of image panels shows results gathered up to dates July 31, September 30, and November 30, respectively. That is, rows 1, 4, and 7 correspond to the July 31 dataset; rows 2, 5, and 8 correspond to the September 30 dataset; and rows 3, 6, and 9 to the November 30 dataset. From top to bottom, the first three rows show a US state & European country map colorized according to class label, the pairwise similarity matrix, and the pairwise class inclusion matrix. The next three rows show the corresponding clusters, and the final three rows show the corresponding cluster crosssectional means ± one cross-sectional standard deviation. The number in the upper-left corner of each panel here represents the average crosssectional variance for that cluster (×10 −6 ).