# kq-flats

In data mining and machine learning, ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm [1] [2] is an iterative method which aims to partition ${\displaystyle m}$ observations into ${\displaystyle k}$ clusters where each cluster is close to a ${\displaystyle q}$-flat, where ${\displaystyle q}$ is a given integer.

It is a generalization of the ${\displaystyle k}$-means algorithm. In ${\displaystyle k}$-means algorithm, clusters are formed in the way that each cluster is close to one point, which is a ${\displaystyle 0}$-flat. ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm gives better clustering result than ${\displaystyle k}$-means algorithm for some data set.

## Description

### Problem formulation

Given a set ${\displaystyle A}$ of ${\displaystyle m}$ observations ${\displaystyle (a_{1},a_{2},\dots ,a_{m})}$ where each observation ${\displaystyle a_{i}}$ is an n-dimensional real vector, ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm aims to partition ${\displaystyle m}$ observation points by generating ${\displaystyle k}$ ${\displaystyle q}$-flats that minimize the sum of the squares of distances of each observation to a nearest q-flat.

A ${\displaystyle q}$-flat is a subset of ${\displaystyle R^{n}}$ that is congruent to ${\displaystyle R^{q}}$. For example, a ${\displaystyle 0}$-flat is a point; a ${\displaystyle 1}$-flat is a line; a ${\displaystyle 2}$-flat is a plane; a ${\displaystyle n-1}$-flat is a hyperplane. ${\displaystyle q}$-flat can be characterized by the solution set of a linear system of equations: ${\displaystyle F=\{x|x\in R^{n},W'x=\gamma \}}$, where ${\displaystyle W\in R^{n\times (n-q)}}$, ${\displaystyle \gamma \in R^{1\times (n-q)}}$.

Denote a partition of ${\displaystyle \{1,2,\dots ,n\}}$ as ${\displaystyle S=(S_{1},S_{2},\dots ,S_{k})}$. The problem can be formulated as

${\displaystyle (P1)\min _{F_{l},l=1,\dots ,k{\text{ are q-flats}}}\min _{S}\sum _{l=1}^{k}\sum _{a_{j}\in S_{i}}\|a_{j}-P_{F_{i}}(a_{j})\|^{2},}$

where ${\displaystyle P_{F_{i}}(a_{j})}$ is the projection of ${\displaystyle a_{j}}$ onto ${\displaystyle F_{i}}$. Note that ${\displaystyle \|a_{j}-P_{F_{i}}(a_{j})\|=dist(a_{j},F_{l})}$ is the distance from ${\displaystyle a_{j}}$ to ${\displaystyle F_{l}}$.

### Algorithm

The algorithm is similar to the k-means algorithm (i.e. Lloyd's algorithm) in that it alternates between cluster assignment and cluster update. In specific, the algorithm starts with an initial set of ${\displaystyle q}$-flats ${\displaystyle F_{l}^{(0)}=\{x\in R^{n}|(W_{l}^{(0)})'x=\gamma _{l}^{(0)}\},l=1,\dots ,k}$, and proceeds by alternating between the following two steps:

Cluster Assignment (given ${\displaystyle q}$-flats, assign each point to closest ${\displaystyle q}$-flat): the i'th cluster is updated as ${\displaystyle S_{i}^{(t)}=\{a_{j}|\|(W_{i}^{(t)})'a_{j}-\gamma _{i}^{(t)}\|_{F}=\min _{l=1,\dots ,k}\|(W_{l}^{(t)})'a_{j}-\gamma _{l}^{(t)}\|_{F}\}.}$
Cluster Update (given cluster assignment, update the ${\displaystyle q}$-flats): For ${\displaystyle l=1,\dots ,k}$, let ${\displaystyle A(l)\in R^{m(l)\times n}}$ with rows corresponding to all ${\displaystyle a_{i}}$ assigned to cluster ${\displaystyle l}$. Set ${\displaystyle W_{l}^{(t+1)}}$ to be the matrix whose columns are the orthonormal eigenvectors corresponding to the ${\displaystyle (n-q)}$ least eigenvalues of ${\displaystyle A(l)'(I-{\frac {ee'}{m}})A(l)}$ and ${\displaystyle \gamma _{l}^{(t+1)}={\frac {e'A(l)W_{l}^{(t+1)}}{m}}}$.

Stop whenever the assignments no longer change.

The cluster assignment step uses the following fact: given a q-flat ${\displaystyle F_{l}=\{x|W'x=\gamma \}}$ and a vector ${\displaystyle a}$, where ${\displaystyle W^{\prime }W=I}$, the distance from ${\displaystyle a}$ to the q-flat ${\displaystyle F_{l}}$ is ${\displaystyle dist(a,F_{l})=min_{x:W^{\prime }x=\gamma }\|x-a\|_{F}^{2}=\|W(W'W)^{-1}(W^{\prime }x-\gamma )\|_{F}^{2}=\|W^{\prime }x-\gamma \|_{F}^{2}.}$

The key part of this algorithm is how to update the cluster, i.e. given ${\displaystyle m}$ points, how to find a ${\displaystyle q}$-flat that minimizes the sum of squares of distances of each point to the ${\displaystyle q}$-flat. Mathematically, this problem is: given ${\displaystyle A\in R^{m\times n},}$ solve the quadratic optimization problem

${\displaystyle (P2)\min _{W\in R^{n\times (n-q)},\gamma \in R^{1\times (n-q)}}\|AW-e\gamma \|_{F}^{2},}$ subject to ${\displaystyle W^{\prime }W=I,}$

where ${\displaystyle A\in R^{m\times n}}$ is given, and ${\displaystyle e=(1,\dots ,1)'\in R^{m\times 1}}$.

The problem can be solved using Lagrangian multiplier method and the solution is as given in the cluster update step.

It can be shown that the algorithm will terminate in a finite number of iterations (no more than the total number of possible assignments, which is bounded by ${\displaystyle k^{m}}$). In addition, the algorithm will terminate at a point that the overall objective cannot be decreased either by a different assignment or by defining new cluster planes for these clusters (such point is called "locally optimal" in the references).

This convergence result is a consequence of the fact that problem (P2) can be solved exactly. The same convergence result holds for ${\displaystyle k}$-means algorithm because the cluster update problem can be solved exactly.

## Relation to other machine learning methods

### ${\displaystyle k}$-means algorithm

${\displaystyle k}$ ${\displaystyle q}$-flats algorithm is a generalization of ${\displaystyle k}$-means algorithm. In fact, ${\displaystyle k}$-means algorithm is ${\displaystyle k}$ 0-flats algorithm since a point is a 0-flat. Despite their connection, they should be used in different scenarios. ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm for the case that data lie in a few low-dimensional spaces.${\displaystyle k}$-means algorithm is desirable for the case the clusters are of the ambient dimension, . For example, if all observations lie in two lines, ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm with ${\displaystyle q=1}$ may be used; if the observations are two Gaussian clouds, ${\displaystyle k}$-means algorithm may be used.

### Sparse Dictionary Learning

Natural signals lie in a high-dimensional space. For example, the dimension of a 1024 by 1024 image is about 106, which is far too high for most signal processing algorithms. One way to get rid of the high dimensionality is to find a set of basis functions, such that the high-dimensional signal can be represented by only a few basis functions. In other words, the coefficients of the signal representation lies in a low-dimensional space, which is easier to apply signal processing algorithms. In the literature, wavelet transform is usually used in image processing, and fourier transform is usually used in audio processing. The set of basis functions is usually called a dictionary.

However, it is not clear what is the best dictionary to use once given a signal data set. One popular approach is to find a dictionary when given a data set using the idea of Sparse Dictionary Learning. It aims to find a dictionary, such that the signal can be sparsely represented by the dictionary. The optimization problem can be written as follows.

${\displaystyle \min _{B,R}\|X-BR\|_{F}^{2}}$ subject to ${\displaystyle \|R_{i}\|_{0}\leq q}$

where

• X is a d by N matrix. Each columns of X represent a signal, and there are total N signals.
• B is a d by l matrix. Each columns of B represent a basis function, and there are total l basis functions in the dictionary.
• R is a l by N matrix. ${\displaystyle R_{i}}$ (ith columns of R) represent the coefficients when we use the dictionary B to represent the ith columns of X.
• ${\displaystyle \|v\|_{0}}$ denotes the zero-norm of the vector v.
• ${\displaystyle \|V\|_{F}}$ denotes the Frobenious norm of matrix V.

The idea of ${\displaystyle k}$ ${\displaystyle q-}$flats algorithm is similar to sparse dictionary learning in nature. If we restrict the q-flat to q-dimensional subspace, then the ${\displaystyle k}$ ${\displaystyle q-}$flats algorithm is simply finding the closed q-dimensional subspace to a given signal. Sparse dictionary learning is also doing the same thing, except for an additional constraints on the sparsity of the representation. Mathematically, it is possible to show that ${\displaystyle k}$ ${\displaystyle q-}$flats algorithm is of the form of sparse dictionary learning with an additional block structure on R.

Let ${\displaystyle B_{k}}$ be a ${\displaystyle d\times q}$ matrix, where columns of ${\displaystyle B_{k}}$ are basis of the ${\displaystyle k^{th}}$ flat. Then the projection of the signal x to the ${\displaystyle k^{th}}$ flat is ${\displaystyle B_{k}r_{k}}$, where ${\displaystyle r_{k}}$ is a q-dimensional coefficient. Let ${\displaystyle B=[B_{1},\cdots ,B_{K}]}$ denote concatenation of basis of K flats, it is easy to show that the k -q-flat algorithm is the same as the following.

${\displaystyle \min _{B,R}\|X-BR\|_{F}^{2}}$ subject to ${\displaystyle \|R_{i}\|_{0}\leq q}$ and R has a block structure.

The block structure of R refers the fact that each signal is labeled to only one flat. Comparing the two formulations, k q-flat is the same as sparse dictionary modeling when ${\displaystyle l=K\times q}$ and with an additional block structure on R. Users may refer to Szlam's paper [3] for more discussion about the relationship between the two concept.

## Applications and variations

### Classification

Classification is a procedure that classifies an input signal into different classes. One example is to classify an email into spam or non-spam classes. Classification algorithms usually require a supervised learning stage. In the supervised learning stage, training data for each class is used for the algorithm to learn the characteristics of the class. In the classification stage, a new observation is classified into a class by using the characteristics that were already trained.

k q-flat algorithm can be used for classification. Suppose there are total of m classes. For each class, k flats are trained a priori via training data set. When a new data comes, find the flat that is closest to the new data. Then the new data is associate to class of the closest flat.

However, the classification performance can be further improved if we impose some structure on the flats. One possible choice is to require different flats from different class be sufficiently far apart. Some researchers [4] use this idea and develop a discriminative k q-flat algorithm.

### K-metrics [3]

In ${\displaystyle k}$ ${\displaystyle q}$-flats algorithm, ${\displaystyle \|x-P_{F}(x)\|^{2}}$ is used to measure the representation error. ${\displaystyle P_{F}(x)}$ denotes the projection of x to the flat F. If data lies in a q-dimension flat, then a single q-flat can represent the data very well. On the contrary, if data lies in a very high dimension space but near a common center, then k-means algorithm is a better way than k q-flat algorithm to represent the data. It is because ${\displaystyle k}$-means algorithm use ${\displaystyle \|x-x_{c}\|^{2}}$ to measure the error, where ${\displaystyle x_{c}}$ denotes the center. K-metrics is a generalization that use both the idea of flat and mean. In k-metrics, error is measured by the following Mahalanobis metric.

${\displaystyle \|x-y\|_{A}^{2}=(x-y)^{T}A(x-y)}$

where A is a positive semi-definite matrix.

If A is the identity matrix, then the Mahalanobis metric is exactly the same as the error measure used in k-means. If A is not the identity matrix, then ${\displaystyle \|x-y\|_{A}^{2}}$ will favor certain directions as the k q-flat error measure.

## References

1. ^ Bradley, P S, and O L Mangasarian. 2000. k-Plane Clustering. Journal of Global Optimization 16, no. 1: 23-32. https://doi.org/10.1023%2FA%3A1008324625522.
2. ^ Tseng, P. 2000. Nearest q-flat to m points. Journal of Optimization Theory and Applications 105, no. 1: 249–252.
3. ^ a b Szlam, A, and G Sapiro. 2009. “Discriminative k-metrics.” Ed. Léon Bottou and Michael Littman. Processing (1) 744615-744615-10
4. ^ Szlam, A, and G Sapiro. "Supervised Learning via Discriminative k q-Flats" [1]