{'fraction_non_alphanumeric': 0.03548439443933575, 'fraction_numerical': 0.007356520798398875, 'mean_word_length': 4.683215493390716, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Modeling Dynamic Swarms

This paper proposes the problem of modeling video sequences of dynamic swarms (DS). We define DS as a large layout of stochastically repetitive spatial configurations of dynamic objects (swarm elements) whose motions exhibit local spatiotemporal interdependency and stationarity, i.e., the motions are similar in any small spatiotemporal neighborhood. Examples of DS abound in nature, e.g., herds of animals and flocks of birds. To capture the local spatiotemporal properties of the DS, we present a probabilistic model that learns both the spatial layout of swarm elements and their joint dynamics that are modeled as linear transformations. To this end, a spatiotemporal neighborhood is associated with each swarm element, in which local stationarity is enforced both spatially and temporally. We assume that the prior on the swarm dynamics is distributed according to an MRF in both space and time. Embedding this model in a MAP framework, we iterate between learning the spatial layout of the swarm and its dynamics. We learn the swarm transformations using ICM, which iterates between estimating these transformations and updating their distribution in the spatiotemporal neighborhoods. We demonstrate the validity of our method by conducting experiments on real video sequences. Real sequences of birds, geese, robot swarms, and pedestrians evaluate the applicability of our model to real world data.


Introduction
This paper is about modeling of video sequences of a dense collection of moving objects which we will call swarms. Examples of dynamic swarms (DS) in nature abound: a colony of ants, a herd of animals, people in a crowd, a flock of birds, a school of fish, a swarm of honeybees, trees in a storm, and snowfall. In artificial settings, dynamic swarms are illustrated by: fireworks, a caravan of vehicles, sailboats on a lake, and robot swarms. A DS is characterized by the following properties. (1) All swarm elements belong to the same category. This means that the appearances (i.e. geometric and photometric properties) of the elements are similar although not identical. For example, each element may be a sample from the same underlying probability density function (pdf) of appearance parameters.
(2) The swarm elements occur in a dense spatial configuration. Thus, their spatial placement, although not regular, is statistically uniform, e.g., determined by a certain pdf. (3) Element motions are statistically similar. (4) The motions of the swarm elements are globally independent. In other words, the motions of two elements that are sufficiently well separated are independent. However, this is not strictly true on a local scale because if they are located too close compared to the extents of their displacements, then their motions must be interdependent to preserve separation. Thus, the motion parameters of each element vs. the other elements can be considered as being chosen from a mutually conditional pdf. Occasional variations in these swarm properties are also possible, e.g. elements may belong to multiple categories such as different types of vehicles in traffic. Fig. 1 shows some examples of DS. This definition of DS is reminiscent of dynamic textures (DT). Indeed, a DS is analogous to a DT of complex nonpoint objects. The introduction of complex nonpoint objects introduces significant complexity: (1) Extraction of nonpoint objects becomes necessary, whose added complexity is evident from, e.g., the algorithm of [3]. (2) Motion for nonpoint objects is richer than point objects, e.g., rotation and nonrigid transformations become feasible. Since most work on DTs has focused on textures formed of pixel or subpixel objects, DS is a relatively unexplored problem. Tools for DS analysis should be useful for general problems such as dynamic scene recognition, dynamic scene synthesis, and anomaly detection, as well as, specific problems such as the motion analysis of animal herds or flocks of birds. In this paper, we present an approach to derive the model of a DS from its video, and demonstrate its efficacy through example applications. Before we do this, we first review the work most related to DS, namely, that on DT.

Related Work
A DT sequence captures a random spatiotemporal phenomenon which may be the result of a variety of physical processes, e.g., involving objects that are small (smoke particles) or large (snowflakes), or rigid (flag) or nonrigid (cloud, fire), moving in 2D or 3D, etc. Even though the overall global motion of a DT may be perceived by humans as being simple and coherent, the underlying local motion is governed by a complex stochastic model. Irrespective of the nature of the physical phenomena, the objective of DT modeling in computer vision and graphics is to capture the nondeterministic, spatial and temporal variation in images.
As discussed earlier, although the basic notion of DTs allows that both spatial and temporal variations be complex, the limited work done on DT's has focused on moving objects (texels) that have little spatial complexity, even as they exhibit complex motion. The texels are of negligible size (e.g., smoke particles), whose movement appears as a continuous photometric variation in the image, rather than as a sparser arrangement of finite (nonzero) size texels. Consequently, the DT model must mainly capture the motion and less is needed to represent the spatial structure.
Statistical modeling of spatiotemporal interdependence among DT images serves as being closest to the work we present here. This work includes the spatiotemporal autoregressive (STAR) model by Szummer et al. [13] and multiresolution analysis (MRA) trees by Bar-Joseph et al. [5]. The DT model of Doretto et al. [12] uses a stable linear dynamical system (LDS). LDS mixture models have been developed in [8] and implemented on DT clustering and segmentation. In [10], a mixture of globally coordinated PPCA models was employed to model a DT.
Along with their merits, the previously proposed models also suffer from certain shortcomings. (i) These models make restrictive assumptions about the DT sequences. Most of them assume that there is either a single DT covering each frame in the sequence. The others that consider multiple DT's are usually limited to particle textures (e.g. water and smoke). Consequently, these models cannot be easily extended to dynamic swarms. Even if the texels were known beforehand, learning a separate model for each texel does not guarantee the underlying spatiotemporal stationarity of DS. (ii) They do not make a clear separation between the appearance and dynamical models of the DT. The approach proposed in [9] explicitly aims at this separation, but it is limited to fluid DT's only.
Another body of work that is related to our swarm motion models a DT as a set of dynamic textons (or motons) whose motion is governed by a Markov chain model [14,16]. This generative model is limited to sequences of particle objects (e.g. snowflakes) or objects imaged at large distances. The texton dynamics are constrained by the underlying assumptions of the model, which state that all textons have the same frame-to-frame transformation, that this transformation is constant over time, and that the dynamics of spatially neighboring textons are independent. While this work does involve moving objects containing more than one pixel per object as well as some interpixel spacing, its modeling power still does not match the needs of the properties (1-4) of a DS given above.
In the rest of this paper, we refer to the objects forming a swarm as swarm elements. We propose a probabilistic model that learns both the spatial layout of the swarm elements and their joint dynamics, modeled as linear transformations, which allow for a clear separation between the appearance and dynamics of these elements. This joint representation takes into account the interdependence in the properties of elements that are neighbors in space and time. This is done by enforcing stationarity only within spatiotemporal neighborhoods. This local stationarity constraint allows us to model DS sequences that not only exhibit globally uniform dynamics (to which previous methods are limited), but also sequences whose element properties and dynamics gradually change, in space and time.

Overview of Proposed Model
Given a DS sequence in which swarm elements undergo locally stationary transformations, we iterate between learning the spatial layout of these elements (i.e. their binary alpha mattes and their frame-to-frame correspondences) and their dynamics. We estimate swarm dynamics such that they follow a probabilistic model that enforces local stationarity within a spatiotemporal neighborhood of each element. In regards to spatial layout, we assume that each swarm element consists of one or more homogenous segments that also possess these spatiotemporal stationarity properties.
We model the frame-to-frame motion of each individual element as a linear transformation, which reconstructs the element's features in a given frame from its features in the previous one. These features can describe local or global properties. In our framework, we do not restrict the choice of these features, since they can be application dependent.
These linear transformations are chosen to capture a wide variety of possible changes especially rotation, scaling, and shear. Moreover, a spatiotemporal neighborhood is associated with each element, in which local stationarity is enforced. Spatially, this is done by assuming that the dynamics of elements in a given neighborhood are samples from the same distribution corrupted by i.i.d. Gaussian noise. Temporally, these dynamics are governed by an autoregressive (AR) model. We learn swarm dynamics by estimating the transformations that maximize the a posteriori probability or equivalently that (i) minimize the reconstruction error and (ii) enforce stationarity in each element's neighborhood.
Contributions: (1) We present an approach that learns the dynamics of swarm elements jointly. This is done by modeling their frame-to-frame linear transformations instead of directly modeling their features. Using these transformations, our model is able to handle more complex swarm motions and allows for a clear separation between the appearance and dynamics of a swarm.
(2) Based on our assumption of local spatiotemporal stationarity, the proposed probabilistic model allows for interdependence between swarm elements both in time and space. This is done locally, so as not to limit the types of DS sequences that can be modeled, which is a shortcoming of most other methods. (3) The proposed model and learning algorithm estimate the spatial layout of swarm elements by enforcing temporal coherence in determining their frame-to-frame correspondences and the spatial stationarity of their dynamics

Proposed Spatiotemporal Model
In this section, we give a detailed description of our spatiotemporal model for the spatial layout and dynamics of a DS. We consider sequences whose fundamental spatial elements are opaque objects. The changes these elements undergo are stationary, both spatially and temporally. We also assume that each swarm element consists of one or more homogenous segments that also possess these spatiotemporal stationarity properties. To learn the spatial layout of a swarm, we refrain from using texel extraction algorithms (e.g [3]) or multiple object trackers from the literature (e.g. [15]). This is because they do not make use of the spatiotemporal relationship inherent to swarm elements. Instead, we revisit the video segmentation algorithm of [7], which has some interesting properties that we exploit to learn spatial layout. Since no explicit tracking is performed on the swarm elements, occlusion handling remains a problem and is left for future work. To enforce stationarity, we assume that the dynamics of the swarm elements are distributed according to an MRF in both space and time. In our model, the dynamics of each swarm element is influenced by its spatial and temporal neighbors, within its spatiotem-poral neighborhood. Unlike other dynamical models (e.g. [12,16]) that assume spatial independence between texture elements, we maintain spatiotemporal dependence among swarm elements to render a more constrained model. In what follows, we give a clear mathematical formulation of our problem.
We are given F frames of size M × N constituting a swarm sequence. Frame t in this sequence contains K t swarm elements. This permits that elements can disappear and be formed at different time instances. A swarm element consists of one or more adjacent low-level image segments that have similar dynamics. Note that any low-level segmentation algorithm can be used here. In the following sections, we show how we iterate between learning the spatial layout of the elements and their dynamics. At a given iteration, we fix element dynamics and update the swarm elements by clustering segments to enforce spatiotemporal stationarity. Then, we update the dynamics of the new swarm elements.
Let us denote the swarm elements by their spatial lay- is the manifestation of the i th element in frame t and T t = is the set of swarm elements in frame t. These swarm elements are represented by their d-dimensional fea- , which describe their appearances. To model local swarm dynamics, we define a linear transformation A t+1 . Due to its general form, it can encompass commonly used transformations (e.g. rotation and scaling) as well as more specific ones (e.g. any orthogonal or orthonormal transformation).
to denote the set of transformations for the K elements in frame t and F t = f to denote the set of features.
By using frame-to-frame transformations to characterize swarm dynamics instead of their corresponding features, we emphasize the separation between swarm appearance and dynamics. This is usually ignored in other models. This explicit separation allows distinction between and independent control of elements' appearance and motion. That is, we can pair any swarm elements with any dynamics.
The goals of modeling these linear transformations are twofold.
[G1] We desire accurate frame-to-frame reconstruction of the feature vectors, which determines how well our model fits the underlying data.
[G2] We need to impose spatial and temporal stationarity on the transformations within a local spatiotemporal neighborhood. In the absence of [G2], our model is ill-posed and too general for any practical use. Consequently, [G2] ensures that our model conforms to the underlying process that generates the swarm elements' dynamics.
Section 2.1 gives a detailed description of how a swarm element's spatiotemporal neighborhood is formed. In Section 2.3, we learn the spatial layout and the linear transformations in a probabilistic MAP framework.

Spatiotemporal Neighborhood in a DS
Our dynamical model assumes spatial and temporal stationarity for each swarm element within its spatiotemporal be the set of all spatiotemporal neighborhoods in the sequence.

Spatial Neighborhood
The elements, indexed by Γ S (t, i), are determined by the generalized Voronoi regions corresponding to the elements present in the t th frame. We also weigh the "neighborness" of every pair of spatial neighbors. w t (i, j) is the corre- . It is equal to the ratio of the length of the common boundary between the Voronoi regions of the neighboring elements, to the average distance of these elements to the common boundary. For elements that are not spatial neighbors, this weight is set to zero. Local spatial stationarity is enforced by assuming that transformations of neighboring elements are drawn from the same distribution, corrupted by Gaussian i.i.d. noise. Therefore, we have:

Temporal Neighborhood
The elements, indexed by Γ T (t, i), are the manifestations of the i th element in a temporal window consisting of the W T previous frames. The limits of this window are truncated to remain within the limits of the video sequence itself. This is done to resolve exceptions occurring at the first W T frames in the sequence. We enforce temporal stationarity by applying an AR model of order W T to the sequence of transformations in this temporal window. In fact, the AR model has often been used to model features over time (e.g. [14]), but here, we use it to model the temporal variations of these features (i.e. the dynamics themselves). Therefore, T . For simplicity, the AR coefficients ( α ∈ R W T ), are assumed to be time invariant and the constant for all swarm elements.
In Figure 2, we show an example of the spatiotemporal neighborhood of T (1) t with W T = 2. Note that the number of spatial neighbors and the "neighborness" weights can change from frame-to-frame.

Model for Swarm Dynamics and Spatial Layout
Here, we present the probabilistic model that governs the dynamics of swarm elements and their spatial layout in a DS. We model the joint probability of the spatial layout of the swarm elements, their features, and their dynamics. This is done by decomposing the joint into the prior over the transformations and the spatial layout, in addition, to the likelihood of the features given the swarm layout and dynamics as in Eq (1). In what follows, we model the three terms to ensure [G1] and [G2].

Likelihood Model (L)
Since we assume a linear relationship between consecutive feature vectors, we can decompose the likelihood probability as: is a constant with respect to the transformations. Consequently, we can write the negative log likelihood as in Eq (2).
Prior on Swarm Spatial Layout (P T ) As stated before, each swarm element consists of one or more homogenous segments that are produced by the algorithm of [4]. The spatial layout of these elements and their frame-to-frame correspondences must ensure that the swarm elements' features are reconstructed faithfully and that spatial stationarity of their dynamics is enforced. The frame-to-frame correspondences of a swarm element are equivalent to many-to-many correspondences between segments from the two frames. To formalize this problem, we denote the frame-to-frame correspondence between T (i) t and T (i) t+1 as n (t,i) , which is a node in the graph of all frame-to-frame correspondences in the swarm sequence. Two nodes n (t,i) and n (s,j) are considered neighbors in the graph, if any pair of T are spatially adjacent (i.e. share boundaries). We show an example in Figure 3. Here, we can define a self-similarity function for each node, s 1 n (t,i) , that quantifies the quality of frame-toframe feature reconstruction. Also, we define a pairwise similarity function for each pair of neighboring nodes, s 2 n (t,i) , n (s,j) , that evaluates how similar their frame-toframe transformations are. This setup is similar to the one used in [7]. Actually, we shall see later that we use a similar method to update the spatial layout. We use normalized correlation to define s 1 (.) and s 2 (.), where s 1 n (t,i) = The prior P T is proportional to the self and pairwise similarities of all neighboring nodes in the graph.

Prior on Swarm Dynamics (P A )
As L was modeled to guarantee [G1], [G2] is accounted for by modeling P A as a product of potential functions defined on the set of all spatiotemporal neighborhoods. This decomposition is widely used to model priors on maximum cliques defined on an undirected graph. We define the potential function for each clique as the product of a spatial potential Ψ S (.) and a temporal potential Ψ T (.), which guarantee spatial and temporal stationarity in swarm dynamics, respectively. So, we have f S and f T are potentials that evaluate how spatially and temporally stationary the swarm transformations are. For . We can express the negative log prior as in Eq (3). Note that p 2 is a constant that depends on the "neighborness" weights, Also, we assume that the normalizing factor Z is constant with respect to the swarm dynamics, the noise variances, and the AR coefficients.

Learning Swarm Layout and Dynamics
After establishing our probabilistic model, we proceed to learning its parameters, , the noise variances σ S , σ T , and γ (i.e. {γ t } F −1 t=1 ), as well as the AR coefficients α (i.e. {α j } W T j=1 ). To do this, we embed our model into a MAP framework. We assume that the prior on the features and the prior on the noise variances are uniform. Replacing Eq (2,3) in Eq (1), we formulate the MAP problem as a nonlinear and non-convex minimization problem.
Due to the complex form of Eq (4), we learn the spatial layout of the DS and its dynamics in an iterative fashion. In each iteration, we either fix the dynamics and update the spatial layout or vice versa. In what follows, we show the steps involved in updating the spatial layout and the dynamics at the j th iteration.

Spatial Layout Update
We employ a method similar to the one used for video object segmentation in [7] to update {T t [j − 1]} F t=1 . We will only highlight the main aspects of this method and how it applies to modeling DS's. We create a graph whose nodes are all candidates for frame-to-frame correspondences between {T t [j − 1]} F t=1 and individual segments of these frames. In other words, a segment or swarm element in frame t corresponds to a segment or swarm element in the next frame, if the projection of the former into frame t + 1 (according to its optical flow) overlaps with the latter. This graph allows for the clustering of similar and neighboring nodes, thus, enabling many-to-many correspondences between consecutive frames. Once this graph is created, the attributes of each node and the edge weights between neighboring nodes are determined by s 1 (.) and s 2 (.), as defined in Section 2.3. For segments that do not belong to {T t [j − 1]} F t=1 , we use identity for their transformation. Given this weighted undirected graph, we cluster its nodes into valid and invalid correspondences. This binary clustering is done using graph cuts, instead of relaxation labeling. Then, the resulting valid correspondences are broken down into individual connected components, where connectedness is over time and space. This yields {T t [j]} F t=1 . As pointed out in [7], this method tends to cluster adjacent/occluding swarm elements with similar dynamics. For initialization, we set {T t [0]} F t=1 to all segments in the video sequence with non-zero optical flow.

Dynamics Update
Given {T t [j]} F t=1 , Eq. (4) can be solved iteratively using Iterated Conditional Modes (ICM) [6], which guarantees a local minimum. In the k th ICM iteration, the variances are updated to their ML estimates. Updating each A (i) t requires the minimization of a convex quadratic, matrix problem. α is updated by solving a linear system of equations. In what follows, we index the model parameters with [k] to denote their estimates in the k th ICM iteration.
First, we show the update equation for the AR coefficients. Taking the gradient of Eq (4) with respect to α and setting it to zero renders the following update equation: Here, M is the sum of Gramm matrices corresponding to the transformations associated with the spatiotemporal neighborhoods at iteration k. m is the sum of the inner products between these transformations. Now, we turn to updating the transformations. At each ICM iteration, we fix all of them except for X = A Here, we isolate the dependence of Eq (4) on X and minimize the following convex-quadratic matrix problem.
where e R and e S represent the reconstruction and spatial stationarity residuals, respectively. e T represents the temporal stationarity residuals corresponding to the frames preceding frame t. We express these terms as follows.
Minimizing g (X) is a convex quadratic problem that admits a global minimum X * . It can be obtained using gradient descent where the rate of descent (η) is determined by a line search. A closed form solution for η can be derived. Till now, X has been an unconstrained linear transformation; however, certain applications require that it belong to a feasible set S d (e.g. rotation or symmetric matrices).
To do this, we project the intermediate solution at each descent step onto S d . In some cases, this projection is trivial. For example, if S d = X ∈ R d×d : X = X T , the projection of X is X+X T 2 . Using differential matrix identities, we can express the gradient of g (X) in a computationally ef- t+1 , and the current estimates of the transformations and α. Algorithm 1 provides details for solving Eq (5).
We can initialize X in two ways. (a) Set X (0) equal to the transformation obtained from the previous ICM iteration (i.e. we can initialize X (0) by projecting the solution to the unconstrained version of Eq (5), denoted X * UNC , onto S d . Setting ∇g = 0 and using the matrix inversion lemma, we get In our experiments, both initialization schemes had similar rates of convergence; however, (b) tends to be more numerically unstable when β is small. For the first ICM iteration (k = 0), we initialize every A

Algorithm 1: Gradient Descent (GD)
Input : Algorithm 2 combines all these update equations together into the overall algorithm for solving Eq (4) to learn the swarm spatial layout and dynamics. The worst case complexity of this algorithm is O (F d 3 ), since it is defined by the complexity of Algorithm 1 that has a linear convergence rate.

Experimental Results
To validate our model and evaluate the performance of our algorithm, we conducted experiments on synthetic sequences (Section (3.1)) and real sequences (Section (3.2)). The synthetic sequences help provide quantitative evaluation. The experiments show that we can learn the dynamics of swarms and discriminate between different types of swarm motion.

Algorithm 2: Learn Swarm Layout and Dynamics
• compute w t (t, i)

Synthetic Sequences
Model Learning: First, we construct a synthetic DS sequence of F = 25 frames and K = 8 elements (4 leaves and 4 squares with a simple textured interior). Figure 4(a) shows a sample frame of this sequence, where the boundaries of the generalized Voronoi regions are drawn in green. The motion of the swarm elements is synthesized by applying a globally similar rotation R θ (i) t . Specifically, for each element in every frame, θ (i) t is sampled from a Gaussian distribution N (θ 0 = π 25 , σ = 1 50 ) The features we used were based on a polar coordinate system centered at the centroid of each element, where each angular bin had a width of π 20 rad. For each angular bin, we extracted two shape features (kurtosis and skew), the mean centroidal distance of the element boundary, and the mean intensity value. This yielded a feature vector of size d = 160. Setting = 10 −3 , k max = 50 and W T = 3, we applied Algorithm 2 to learn the swarm dynamics. Running MATLAB on a 2.4GHz PC, our algorithm converged in 40 ICM iterations (∼ 30 seconds). Figure 4(b) shows a sample transformation matrix after convergence. We evaluate our model fitting performance by using three measures: the reconstruction residual error ζ R (t), the spatial residual error ζ S (t), and the temporal residual error ζ T (t) defined as: They quantify the average error incurred in reconstructing the data and enforcing stationarity in the spatiotemporal neighborhood of each swarm element. Clearly, the smaller these measures are, the better our model fits the data. Figure 4(c) plots these measures for all frames in the sequence. All three measures show a stable variation with time. ζ S and ζ T are consistently larger than ζ R due to the added noise corrupting each transformation. In fact, as σ → 0, ζ S and ζ T both get closer to ζ R . Furthermore, ζ T is consistently larger than ζ S because temporal neighborhoods only extend W T = 3 frames from each swarm element. In fact, as W T → (F − 1), ζ T gets closer to ζ S , since temporal stationarity is enforced on a larger number of frames. Here, we point out that although the leaf and square elements are significantly different in appearance, their dynamics are the same. This reinforces the fact that our method successfully separates between swarm appearance and dynamics.  Motion Discrimination: Here, we demonstrate that the learned transformations can discriminate between different types of motion. Another synthetic DS sequence is constructed in the same manner as before, but with the leaf and square elements now rotating in opposite directions. Leaf elements undergo R θ (i) t , while square elements undergo R −θ (i) t . After learning the swarm dynamics, we compute all the distances (i.e. Frobenius norm of the difference) between pairs of learned transformations. We show the resulting distance matrix in Figure 5(a). We see that the transformations corresponding to the leaf elements are close to each other and far from those corresponding to the square elements. For visualization purposes, we perform MDS on these pairwise distances to embed the transformations in R 3 . In this space, the leaf and square dynamics are easily separable. Moreover, these transformations can be perfectly clustered using spectral clustering (K = 2).
This result reinforces the fact that our method can successfully learn and discriminate between different motions occurring within a single DS sequence. This conclusion is valid as long as the "neighborness" weights associated with swarm elements undergoing similar dynamics are reasonably higher than those moving differently.

Real Sequences
In this section, we present experimental results produced when Algorithm 2 is applied to real sequences where single or multiple elements are undergoing an underlying dynamic swarm motion.

Single Swarm Element Sequences
Here, we apply our algorithm to human action recognition, where we consider the human as a single texel. There is no need to determine the spatial neighborhoods of the texels. The action sequences were obtained from the Weizmann classification database [1], which contains 10 human actions. We use background subtraction to extract the tex-  els. In addition to the features used earlier, we use the height and the width of the texel masks at each frame.
After learning the texel transformations, we use a nearest neighbor (NN) classifier to recognize a test action sequence, given a set of training sequences. We define the dissimilarity between two sequences (S 1 and S 2 ) as the DTW (dynamic time warping) cost needed to warp the transformations of S 1 into those of S 2 , where the dissimilarity between transformations X 1 and X 2 is defined as: This cost is efficiently computed using dynamic programming. Figure 6(a) plots the variation of the average recognition rate versus the number of sequences (per action class) used for training. For each training sample size, we randomly choose a set of such size from each action class and perform classification. We repeat this multiple times and average the recognition rate to obtain the plotted values. Obviously, the performance improves as the number of training samples increases. More importantly, we note that a simple classifier using only one training sample achieves a 62% recognition rate, where random chance is 10%. Furthermore, Figure 6(b) shows the average confusion matrix. Note the high diagonal values.
Here, we point out that confusion occurred between similar actions especially for the ("jump", "skip") and ("run", "walk") pairs. Better performance is expected, when texels are extracted more reliably and features are more discriminative of human motion.
Model Learning: The features we used were based on a polar coordinate system centered at the centroid of each swarm element, where each angular bin had a width of π 10 rad. For each angular bin, we extracted two shape features (kurtosis and skew), the mean centroidal distance of the element boundary, and the mean intensity value. This yielded a feature vector of size d = 100. Setting = 10 −3 , j max = 5, k max = 50 and W T = 5, we applied Algorithm 2 to learn the spatial layout and dynamics of each swarm sequence.
To evaluate the performance of our method, we conducted a leave-five-out experiment, where we learn the swarm dynamics using all the frames except for five. The transformations and features of the elements in these left out frames are reconstructed using the AR model. We repeated this experiment and reported the average normalized residual errors in Table 1, for the four sequences. These results show that our DS model represents the ground truth data well. Here, we note that the error was the highest for the "pedestrian" sequence due to the variability in the swarm dynamics and appearance. Also, we compared these residual errors to the case when identity is used instead of the learned transformations (i.e. no dynamics update). The percentage ratio of these two errors are shown in parenthesis. We conclude that our learned dynamics substantially improve model fitting. Figure 7. "birds", "geese", "robot", and "pedestrian" swarms "birds" "geese" "robot" "pedestrian" e R 8.2 (5.4) 10.3 (4.9) 3.5 (4.2) 12.9 (9.5) e S 12.5 (6.8) 6.5 (5.8) 11.6 (5.5) 15.8 (11.6) e T 18.0 (4.1) 14 Motion Discrimination: Here, we demonstrate that our method can discriminate between different motions (i.e. sequences of transformations) within the same video sequence. After learning the swarm dynamics, we compute the dissimilarity in dynamics between every pair of swarm elements. We define the dissimilarity between two sequences of swarm element transformations (T 1 and T 2 ) as the dynamic time warping (DTW) cost needed to warp the transformations of T 1 into those of T 2 [11]. Such a warping is crucial, since T 1 and T 2 might have different cardinalities (i.e. swarm elements do not have to appear in the same number of frames). This DTW cost is efficiently computed using dynamic programming. However, to compute this sequence-to-sequence DTW cost, we need to define a distance between individual transformations comprising the sequences. We define the distance between transformations X 1 and X 2 as: d (X 1 , X 2 ) = 1 − trace(X T 1 X2) X1 F X2 F . These DTW costs are employed in spectral clustering to cluster the swarm elements' dynamics.
The "birds" and "pedestrian" sequences contain more than one distinguishable motion. Figure 8 illustrates the clustering results obtained for the "birds" sequence. The extracted swarm elements are color-coded in the frames according to their distinct motions. In this sequence, two types of motion co-exist: (i) a "bird-flapping" motion where wings oscillate up and down and (ii) a "bird-gliding" motion where the wings remain relatively still. On the right, Figure 8 shows the DTW distances computed between all pairs of swarm element dynamics. We clearly see that type (i) elements undergo quite different transformations than those of type (ii). Our approach was able to simultaneously learn the different dynamics in the sequence and discriminate them. This cannot be done by DT models such as [16]. Figure 8. Shows the "birds" swarm example containing a "birdflapping" and "bird-gliding" motion. The pairwise distances between the learned transformations are shown on the right.
We also apply our algorithm to "pedestrian" video sequences, where humans or groups of humans are considered swarm elements. These sequences were obtained from the UCSD pedestrian traffic database [8]. Figure 9 illustrates the results obtained for a single pedestrian sequence that exhibits dense swarm activity. The extracted swarm elements are color-coded in the frames according to their distinctive dynamics. In this sequence, three types of motion co-exist. (i) Elements (some of which are groups of pedestrians) move/walk from the top right corner to the bottom left corner. (ii) Other elements moves in the opposite direction. (iii) One element represents a person crossing the grass instead of walking along the diagonal path. On the right, Figure 9 shows the DTW distances computed between all pairs of swarm elements. We see that the elements of (i) undergo much more similar transformations than those of (ii)-(iii), which, in turn, have significantly different dynamics. Some pedestrian segments were not part of the spatial layout since they were indistinguishable from the background.

Conclusion
This paper proposes a spatiotemporal model for learning the spatial layout and dynamics of elements in swarm sequences. It represents a swarm element's motion as a sequence of linear transformations that reproduce its properties subject to local stationarity constraints. We conducted experiments on real sequences to demonstrate our approach's merit in representing swarm dynamics and discriminating between different dynamics. Our future goal is to apply this method to motion synthesis and recognition. The support of the Office of Naval Research under grant N00014-09-1-0017 and the National Science Foundation under grant IIS 08-12188 is gratefully acknowledged.