A Binary Optimization Approach for Constrained K-Means Clustering

Abstract: K-Means clustering still plays an important role in many computer vision problems. While the conventional Lloyd method, which alternates between centroid update and cluster assignment, is primarily used in practice, it may converge to a solution with empty clusters. Furthermore, some applications may require the clusters to satisfy a specific set of constraints, e.g., cluster sizes, must-link/cannot-link. Several methods have been introduced to solve constrained K-Means clustering. Due to the non-convex nature of K-Means, however, existing approaches may result in sub-optimal solutions that poorly approximate the true clusters. In this work, we provide a new perspective to tackle this problem. Particularly, we reconsider constrained K-Means as a Binary Optimization Problem and propose a novel optimization scheme to search for feasible solutions in the binary domain. This approach allows us to solve constrained K-Means where multiple types of constraints can be simultaneously enforced. Experimental results on synthetic and real datasets show that our method provides better clustering accuracy with faster runtime compared to several commonly used techniques.

\section{Introduction}
\input{tex/introduction}
\section{Related work}
\input{tex/related_work}
\section{Problem formulation}
\input{tex/formulation}
\section{Constrained K-Means as Binary Optimization}
\input{tex/binary_optimization}
\section{Optimization Strategy}
\input{tex/optimization_strategy}
\section{Main algorithm}
\input{tex/algorithm}
\section{Experiments}
\input{tex/results}
\section{Conclusion}
\input{tex/conclusion}
\bibliographystyle{splncs04}

\subsection{Updating the centroids}
To solve~\eqref{eq:C_update}, notice that it is a convex quadratic problem in which solutions can be derived in closed-form. However, to avoid numerical issues of the solutions for large-scale problems, we update $\mathbf{C}$ by solving the regularized least square problem~\cite{rifkin2007notes}:
\begin{equation}
\label{eq:C_update_rls}
\begin{aligned}
& \min_{\mathbf{C}}  && \| \mathbf{X}  - \mathbf{C}\mathbf{S}\|^2_F  \;\; +  \;\; \lambda \|\mathbf{C}\|_F^2, \\
\end{aligned}
\end{equation}
where $\lambda$ is the regularize parameter. The problem~\eqref{eq:C_update_rls} also admits a closed-form solution
\begin{equation}
\label{eq:C_update_solution}
\begin{aligned}
\mathbf{C} = \mathbf{X} \mathbf{S}^T (\mathbf{S}\bS^T + \lambda \mathbf{I})^{-1}.
\end{aligned}
\end{equation}
The advantage of~\eqref{eq:C_update_solution} is that $(\mathbf{S}\bS^T + \lambda \mathbf{I})$ is guaranteed to be full-rank, allowing the inversion to be computed efficiently by several matrix factorization techniques. We choose $\lambda$ to be $10^{-4}$ in all the experiments to prevent $\lambda$ from affecting the solution of $\mathbf{C}$.

\subsection{Updating the assignment matrix}
Due to the special structure of $\mathbf{S}$, the problem of finding the cluster assignments~\eqref{eq:S_udpate} can be written as an optimization problem with linear objective function~\cite{bradley2000constrained}. Let $\mathbf{Y} \in \mathbb{R}^{k \times N}$ be a matrix where each element $\mathbf{Y}_{i,j}$ is defined as $\mathbf{Y}_{i,j} = \|\mathbf{c}_i - \mathbf{x}_j\|_2^2$ ($\mathbf{x}_j$ is the $j$-th column of $\mathbf{X}$ and $\mathbf{c}_i$ is the $i$-th column of $\mathbf{C}$). The problem~\eqref{eq:S_udpate} is equivalent to
\begin{subequations}
    \label{eq:S_udpate_linear}
    \begin{align}
    & \min_{\mathbf{S}}  && \langle \mathbf{Y}, \mathbf{S} \rangle, \\
    & \text{subject to} && \mathbf{S} \in \mathbf{\Omega},\;\; \mathbf{S} \in \{0,1\}^{k\times N} \label{eq:S_udpate_linear:binary}
    \end{align}
\end{subequations}
If the binary constraints in~\eqref{eq:S_udpate_linear:binary} are ignored,~\eqref{eq:S_udpate_linear} becomes a convex linear programming (LP) problem. Based on that observation, a straightforward relaxation technique to tackle~\eqref{eq:S_udpate_linear} is to allow $\mathbf{S}_{ij}$ to be in the continuous domain, i.e., $0 \le \mathbf{S}_{i,j} \le 1 \;\; \forall i,j$. Then, $\mathbf{S}$ can be updated efficiently by solving the relaxed version~\eqref{eq:S_udpate_linear}, which can be done by taking advantage of several state-of-the-art LP solvers. However, the solutions returned by LP may not be feasible w.r.t.~\eqref{eq:S_udpate_linear}, i.e., $\exists (i,j), \mathbf{S}_{i,j} \notin \{0,1\}$. In order to project the LP solutions back to the binary domain of~\eqref{eq:S_udpate_linear}, a thresholding step needs to be executed, which may lead to loose approximation if the threshold is not chosen properly.

To overcome such drawbacks, we introduce an alternating optimization approach to find the feasible solutions for~\eqref{eq:S_udpate_linear} in an optimal way. Our approach is inspired by several algorithms on feasibility pump~\cite{fischetti2005feasibility,bertacco2007feasibility,geissler2017penalty}, which aim to find feasible solutions for mixed integer programming (MIP) problems. Our formulation allows the problem to be tackled using alternating optimization. As will be shown in the experiments, our algorithm provides a better solution for the constrained K-Means problem compared to other approximation techniques.

Let us first introduce the auxiliary variable $\mathbf{V} \in \mathbb{R}^{k \times N}$ that has the same size as $\mathbf{S}$. Furthermore, with the constraint that $\mathbf{V} \in \{0,1\}^{k\times N}$, the problem~\eqref{eq:S_udpate_linear} can now be written equivalently as
\begin{equation}
    \label{eq:S_udpate_SV}
    \begin{aligned}
    & \min_{\mathbf{S}, \mathbf{V}}  && \langle \mathbf{Y}, \mathbf{S} \rangle, \\
    & \text{subject to} && 0 \le \mathbf{S}_{i,j} \le 1 \;\; \forall i,j, \;\; \mathbf{S} \in \mathbf{\Omega}, \\
    & && \mathbf{V} \in \{0,1\}^{k\times N},\;\; \mathbf{S} = \mathbf{V}.
    \end{aligned}
\end{equation}
Note that by introducing the auxiliary matrix $\mathbf{V}$, the task of optimizing~\eqref{eq:S_udpate_SV} w.r.t. $\mathbf{S}$ can be done within the continuous domain. However, due to the binary restrictions on $\mathbf{V}$, solving~\eqref{eq:S_udpate_SV} is still a challenging problem.

In this work, we propose to tackle~\eqref{eq:S_udpate_SV} by using the $\ell_1$ penalty method~\cite{wright1999numerical}. Specifically, by incorporating the coupling constraint $\mathbf{S} = \mathbf{V}$ into the cost function of~\eqref{eq:S_udpate_SV}, in the context of $\ell_1$ penalty method, the penalty problem can be written as follows
\begin{equation}
    \label{eq:S_udpate_SV_penalty}
    \begin{aligned}
    & \min_{\mathbf{S}, \mathbf{V}}  && \langle \mathbf{Y}, \mathbf{S} \rangle + \rho \|\mathbf{S}-\mathbf{V}\|_1, \\
    & \text{subject to} && 0 \le \mathbf{S}_{i,j} \le 1 \;\; \forall i,j,  \\
    & && \mathbf{S} \in \mathbf{\Omega}, \;\; \mathbf{V} \in \{0,1\}^{k\times N}, \\
    \end{aligned}
\end{equation}
where the notation $\|.\|_1$ of a matrix $\mathbf{X}$ is defined as  $\|\mathbf{X}\|_1 = \sum_{i,j} |\mathbf{X}_{i,j}|$ and $\rho > 0$ is the penalty parameter. Intuitively, by minimizing the sum of $\sum_{i,j}|\mathbf{S}_{i,j} - \mathbf{V}_{i,j}|$ with a penalty parameter $\rho$, the element-wise differences between the two matrices $\mathbf{S}$ and $\mathbf{V}$ are penalized during the optimization process, where the penalization strength is controlled by $\rho$.

Furthermore, observe that the equality constraint $\mathbf{S}_{i,j} = \mathbf{V}_{i,j}$ can also be represented by two inequality constraints, i.e., $\mathbf{S}_{i,j} \ge \mathbf{V}_{i,j}$ and $\mathbf{V}_{i,j} \ge \mathbf{S}_{i,j}$. This allows us to write the second term containing the $\ell_1$ norm in~\eqref{eq:S_udpate_SV_penalty} as the sum of two separate terms. Specifically, let $[x]^- = \max\{0, -x\}$, and introduce two non-negative matrices $\boldsymbol{\rho}^+ \in \mathbb{R}^{k \times N}$ and $\boldsymbol{\rho}^- \in \mathbb{R}^{k\times N}$ that store the penalty parameters, the penalty problem~\eqref{eq:S_udpate_SV_penalty} becomes
\begin{equation}
    \label{eq:S_udpate_SV_penalty_2}
    \begin{aligned}
    & \min_{\mathbf{S}, \mathbf{V}}  && \langle \mathbf{Y}, \mathbf{S} \rangle + \sum_{i,j}\boldsymbol{\rho}^+_{i,j} [\mathbf{S}_{i,j}-\mathbf{V}_{i,j}]^- + \sum_{i,j}\boldsymbol{\rho}_{i,j}^- [\mathbf{V}_{i,j} - \mathbf{S}_{i,j}]^-,  \\
    & \text{subject to} && 0 \le \mathbf{S}_{i,j} \le 1 \;\; \forall i,j,  \\
    & && \mathbf{S} \in \mathbf{\Omega}, \;\; \mathbf{V} \in \{0,1\}^{k\times N}. \\
    \end{aligned}
\end{equation}
Note that instead of using one penalty parameter $\rho$ as in~\eqref{eq:S_udpate_SV_penalty}, we associate each matrix index $(i,j)$ with two penalty parameters $\boldsymbol{\rho}^+_{i,j} > 0$ and $\boldsymbol{\rho}^-_{i,j} > 0$ that correspond to the constraints $\mathbf{S}_{i,j} \ge \mathbf{V}_{i,j}$ and $\mathbf{V}_{i,j} \ge \mathbf{S}_{i,j}$, respectively.

We are now ready to introduce the alternating optimization scheme to solve the problem \eqref{eq:S_udpate_SV_penalty_2}. The algorithm consists of iteratively updating $\mathbf{S}$ and $\mathbf{V}$ until convergence. Particularly, let $t$ denote the iteration, the update steps for $\mathbf{S}$ and $\mathbf{V}$ can be formulated as follows

\subsubsection{S update step} With $\mathbf{V}$ fixed to the value at iteration $t$, updating $\mathbf{S}$ at iteration $t+1$ amounts to solving a linear programming (LP) problem.  Specifically, by introducing two non-negative matrices $\boldsymbol{\gamma}^+ \in \mathbb{R}^{k \times N}$ and $\boldsymbol{\gamma}^- \in \mathbb{R}^{k \times N}$, the LP problem to update $\mathbf{S}$ can be written as follows
\begin{subequations}
    \label{eq:S_udpate_SV_penalty_S}
    \begin{align}
    & \mathbf{S}^{(t+1)} = \arg\min_{\mathbf{S}, \boldsymbol{\gamma}}  && \langle \mathbf{Y}, \mathbf{S} \rangle + \sum_{i,j}\boldsymbol{\rho}^+_{i,j} \boldsymbol{\gamma}^+_{i,j} + \sum_{i,j}\boldsymbol{\rho}^-_{i,j} \boldsymbol{\gamma}^-_{i,j} \label{eq:S_udpate_SV_penalty_S:obj}, \\
    &~~~~~~~~~~~~\text{subject to} && \mathbf{V}^{(t)}_{i,j}-\mathbf{S}_{i,j} \le \boldsymbol{\gamma}^+_{i,j} \; \forall i,j \label{eq:S_udpate_SV_penalty_S:gamma1}, \\
    & &&  \mathbf{S}_{i,j} - \mathbf{V}^{(t)}_{i,j} \le \boldsymbol{\gamma}^-_{i,j} \;\; \forall i,j \label{eq:S_udpate_SV_penalty_S:gamma2},\\
    & &&  \boldsymbol{\gamma}^+_{i,j}, \boldsymbol{\gamma}^-_{i,j} \ge 0 \;\;\ \forall i,j, \\
    & && 0 \le \mathbf{S}_{i,j} \le 1 \;\; \forall i,j, \;\;\;\mathbf{S} \in \mathbf{\Omega}.
    \end{align}
\end{subequations}
Note that the purpose of introducing $\boldsymbol{\gamma}^+$ and $\boldsymbol{\gamma}^-$ is to eliminate the $[.]^-$ operator in the objective function of~\eqref{eq:S_udpate_SV_penalty_2} -- based on the observation that $[x]^- \ge 0 \;\forall x$. Therefore, the problem~\eqref{eq:S_udpate_SV_penalty_2} and~\eqref{eq:S_udpate_SV_penalty_S} with fixed $\mathbf{V}$ are equivalent. As~\eqref{eq:S_udpate_SV_penalty_S} is a convex LP problem, it can be solved efficiently using any off-the-shelf solver.

\subsubsection{V update step} After $\mathbf{S}$ is updated by solving the LP problem~\eqref{eq:S_udpate_SV_penalty_S}, starting from~\eqref{eq:S_udpate_SV_penalty_2}, the task of updating $\mathbf{V}$ with fixed $\mathbf{S}$ can be written as
\begin{equation}
    \label{eq:S_udpate_SV_penalty_V}
    \begin{aligned}
    & \mathbf{V}^{(t+1)} = \;\arg\min_{\mathbf{V}}\;  && \sum_{i,j}\boldsymbol{\rho}^+_{i,j} [\mathbf{S}^{(t+1)}_{i,j}-\mathbf{V}_{i,j}]^- + \sum_{i,j}\boldsymbol{\rho}_{i,j}^- [\mathbf{V}_{i,j} - \mathbf{S}^{(t+1)}_{i,j}]^-,  \\
    &~~~~~~~~~~~~~~\text{subject to} &&  \mathbf{V} \in \{0,1\}^{k\times N}.  \\
    \end{aligned}
\end{equation}
Due to the fact that the objective function of~\eqref{eq:S_udpate_SV_penalty_V} consists of non-negative terms, solving for $\mathbf{V}$ can be done element-wise. Moreover, as each element $\mathbf{V}_{i,j} \in \{0,1\}$, it can be updated by choosing the value that results in the smaller objective value
\begin{equation}
    \label{eq:S_update_SV_V_closedform}
    \mathbf{V}^{(t+1)}_{i,j} = \begin{cases}
        0, \;\;\; \text{if} \;\; \boldsymbol{\rho}^-_{i,j}\mathbf{S}^{(t+1)}_{i,j} \le  \boldsymbol{\rho}_{i,j}^+ \left(1 - \mathbf{S}^{(t+1)}_{i,j}\right),  \\
        1, \;\;\; \text{otherwise.}
    \end{cases}
\end{equation}

\subsubsection{Updating penalty parameters}
From~\eqref{eq:S_update_SV_V_closedform}, it can be seen that for a fixed value of $\mathbf{S}^{(t+1)}_{i,j}$, the penalty parameters $\boldsymbol{\rho}^+_{i,j}$ and $\boldsymbol{\rho}^-_{i,j}$ control the weights for updating $\mathbf{V}^{(t+1)}_{i,j}$. Particularly, if $\boldsymbol{\rho}^+_{i,j}$ is much larger than $\boldsymbol{\rho}^-_{i,j}$, the value of $0$ is more favorable for $\mathbf{V}^{(t+1)}_{i,j}$ (since $ \boldsymbol{\rho}_{i,j}^+ (1 - \mathbf{S}^{(t+1)}_{i,j}) \gg \boldsymbol{\rho}^-_{i,j}\mathbf{S}^{(t+1)}_{i,j})$ , and vice versa. Thus, in other to prevent early convergence to a bad local minima, if $\mathbf{V}^{(t+1)}_{i,j} = 0$ at iteration $t+1$, we increase $\boldsymbol{\rho}^-_{i,j}$ to give $\mathbf{V}_{i,j}$ chances to be assigned with the value of $1$ in the later iterations. Similar argument can be applied for the case of $\mathbf{V}^{(t+1)}_{i,j}=1$. The penalty parameters, therefore, are updated as follows
\begin{equation}
    \label{eq:rho_update}
    \boldsymbol{\rho}^{-(t+1)}_{i,j} =  \begin{cases}
        \kappa\boldsymbol{\rho}^{-(t)}_{i,j}, \;\; \text{if}\;\; \mathbf{V}^{(t+1)}_{i,j} = 0, \\
        \boldsymbol{\rho}^{-(t)}_{i,j}, \;\;\; \text{otherwise},
    \end{cases} \text {and} \;\;
    \boldsymbol{\rho}^{+(t+1)}_{i,j} =  \begin{cases}
        \kappa\boldsymbol{\rho}^{+(t)}_{i,j}, \;\; \text{if}\;\; \mathbf{V}^{(t+1)}_{i,j} = 1, \\
        \boldsymbol{\rho}^{+(t)}_{i,j}, \;\;\; \text{otherwise},
    \end{cases}
\end{equation}
where $\kappa$ is a positive number that controls the increase rate. Note that besides controlling the updating of $\mathbf{V}$ in~\eqref{eq:S_update_SV_V_closedform}, the $\boldsymbol{\rho}^+$ and $\boldsymbol{\rho}^-$ parameters also affect the solution of~\eqref{eq:S_udpate_SV_penalty_S}. Specifically, by gradually increasing $\boldsymbol{\rho}^+$ and $\boldsymbol{\rho}^-$ as in~\eqref{eq:rho_update}, the weights for the second and third terms in the objective function~\eqref{eq:S_udpate_SV_penalty_S:obj} become higher in the later iterations, forcing~\eqref{eq:S_udpate_SV_penalty_S} to drive $\mathbf{S}$ to integrality.

\begin{comment}
This insight can be illustrated by considering the following example. Assume that at iteration $t$, $\mathbf{V}^{(t)}_{i,j}$ is assigned with the value of $1$. Then, during the $\mathbf{S}$ update step at iteration $t+1$, the constraint~\eqref{eq:S_udpate_SV_penalty_S:gamma1} at the index $(i,j)$ always hold  since $0\le \mathbf{S}_{i,j} \le 1$ and $\mathbf{S}_{i,j} - 1 \le 0$. Therefore, at iteration $(t+1)$, $\boldsymbol{\gamma}^+_{i,j}$ will be updated the value of $0$, which means $\boldsymbol{\rho}^+_{i,j}$ has no effect on the LP~\eqref{eq:S_udpate_SV_penalty_S}. Therefore, with a sufficiently large $\boldsymbol{\rho}^-_{i,j}$, by minimizing $\boldsymbol{\rho}^-_{i,j}\boldsymbol{\gamma}^-_{i,j}$, the LP~\eqref{eq:S_udpate_SV_penalty_S} finds feasible points such that $\mathbf{S}_{i,j}$ is close to $1$.
\end{comment}
\subsection{Formulation}
Before introducing our approach to tackle constrained K-Means, let us first re-formulate~\eqref{eq:constrained_k_means} as a binary optimization problem.  Let $\mathbf{X} \in \mathbb{R}^{d\times N}$ be the matrix containing the set of $N$ data points, where each point $\mathbf{x}_i \in \mathbb{R}^d$ corresponds to the $i$-th column of $\mathbf{X}$), and $\mathbf{C} \in \mathbb{R}^{d\times k}$ be the matrix that stores the set of $k$ centroids (each centroid lies in one column of $\mathbf{C}$). Additionally, let the cluster assignments be represented by a matrix $\mathbf{S} \in \mathbb{R}^{k \times N}$, where $\mathbf{S}_{ij}$ has the value of $1$ if the data point $\mathbf{x}_j$ is assigned to the $i$-th cluster and $0$ otherwise. The problem~\eqref{eq:constrained_k_means} can now be written as follows
\begin{subequations}
\label{eq:constrained_k_means_01}
\begin{align}
& \min_{\mathbf{C}, \mathbf{S}}  && \| \mathbf{X}  - \mathbf{C}\mathbf{S}\|^2_F, \label{eq:constrained_k_means_01:obj}\\
& \text{subject to} && \mathbf{S}_{ij} \in \{0, 1\} \;\; \forall i,j, \label{eq:constrained_k_means_01:binary} \\
& && \sum_{i=1}^k \mathbf{S}_{ij} = 1 \;\; \forall j = 1\dots N, \label{eq:constrained_k_means_01:cluster_assign} \\
& && l_i \le \sum_{j=1}^N \mathbf{S}_{ij} \le u_i \;\; \forall i=1 \dots k, \label{eq:constrained_k_means_01:size_constraint} \\
& && \mathbf{S}_{ip} = \mathbf{S}_{iq}, \;\; i = 1\dots k \;\; \forall (\mathbf{x}_p, \mathbf{x}_q) \in \mathcal{M}_t, \; t=1\dots m, \label{eq:constrained_k_means_01:must_link} \\
& && \mathbf{S}_{ip} + \mathbf{S}_{iq} \le 1, \;\; i = 1\dots k \;\; \forall (\mathbf{x}_p, \mathbf{x}_q) \in \mathcal{D}_t, \; t=1\dots m. \label{eq:constrained_k_means_01:must_not_link}
\end{align}
\end{subequations}
With the re-arrangements of variables into the matrices $\mathbf{X}$, $\mathbf{C}$ and $\mathbf{S}$, the objective function~\eqref{eq:constrained_k_means:obj} translates to~\eqref{eq:constrained_k_means_01:obj} where $\|.\|_F$ denotes the Frobenius norm of a matrix. The constraint~\eqref{eq:constrained_k_means_01:binary} restricts $\mathbf{S}$ to be a binary assignment matrix, while the second constraint~\eqref{eq:constrained_k_means_01:cluster_assign} allows each point to be assigned to only one cluster. The set cardinality requirements in~\eqref{eq:constrained_k_means:size} are reflected by the third constraint~\eqref{eq:constrained_k_means_01:size_constraint}, as the sum of all elements on the $i$-th row of $\mathbf{S}$ is the number of points being assigned to the $i$-th cluster. Finally,~\eqref{eq:constrained_k_means_01:must_link} and~\eqref{eq:constrained_k_means_01:must_not_link} enforce the must-link and cannot-link constraints. The intuition behind~\eqref{eq:constrained_k_means_01:must_link} is that if two data points $\mathbf{x}_p$ and $\mathbf{x}_q$ have the same cluster assignment, the $p$-th column and $q$-th column of $\mathbf{S}$ must be identical. Consequently, if two data points $\mathbf{x}_p$ and $\mathbf{x}_q$ belong to the same cluster, the element-wise sum of the $p$-th column and $q$-th column of $\mathbf{S}$ must contain a value of $2$. Therefore, by restricting the element-wise sum to be less than $2$ as~\eqref{eq:constrained_k_means_01:must_not_link}, the cannot-link constraint can be enforced.

Henceforth, for the sake of brevity, we define $\mathbf{\Omega}$ as the convex domain in which the linear constraints~\eqref{eq:constrained_k_means_01:cluster_assign},~\eqref{eq:constrained_k_means_01:size_constraint},~\eqref{eq:constrained_k_means_01:must_link},~\eqref{eq:constrained_k_means_01:must_not_link} are satisfied, i.e.,
\begin{equation}
    \label{eq:omega_definition}
    \mathbf{\Omega} = \{ \mathbf{S} \in \mathbb{R}^{k\times N} | ~\eqref{eq:constrained_k_means_01:cluster_assign},~\eqref{eq:constrained_k_means_01:size_constraint},~\eqref{eq:constrained_k_means_01:must_link},~\eqref{eq:constrained_k_means_01:must_not_link} \}.
\end{equation}
With the re-formulation~\eqref{eq:constrained_k_means_01} of the constrained K-Means problem, besides the introduced constraints, other restrictions on point assignments can be explicitly enforced by introducing additional constraints for the matrix $\mathbf{S}$. Therefore, our proposed method for addressing constrained K-Means by solving~\eqref{eq:constrained_k_means_01} can be generalized to incorporate different types of constraints.

\subsubsection{Contributions} In this paper, we revisit the constrained K-Means clustering problem and propose a novel approach to address it in such a way that different types of constraints can be simultaneously enforced. Particularly, we look at the problem at the perspective of a binary optimization problem and devise an algorithm to optimize it so that all the constraints are strictly enforced at each iteration. Unlike other relaxation schemes, our algorithm aims to find feasible solutions in the binary domain, i.e., the cluster assignments are represented by a binary matrix that satisfies the given constraints. One notable feature of our technique is that different types of constraints can be easily integrated into the proposed framework. The experiment results on multiple synthetic and real datasets show that our technique provides much better clustering quality while the run time is comparable to (or even faster than) other approaches.

\begin{comment}
When being employed in quantization-based methods for image retrieval, K-Means can be considered as a divide step in a general divide-and-conquer strategy. In several works, K-Means is integrated into an alternative optimization process.

One example constraint for K-Means is the balance constraint. In many applications, it may require that the cluster sizes are approximately the same for all clusters. To the best of our knowledge, the use of balanced K-Means for PQ has not been thoroughly investigated in the literature and there exist no algorithms in the literature that tackle this problem.

In this paper, we propose a general optimization framework for balanced K-Means that is inspired by recent advances in binary optimization. From the new algorithm to learn K-Means, we develop a new quantization approach that jointly learns the data transformation and balanced clustering.

\end{comment}

\subsection{K-Means clustering}
\label{sec:k-means}
Given a set $\mathcal{X}$ containing $N$ data points $\mathcal{X} = \{ \mathbf{x}_j \}_{j=1}^N$, where $\mathbf{x}_j \in \mathbb{R}^d$, the goal of K-Means is to partition $\mathcal{X}$ into $k$ non-overlapping clusters. Specifically, K-Means finds a set $\mathcal{C}$ containing $k$ centroids $\mathcal{C} = \{\mathbf{c}_i\}_{i=1}^k$,  and an assignment that distributes the points into $k$ distinct groups $\mathcal{S}_1, \dots, \mathcal{S}_k$, where $\mathcal{S}_1 \cup \dots \cup \mathcal{S}_k = \mathcal{X}$ and $\mathcal{S}_i \cap \mathcal{S}_j = \emptyset\; \forall i\neq j$, that minimizes the \emph{within cluster sum of squares} (WCSS) distortion. Mathematically speaking, K-Means clustering can be formulated as the following optimization problem
\begin{equation}
\label{eq:k_means}
\min_{\mathcal{C}, \mathcal{S}_1,\dots,\mathcal{S}_k} \sum_{i=1}^k \sum_{\mathbf{x}_j \in \mathcal{S}_i} ||\mathbf{x}_j - \mathbf{c}_i||^2_2.
\end{equation}
\subsection{Constrained K-Means}
In several applications, it is sometimes desirable to impose some particular restrictions on the clustering. For the ease of representation, we focus on the cluster size constraints~\cite{bradley2000constrained,liu2017balanced}, and must-link/cannot-link constraints~\cite{wagstaff2001constrained}, while other types of constraints (assuming that they can be converted into linear constraints), depending on the applications, can also be integrated into our proposed framework in a similar manner. Assume that we are given as a priori $m$ subsets $\mathcal{M}_1, \dots, \mathcal{M}_m$, where $\mathcal{M}_i \subset \mathcal{X}$ and points belonging to a particular set $\mathcal{M}_i$ \emph{must} be grouped into the same cluster. Likewise, assume that $h$ subsets $\mathcal{D}_1,\dots, \mathcal{D}_h$ are given, where $\mathcal{D} \subset \mathcal{X}$ and each set $\mathcal{D}_i$ contains points that \emph{must not} be in the same cluster.   Let $f$ represent the cluster assignment operation, i.e., $f(\mathbf{x})$ is the cluster that $\mathbf{x}$ is assigned to. Similar to~\eqref{eq:k_means}, constrained K-Means also seeks to find the set of $k$ cluster centroids $\mathcal{C}$ and the subsets $\mathcal{S}_i$ that minimize the WCSS distortion with additional constraints on the clusters, which can be mathematically expressed as
\begin{subequations}
    \label{eq:constrained_k_means}
    \begin{align}
    & \min_{\mathcal{C}, f, \mathcal{S}_1,\dots,\mathcal{S}_k}  && \sum_{i=1}^k \sum_{\mathbf{x}_j \in \mathcal{S}_i} ||\mathbf{x}_j - \mathbf{c}_i||^2_2, \label{eq:constrained_k_means:obj} \\
    & \text{subject to} && l_i \le |\mathcal{S}_i| \le u_i, \;\; \forall i = 1\dots k, \label{eq:constrained_k_means:size} \\
    & &&                   f(\mathbf{p}^t) = f(\mathbf{q}^t) \;\; \forall (\mathbf{p}^t, \mathbf{q}^t) \in \mathcal{M}_t, \; t=1\dots m,  \label{eq:constrained_k_means:must_link} \\
    & &&                   f(\mathbf{p}^t)\neq f(\mathbf{q}^t) \;\; \forall (\mathbf{p}^t, \mathbf{q}^t) \in \mathcal{D}_t, \; \mathbf{p}^t \neq \mathbf{q}^t \; \; t=1\dots h,  \label{eq:constrained_k_means:must_not_link}
    \end{align}
\end{subequations}
where the notation $|\;.\;|$ denotes the cardinality of a set, and the pairs $\{(l_i, u_i)\}_{i=1}^k$ represent the lower and upper bound on the sizes of the corresponding clusters. The constraints~\eqref{eq:constrained_k_means:size} limit the sizes of the clusters, while the must-link and cannot-link constraints are reflected by~\eqref{eq:constrained_k_means:must_link} and~\eqref{eq:constrained_k_means:must_not_link}, i.e., $f$ must assign all points in $\mathcal{M}_t$ to the same cluster and, similarly, points reside in the same $\mathcal{D}_t$ must be distributed into different clusters.

\subsection{Balanced clustering on synthetic data}
In this experiment, we test the performance of the methods on the task of balanced clustering with must-link and cannot-link constraints on high dimensional data. Note that our algorithm, based on the formulation~\eqref{eq:constrained_k_means_01}, is capable of handling different bounds on cluster sizes. However, we conduct experiments on balanced clustering to provide a fair comparison for algorithms that can only handle balance constraints~\cite{liu2017balanced}.
We randomly generate $k$ clusters, where each cluster contains $n$ data points. We choose $N = kn \approx 500$ data points, and each data point $\mathbf{x}_i$ belongs the space of $\mathbb{R}^{d}$ (with $d=512$).
To generate the set containing $k$ cluster centers $\{\mu_i\}_{i=1}^k$, we uniformly sample $k$ points in the hyperbox $[-1,1]^d$. For each $i$-th cluster, its members are generated by randomly drawing $n$ points from a Gaussian distribution with mean $\mu_i$ and covariance matrix of $\sigma\mathbf{I}$ ($\mathbf{I}$ is the identity matrix).
To achieve balanced clustering, we set the lower bounds on the cluster sizes for all clusters to be $n$.  Besides, within each cluster, $20\%$ of the points are randomly sampled to generate must-link and cannot-link constraints.

Figure~\ref{fig:synthetic_results} shows experiment results for $\sigma = 0.1$ (top row), $\sigma = 0.5$ (second row) and $\sigma = 0.7$ (bottom row), respectively. On each row of Figure~\ref{fig:synthetic_results}, we plot the NMI (left) and run time (right) for all the methods.
As can be observed from this figure, with small values of $k$, all methods provide relatively good clustering results. As $k$ increases, however, the performances of all methods also degrade (with lower NMI). Among them, our proposed method provides the best NMI result due to its ability to strictly enforce the constraints. Note that although the linking constraints are also added to the LP formulation in~\cite{bradley2000constrained}, our method is able to achieve much higher NMI due to its ability to find good binary solutions, while our runtime is only slightly higher compared to that of~\cite{bradley2000constrained}. Observe that as the value of $\sigma$ increases, the performance of the methods also degrade, but ours is able to achieve the best NMI compared to others as the constraints are properly enforced.

To demonstrate the ability to provide balanced clusters, we plot in Figure~\ref{fig:synthetic_cluster_distribution} the number of points distributed into each cluster by K-Means and our method for three different values of $k$ (we use K-Means to initialize our method). Observe that as $k$ increases, the clusters provided by K-Means becomes highly unbalanced. With such unbalanced initializations, however, our method is able to refine the initial solutions and return balanced clusters, while the must-link and cannot-link constraints are also enforced to provide better NMI compared to other approaches.
\begin{figure}
    \centering
    \includegraphics[width = 0.45\textwidth]{figs/nmi_sigma01.pdf}
    \includegraphics[width = 0.45\textwidth]{figs/time_sigma01.pdf}\\
    \includegraphics[width = 0.45\textwidth]{figs/nmi_sigma05.pdf}
    \includegraphics[width = 0.45\textwidth]{figs/time_sigma05.pdf}\\
    \includegraphics[width = 0.45\textwidth]{figs/nmi_sigma07.pdf}
    \includegraphics[width = 0.45\textwidth]{figs/time_sigma07.pdf}
    \caption{NMI (left column) and run time (right) for different values of clusters with $N=500$ points and $d=512$. First row: NMI and run time for $\sigma = 0.1$. Second row: NMI and run time for $\sigma = 0.5$. Last row: NMI and run time for $\sigma = 0.7$.}
    \label{fig:synthetic_results}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width = 0.31\textwidth]{figs/cluster_dist_10.pdf}
    \includegraphics[width = 0.31\textwidth]{figs/cluster_dist_20.pdf}

    \includegraphics[width = 0.31\textwidth]{figs/cluster_dist_30.pdf}
    \caption{Cluster distribution of K-Means and our method for 3 different values of $k={10, 20, 50}$ (from left to right). }
    \label{fig:synthetic_cluster_distribution}
\end{figure}
\subsection{Clustering on real datasets}
Besides testing with synthetic data, we also conduct experiments on some real datasets that are often employed to benchmark clustering algorithms, including MNIST~\cite{lecun1998gradient}, ORL Face Dataset\footnote{http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html}, UMIST Face Datset\footnote{https://www.sheffield.ac.uk/eee/research/iel/research/face}, Yale Dataset\footnote{http://vision.ucsd.edu/content/yale-face-database} and YaleB Dataset\footnote{http://vision.ucsd.edu/content/extended-yale-face-database-b-b}.
\begin{comment}
    \begin{itemize}
    \item MNIST~\cite{lecun1998gradient}: MNIST is a well-known dataset for hand-written digits, which contains 60,000 training images and 10,000 testing images.
    \item ORL Face Dataset\footnote{http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html}: This face dataset contains 40 subjects (classes), and each class contain 10 images.
    \item UMIST Face Datset\footnote{https://www.sheffield.ac.uk/eee/research/iel/research/face}: UMIST contains 564 images with different appearance of 20 individuals.
    \item Yale Dataset~\footnote{http://vision.ucsd.edu/content/yale-face-database}: This dataset contains 165 gray scale images of 15 individuals with different face expressions and configurations.
    \item YaleB Dataset\footnote{http://vision.ucsd.edu/content/extended-yale-face-database-b-b}: YaleB is an extended version of Yale, which contains 16128 images of 28 different subjects under different poses and illumination conditions.
\end{itemize}

\end{comment}
For each dataset, we randomly sample data points from 10 to 15 clusters, and each cluster contains the same number of instances (for the task of balanced clustering). Within each cluster, we randomly select 20\% of the points to enforce the must-link and cannot-link constraints. For large datasets, we repeat the experiment with different random subsets of data (the subset indexes are shown by the number in the parentheses). The NMI and the run time of the methods are shown in Table.~\ref{table:real}. Similar to the case of synthetic data, throughout most of the experiments, our method provides better NMI compared to other approaches due to its ability to provide assignments that satisfy the constraints. Note that in some cases, the NMI results provided by BCLS and COP are very close to ours, while our run time is much faster. We also apply the must-link and cannot-link constraints to the LP formulation of CKM~\cite{bradley2000constrained}, yet we are able to achieve better NMI. This demonstrates that our binary optimization technique provides better solutions compared to the LP relaxation approach.

\input{tex/table_real}

\subsubsection{$\mathbf{P}$ update}
With the matrix $\mathbf{Q}$ fixed, updating $\mathbf{P}$ amounts to solving a convex Linear Programming problem
\begin{subequations}
    \label{eq:S_udpate_P_update}
    \begin{align}
    & \min_{\mathbf{P}}  && \langle \mathbf{D} - \rho \mathbf{Q}, \mathbf{P} \rangle \\
    & \text{subject to} && -1 \le \mathbf{P}_{ij} \le 1  \\
    & && \sum_{i=1}^k \mathbf{P}_{ij} = 2 - k \;\; \forall j = 1\dots N, \\
    & && 2l_i - N \le \sum_{j=1}^N \mathbf{P}_{ij} \le 2u_i - N \;\; \forall i=1 \dots k. \\
    & && \mathbf{P}_{ip} = \mathbf{P}_{iq}, \;\; i = 1\dots k \;\; \forall (\mathbf{x}_p, \mathbf{x}_q) \in \mathcal{M}_t, \; t=1\dots m. \label{eq:S_udpate_P_update:must_link} \\
    & && \mathbf{P}_{ip} + \mathbf{P}_{iq} \le 1, \;\; i = 1\dots k \;\; \forall (\mathbf{x}_p, \mathbf{x}_q) \in \mathcal{D}_t, \; t=1\dots m. \label{eq:S_udpate_P_update:must_not_link}\\
    \end{align}
\end{subequations}
\subsubsection{$\mathbf{Q}$ update}
The update step of $\mathbf{Q}$ with a fixed $\mathbf{P}$ can be done by solving the following problem
\begin{subequations}
    \label{eq:S_udpate_Q_update}
    \begin{align}
    & \min_{\mathbf{Q}}  &&  - \langle \mathbf{P}, \mathbf{Q} \rangle \\
    & \text{subject to} && \|\mathbf{Q}\|^2_F \le Nk
    \end{align}
\end{subequations}
In fact,~\eqref{eq:S_udpate_Q_update} can be updated by the following closed-form formular:
\begin{equation}
    \label{eq:S_udpate_Q_update_closed_form}
    \mathbf{Q} = \begin{cases}
    \frac{\sqrt[]{Nk}}{\|\mathbf{P}\|_F}\mathbf{P}, \;\;\; \mathbf{P} \neq \mathbf{0}_{N \times k } \\
    \mathbf{0}_{N\times k}, \;\;\; \text{otherwise.}
    \end{cases}
\end{equation}

Computer Vision and Pattern Recognition (cs.CV); Machine Learning (cs.LG)


Semi-reflexive polytopes

Abstract: The Ehrhart function $L_P(t)$ of a polytope $P$ is usually defined only for integer dilation arguments $t$. By allowing arbitrary real numbers as arguments we may also detect integer points entering (or leaving) the polytope in fractional dilations of $P$, thus giving more information about the polytope. Nevertheless, there are some polytopes that only gain new integer points for integer values of $t$; that is, these polytopes satisfy $L_P(t) = L_P(\lfloor t \rfloor)$. We call those polytopes semi-reflexive. In this paper, we give a characterization of these polytopes in terms of their hyperplane description, and we use this characterization to show that a polytope is reflexive if and only if both it and its dual are semi-reflexive.

\section{
    Characterizing semi-reflexive polytopes
    in terms of their hyperplane description
}
\label{sec:characterization}
(We will use the Iverson bracket in this section.)

In this section,
mostly deal with full-dimensional polytopes.
If $P$ is full-dimensional,
then in the representation~\eqref{intersection-representation}
the number $n$ may be chosen to be the number of facets in $P$.
In this case,
each hyperplane $\{ x \mid \langle a_i, x \rangle = b_i \}$ intersects $P$ in a facet,
so that there is no redundant hyperplanes;
that is, such representation is minimal.
We'll assume such representations are always minimal for full-dimensional polytopes.

For full-dimensional polytopes,
there is a slight generalization
of the hyperplane description of Theorem~\ref{thm:characterization}.
Instead of demanding that $a_i$ is an integer for all $i$,
we will only require that $a_i$ is an integer if the corresponding $b_i$ is $1$.
Thus, if $b_i = 0$, then $a_i$ may be an arbitrary vector.
Observe that,
for rational polytopes,
$a_i$ will necessarily be a rational vector,
so when $b_i = 0$ we may multiply both sides by an appropriate integer constant
(the $\lcm$ of all denominators of the coordinates of $a_i$)
to get the same condition of Theorem~\ref{thm:characterization}.

One direction is easy.

\begin{theorem}
    \label{thm:if-part}
    Let $P$ be as in~\eqref{intersection-representation}.
    If all $b_i$ is either $0$ or $1$,
    and $a_i$ is integral whenever $b_i = 1$,
    then $L_P(s) = L_P(\floor s)$.
\end{theorem}

\begin{proof}
    \begin{equation*}
        L_P(s)
            = \sum_{x \in \mathbb Z^d} [x \in sP]
            = \sum_{x \in \mathbb Z^d} \prod_{i = 1}^n
                \big[\langle a_i, x \rangle \leq s b_i\big].
    \end{equation*}

    If $b_i = 0$, the term $[\langle a_i, x \rangle \leq s b_i]$
    reduces to $[\langle a_i, x \rangle \leq 0]$,
    which is constant for all $s$;
    thus $[\langle a_i, x \rangle \leq s b_i]
    = \big[\langle a_i, x \rangle \leq \floor s b_i\big]$.

    If $b_i = 1$,
    as $x$ and $a_i$ are integral,
    the number $\langle a_i, x \rangle$ is an integer,
    thus $[\langle a_i, x \rangle \leq s b_i]
    = \big[\langle a_i, x \rangle \leq \floor s b_i\big]$ again.

    Therefore,
    \begin{align*}
        L_P(s)  &= \sum_{x \in \mathbb Z^d} \prod_{i = 1}^n
                    \big[\langle a_i, x \rangle \leq s b_i\big] \\
                &= \sum_{x \in \mathbb Z^d} \prod_{i = 1}^n
                    \big[\langle a_i, x \rangle \leq \floor s b_i\big] \\
                &= \sum_{x \in \mathbb Z^d} [x \in \floor s P] \\
                &= L_P(\floor s).
                \qedhere
    \end{align*}
\end{proof}

For the other direction we need a lemma.

Denote the open ball with radius $\delta$ centered at $x$ by $B_\delta(x)$;
that is,
if $x \in \mathbb R^d$,
we have
\begin{equation*}
    B_\delta(x) = \{y \in \mathbb R^d \mid \norm{y - x} < \delta\}.
\end{equation*}

\begin{lemma}
    \label{thm:integral-points-in-cone}
    Let $K$ be a full-dimensional cone with apex $0$,
    and let $\delta > 0$ be any value.
    Then there are infinitely many integer points $x \in K$
    such that $B_\delta(x) \subset K$.
\end{lemma}

That is,
there are many points which are ``very inside'' $K$.

\begin{proof}
    Choose $x$ to be any rational point in the interior of the cone.
    By definition,
    there is some $\varepsilon > 0$ with $B_\varepsilon(x) \subseteq K$.
    For any $\lambda > 0$,
    we have
    \begin{equation*}
        \lambda B_\varepsilon(x) = B_{\lambda \varepsilon}( \lambda x ) \subseteq K.
    \end{equation*}

    For all sufficiently large $\lambda$,
    we have $\lambda \varepsilon > \delta$,
    so we just need to take the infinitely many integer $\lambda$
    such that $\lambda x$ is an integer vector.
\end{proof}

We'll need the fact that these integral points are distant from the boundary
only in the proof of Theorem~\ref{thm:only-if-part}.
For the next theorem,
existence of infinitely many such points would be enough.

\begin{proposition}
    \label{thm:weak-only-if-part}
    Let $P$ be a full-dimensional polytope.
    If $0 \notin P$,
    then $L_P(s)$ is not a nondecreasing function.
    In fact, $L_P(s)$ has infinitely many ``drops'';
    that is,
    there are infinitely many points $s_0$
    such that $L_P(s_0) > L_P(s_0 + \varepsilon)$
    for sufficiently small $\varepsilon > 0$.
\end{proposition}

\begin{proof}
    Writing $P$ as in~\eqref{intersection-representation},
    we conclude at least one of the $b_i$ must be negative
    (because the vector $0$ satisfies every linear restriction where $b_i \geq 0$).
    Equivalently (dividing both sides by $b_i$),
    there is a half-space of the form $\{x \mid \langle u, x \rangle \geq 1\}$
    such that some facet $F$ of $P$ is contained in
    $\{x \mid \langle u, x \rangle = 1\}$.

    Now, consider the cone $\bigcup_{\lambda > 0} \lambda F$.
    The previous lemma says
    there is an integral point $x_0$ in this cone,
    and so by its definition we have $x_0 \in s_0 F$ for some $s_0 > 0$;
    thus, $x_0 \in s_0 P$.
    We'll argue that, for all sufficiently small $\varepsilon > 0$,
    the polytopes $(s_0 + \varepsilon)P$ do not contain any integral point
    which is not present in $s_0 P$ (Figure~\ref{fig:polytope-not-containing-origin}).

    \begin{figure}[t]
        \centering
        \begin{tikzpicture}

            \def(1.5, -0.5) -- ++(-2, 2) -- ++(2, 2) -- ++(2, -2) -- cycle{(1.5, -0.5) -- ++(-2, 2) -- ++(2, 2) -- ++(2, -2) -- cycle}
            \filldraw[blue, thick, fill = blue!40] (1.5, -0.5) -- ++(-2, 2) -- ++(2, 2) -- ++(2, -2) -- cycle;
            \node [blue!50!black] at (1.5, 1.5) {$s_0 P$};

            \draw[scale = 1.15, green!30!black] (1.5, -0.5) -- ++(-2, 2) -- ++(2, 2) -- ++(2, -2) -- cycle;
            \node[green!30!black] at (4, 0.5) {$(s_0+\varepsilon) P$};

            \draw[very thick, red] (1.5, -.5) -- ++(-2, 2)
                node[below=0.2cm] {$F$};

            \begin{pgfonlayer}{background}
                \draw[lightgray] (-1, 0) -- (4, 0)
                            (0, -1) -- (0, 4);
            \end{pgfonlayer}{background}
            \foreach \x in {-1, ..., 4}
                \foreach \y in {-1, ..., 4}
                    \fill (\x, \y) circle [radius = 1pt];
            \node [below left] at (0, 0) {$0$};

            \fill (1, 0) circle [radius=2pt]
                node [below left] {$x_0$};
        \end{tikzpicture}

        \caption[
            If the polytope is dilated it will lose the point $x_0$.
        ]{
            The polytope $P$,
            when dilated,
            loses the point $x_0$,
            but if the dilation is small enough
            then it does not gain any new integral point.
            Therefore, $L_P(s)$ will decrease from $s_0$ to $s_0 + \varepsilon$.
        }
        \label{fig:polytope-not-containing-origin}
    \end{figure}

    For small $\varepsilon$ (say, $\varepsilon < 1$),
    all these polytopes are ``uniformly bounded'';
    that is, there is some $N$ such that $(s_0 + \varepsilon)P \subseteq [-N, N]^d$
    for all $0 \leq \varepsilon < 1$.
    Each integral $x$ in $[-N, N]^d$ which is not in $s_0 P$
    must violate a linear restriction of the form $\langle a_i, x \rangle \leq s_0 b_i$;
    that is, $\langle a_i, x \rangle > s_0 b_i$ for some $i$.
    As we're dealing with real variables,
    we also have $\langle a_i, x \rangle > (s_0 + \varepsilon) b_i$
    for all sufficiently small $\varepsilon$,
    say, for all $\varepsilon < \delta_x$ for some $\delta_x > 0$.
    Now, as there is a finite number of such relevant integral $x$,
    we can take $\delta$ to be the smallest of all such $\delta_x$;
    then if $0 < \varepsilon < \delta$
    every integral point of $(s_0 + \varepsilon)P$ also appears in $s_0 P$.

    But the special restriction $\langle u, x \rangle \geq 1$,
    considered above,
    ``dilates'' to the linear restriction
    $\langle u, x \rangle \geq s_0 + \varepsilon$ in $(s_0 + \varepsilon)P$.
    Since $x_0$ satisfy this restriction with equality for $\varepsilon = 0$,
    for any $\varepsilon > 0$ we'll have $x_0 \notin (s_0 + \varepsilon)P$.
    Therefore,
    not only the dilates $(s_0 + \varepsilon)P$ do not contain new integral points
    (for small enough $\varepsilon$),
    but actually these dilates lose the point $x_0$ if $\varepsilon > 0$.
    Thus,
    $L_P(s_0) > L_P(s_0 + \varepsilon)$ for all sufficiently small $\varepsilon > 0$.

    Finally,
    there are infinitely many integral $x_0$ in the cone
    $\bigcup_{\lambda > 0} \lambda F$;
    thus we have infinitely many different values of $\norm{x_0}$
    and hence of $s_0$,
    and the reasoning above shows $L_P(s)$ ``drops'' in every such $s_0$.
\end{proof}

A simple consequence of this proposition is that
if $s_0$ is a point where $L_P(s)$ ``drops'',
then in the interval $\big[\!\floor{s_0}, \floor{s_0} + 1\big)$
the function $L_P(s)$ will not be a constant function,
so we cannot have $L_P(s) = L_P(\floor s)$ for all $s$
if $P$ does not contain the origin.

We're now able to show that,
for full-dimensional polytopes,
the converse of Theorem~\ref{thm:if-part} holds.

\begin{theorem}
    \label{thm:only-if-part}
    Let $P$ be a full-dimensional polytope.
    If $L_P(s) = L_P(\floor s)$,
    then the polytope $P$ can be written as in~\eqref{intersection-representation}
    where each $b_i$ is either $0$ or $1$,
    and when $b_i = 1$ the vector $a_i$ must be integral.
\end{theorem}

\begin{proof}
    Since $0 \in P$, by the previous proposition,
    we know we can write $P$ as in~\eqref{intersection-representation},
    with each $b_i$ being nonnegative.
    By dividing each inequality by the corresponding $b_i$ (if $b_i \neq 0$),
    we may assume each $b_i$ is either $0$ or $1$.
    Now we must show that when $b_i = 1$,
    the vector $a_i$ will be integral.

    Let $\langle u, x \rangle \leq 1$ be one of the linear restrictions where $b_i = 1$.
    Using an approach similar to the proof of the previous proposition,
    we'll show $u$ must be an integral vector.

    Let $F$ be the facet of $P$ which is contained in $\{\langle u, x \rangle = 1\}$,
    and again define $K = \bigcup_{\lambda \geq 0} \lambda F$.
    Suppose $u$ has a non-integer coordinate;
    first, we'll find an integral point $x_0$ and a non-integer $s_0 > 0$
    such that $x_0 \in s_0 F$.

    By Lemma~\ref{thm:integral-points-in-cone}
    (using $\delta = \frac32$),
    there is some integral $y \in K$ such that $B_{\frac32}(y) \subset K$.
    If $\langle u, y \rangle$ is not an integer,
    we may let $x_0 = y$ and $s_0 = \langle u, y \rangle$;
    then $x_0$ is an integral point which is in the relative interior of $s_0 F$.
    If $\langle u, y \rangle$ is an integer,
    as $u$ is not an integral vector,
    some of its coordinates is not an integer,
    say the $j$th;
    then $\langle u, y + e_j \rangle$ will not be an integer,
    so (as $y + e_j \in B_{\frac32}(y) \subset K$)
    we may let $x_0 = y + e_j$ and $s_0 = \langle u, y + e_j \rangle$
    to obtain our desired integral point which is in a non-integral dilate of $F$.

    We have $sP \subset s_0 P$ for $s < s_0$,
    but $x_0 \notin sP$ for any $s < s_0$,
    so $L_P(s) < L_P(s_0)$ for all $s < s_0$.
    As $s_0$ is not an integer (by construction),
    this shows that $L_P(\floor{s_0}) < L_P(s_0)$,
    a contradiction.
\end{proof}

Finally,
using unimodular transforms,
we may show the characterization for rational polytopes.

\begin{restatetheorem}{thm:characterization}
    Let $P$ be a rational polytope
    written as in~\eqref{intersection-representation}.
    Then $L_P(s) = L_P(\floor s)$
    if and only if all $a_i$ are integers
    and all $b_i$ are either $0$ or $1$.
\end{restatetheorem}

\begin{proof}
    The ``if'' part is Theorem~\ref{thm:if-part},
    so assume that $L_P(s) = L_P(\floor s)$.
    By Proposition~\ref{thm:weak-only-if-part},
    we must have $0 \in P$.
    If $P$ is full-dimensional,
    we just need to apply Theorem~\ref{thm:only-if-part}:
    if any of the $a_i$ is non-integer,
    then it must be rational (because $P$ is rational)
    and the corresponding $b_i$ must be zero,
    so we may just multiply the inequality
    by the $\lcm$ of the denominators of the coordinates of $a_i$.
    Thus, assume that $P$ is not full-dimensional.

    Let $L = \aff P$,
    the affine hull of $P$.
    Since $P$ contains the origin,
    $L$ is a vector space;
    since $P$ is rational,
    $L$ is spanned by integer points.
    Let $\dim P$ be the dimension of $P$ (and of $L$)
    and let $d$ be the dimension of the ambient space
    (so that $P \subseteq \mathbb R^d$).
    Then there is a unimodular transform $M$
    which maps $L$ to $\mathbb R^{\dim P} \times \{0\}^{d - \dim P}$.

    If $P$ is contained in the half-space
    \begin{equation*}
        \{x \in \mathbb R^d \mid \langle a, x \rangle \leq b\},
    \end{equation*}
    then $MP$ is contained in the half-space
    \begin{equation*}
        \{x \in \mathbb R^d \mid \langle M^{-t}a, x \rangle \leq b\},
    \end{equation*}
    so applying unimodular transforms
    don't change neither the hypothesis nor the conclusions.
    Thus,
    let $Q$ be the projection of $MP$ to $\mathbb R^{\dim P}$;
    then $Q$ is a full-dimensional polytope which satisfies $L_Q(s) = L_P(s)$,
    so we may apply Theorem~\ref{thm:only-if-part} to conclude the proof.
\end{proof}

We finish this section by remarking that
the hypothesis of $P$ being either full-dimensional or rational
is indeed necessary.
For example,
if $H$ is the set of vectors which are orthogonal to
$(\ln 2, \ln 3, \ln 5, \ln 7, \dots, \ln p_d)$
(where $p_d$ is the $d$th prime number)
and $x = (x_1, \dots, x_d)$ is an integral vector,
$x \in H$ if and only if
\begin{equation*}
    x_1 \log 2 + \dots x_d \log p_d = 0,
\end{equation*}
which (by applying $e^x$ to both sides)
we may rewrite as
\begin{equation*}
    2^{x_1} 3^{x_2} \dots p_d^{x_d} = 1,
\end{equation*}
which is only possible if $x_1 = \dots = x_d = 0$.
That is,
the only integral point in $H$ is the origin.
So,
if $P \subseteq H$,
then $L_P(s)$ will be a constant function,
regardless of any other assumption over $P$.

\section{Examples of semi-reflexive polytopes}
\label{sec:examples}

Here,
we will use the ``if'' part of the characterization
to provide some examples of semi-reflexive polytopes.

\begin{itemize}
    \item The unit cube $P = [0, 1]^d$.
        $P$ may be represented by the inequalities
        $x_i \geq 0$ and $x_i \leq 1$, for all $i$.

    \item The standard simplex,
        which is defined by the inequalities $x_i \geq 0$ for all $i$,
        and $x_1 + \dots + x_d \leq 1$.

    \item The cross-polytope.
        This polytope is defined by $|x_1| + \dots |x_d| \leq 1$.
        Each of the $2^d$ vectors $(\alpha_1, \dots \alpha_d) \in \{-1, 1\}^d$
        gives a bounding inequality of the form
        $\alpha_1 x_1 + \dots + \alpha_d x_d \leq 1$,
        all of which satisfy the characterization.

    \item Order polytopes~\cite{StanleyCounterexample}.
        Let $\prec$ be a partial order over the set $\{1, \dots, d\}$.
        The order polytope for the partial order $\prec$
        is the set of points $(x_1, \dots, x_d) \in \mathbb R^d$
        which satisfy $0 \leq x_i \leq 1$ for all $i$,
        and $x_i \leq x_j$ whenever $i \prec j$.

    \item Chain polytopes~\cite{StanleyCounterexample}.
        Let $\prec$ be a partial order over the set $\{1, \dots, d\}$.
        The chain polytope for the partial order $\prec$
        is the set of points $(x_1, \dots, x_d) \in \mathbb R^d$
        which satisfy $0 \leq x_i$ for all $i$,
        and $x_{i_1} + \dots + x_{i_k} \leq 1$
        for all chains $i_1 \prec i_2 \prec \dots \prec i_k$.

    \item Quasi-metric polytopes~\cite{Cris2017}.
        Let $G$ be a graph such that every vertex has degree $1$ or $3$.
        Identify its edge set with $\{1, \dots, d\}$.
        The quasi-metric polytope $\mathcal P_G$
        is defined to be the set of points $(x_1, \dots, x_d) \in \mathbb R^d$
        satisfying all inequalities of the form
        $x_i \leq x_j + x_k$ and $x_i + x_j + x_k \leq 1$,
        whenever $i$, $j$ and $k$ are the edges
        incident to a degree-$3$ vertex in $G$.

    \item And,
        as we will see in Section~\ref{sec:relation-with-reflexive},
        all reflexive polytopes are also semi-reflexive.
\end{itemize}

\section{Interiors of polytopes}
\label{sec:interiors-of-polytopes}

It is interesting to note there are results
similar to Theorems \ref{thm:characterization} and~\ref{thm:only-if-part},
but for interiors of polytopes.
More precisely:

\begin{theorem}
    Let $P$ be a full-dimensional polytope
    written as in~\eqref{intersection-representation}.
    Then $L_{P^\circ}(s) = L_{P^\circ} (\ceil s)$ for all $s \geq 0$
    if and only if all $b_i$ is either $0$ or $1$,
    and $a_i$ is integral whenever $b_i = 1$.
\end{theorem}

In other words,
$L_P(s) = L_P(\floor s)$ if and only if $L_{P^\circ}(s) = L_{P^\circ}(\ceil s)$.

\begin{proof}
    The proof is very similar to the proofs of the theorems~\ref{thm:if-part},
    \ref{thm:weak-only-if-part}, and~\ref{thm:only-if-part},
    so only the needed changes will be stated.

    For Theorem~\ref{thm:if-part},
    the case $b_i = 0$ is left unchanged,
    and when $b_i = 1$ we need to use $[n < x] = [n < \ceil x]$ to conclude that,
    in all cases,
    $[\langle a_i, x \rangle < s b_i]
    = \big[\langle a_i, x \rangle < \ceil s b_i\big]$.

    For Proposition~\ref{thm:weak-only-if-part},
    we can use the same $u$, $s_0$ and $x_0$,
    but now we will show $L_{P^\circ}(s_0) < L_{P^\circ}(s_0 - \varepsilon)$.
    A point $x$ which is in the interior of $s_0 P^\circ$
    satisfy all linear restrictions of the form $\langle x, a_i \rangle < s_0 b_i$.
    For all sufficiently small $\varepsilon > 0$
    we have $\langle x, a_i \rangle < (s_0 - \varepsilon) b_i$,
    and so every integer point in $s_0 P^\circ$
    will also be present on $(s_0 - \varepsilon) P^\circ$.
    Now the linear restriction $\langle u, x \rangle > 1$
    ``shrinks'' to $\langle u, x \rangle > 1 - \varepsilon$,
    and so the point $x_0$
    (which satisfy $\langle u, x_0 \rangle = 1$)
    will be contained in $(s_0 - \varepsilon) P^\circ$,
    and thus $L_{P^\circ}(s_0 - \varepsilon) > L_{P^\circ}(s_0)$.

    And for Theorem~\ref{thm:only-if-part},
    we again can use the same $s_0$ and $x_0$ and also the face $F$,
    but now we will dilate $P^\circ$ instead of shrinking.
    As $sP \subseteq s'P$ for all $s \leq s'$,
    we also have $sP^\circ \subseteq s' P^\circ$ for all $s \leq s'$.
    Now $x_0 \in s_0 F$,
    so for all $\varepsilon > 0$
    we will have $x_0 \in (s_0 + \varepsilon)P^\circ$,
    which thus show $L_P(s_0) < L_P(s_0 + \varepsilon)$.
\end{proof}

Thus,
using essentially the same proof as of Theorem~\ref{thm:characterization},
we have the following characterization of semi-reflexive polytopes.

\begin{theorem}
    Let $P$ be a rational polytope.
    Then $P$ is semi-reflexive
    if and only if
    $L_{P^\circ}(s) = L_{P^\circ} (\ceil s)$ for all real $s \geq 0$.
\end{theorem}

\section{Introduction}

Given a polytope $P \subseteq \mathbb R^d$,
the classical Ehrhart lattice point enumerator $L_P(t)$ is defined as
\begin{equation*}
    L_P(t) = \#(tP \cap \mathbb Z^d), \qquad \text{integer $t > 0$.}
\end{equation*}
Here,
$\#(A)$ is the number of elements in $A$
and $tP = \{tx \mid x \in P\}$ is the dilation of $P$ by $t$.
The above definition may be extended
to allow arbitrary real numbers as dilation parameters;
we will assume this extension in this paper.
Moreover,
we will agree that $L_P(0) = 1$.

To minimize confusion,
we will denote real dilation parameters with the letter $s$,
so that $L_P(t)$ denotes the classical Ehrhart function
and $L_P(s)$ denotes the extension considered in this paper.
So,
for example,
$L_P(t)$ is just the restriction of $L_P(s)$ to integer arguments.

Every polytope $P \subset \mathbb R^d$ may be written as
\begin{equation}
    \label{intersection-representation}
    P = \bigcap_{i = 1}^n \{
            x \in \mathbb R^d \mid \langle a_i, x \rangle \leq b_i
        \},
\end{equation}
where each $a_i$ is a vector in $\mathbb R^d$
and each $b_i$ is a real number.

We define a polytope $P$ to be \emph{semi-reflexive}
if $P$ is rational and satisfies $L_P(s) = L_P(\floor s)$
for all $s \geq 0$.
We have the following characterization.

\begin{theorem}
    \label{thm:characterization}
    Let $P$ be a rational polytope.
    Then $P$ is a semi-reflexive polytope
    if and only if $P$ may be written as in~\eqref{intersection-representation},
    with all the $a_i$ being integers
    and all $b_i$ being either $0$ or $1$.
\end{theorem}

Section~\ref{sec:examples} contains some examples of semi-reflexive polytopes.
The characterization above is proven in Section~\ref{sec:characterization}.
A similar proof yields another, similar,
characterization of semi-reflexive polytopes
in terms of their relative interiors;
this is discussed in Section~\ref{sec:interiors-of-polytopes}.
Finally,
in Section~\ref{sec:relation-with-reflexive}
we show how semi-reflexive polytopes relate with reflexive polytopes.

\section{Relation with reflexive polytopes}
\label{sec:relation-with-reflexive}

The hyperplane representation of Theorem~\ref{thm:characterization}
may be rewritten in matricial form as follows:
\begin{equation}
    P = \{x \in \mathbb R^d \mid A_1 x \leq \mathbf 1, A_2 x \leq 0 \},
    \label{eq:matricial-representation}
\end{equation}
where $\mathbf 1 = (1, \dots, 1)$ is the all-ones vector,
and $A_1$ and $A_2$ are integer matrices.
We will use this representation to relate semi-reflexive and reflexive polytopes.

There are several equivalent definitions of reflexive polytopes
(see e.g.~\cite[p.~97]{ccd}).
We mention two of them.

First, $P$ is a reflexive polytope if it is an integer polytope
which may be written as
\begin{equation*}
    P = \{x \in \mathbb R^d \mid A x \leq \mathbf 1 \},
\end{equation*}
where $\mathbf 1 = (1, \dots, 1)$ is the all-ones vector
and $A$ is an integer matrix.
This definition make it obvious that
every reflexive polytope is also semi-reflexive.

The second definition uses the dual $P^*$ of a polytope $P$,
defined by
\begin{equation*}
    P^* = \{x \in \mathbb R^d \mid
            \langle x, y \rangle \leq 1 \text{ for all $y \in P$}
        \}.
\end{equation*}
Then $P$ is reflexive if and only if both $P$ and $P^*$ are integer polytopes.

We have the following relation between reflexive and semi-reflexive polytopes.

\begin{theorem}
    $P$ is a reflexive polytope
    if and only if
    both $P$ and $P^*$ are semi-reflexive polytopes.
\end{theorem}

\begin{proof}
    If $P$ is reflexive,
    then $P^*$ is also reflexive,
    and thus both are semi-reflexive.

    Now,
    suppose that $P$ and $P^*$ are semi-reflexive polytopes.
    This contains the implicit assumption that $P^*$ is bounded,
    and thus $P$ must contain the origin in its interior.
    Therefore,
    by Theorem~\ref{thm:characterization},
    we must have
    \begin{equation*}
        P = \{x \in \mathbb R^d \mid A x \leq \mathbf 1 \}
    \end{equation*}
    for some integer matrix $A$.
    (The fact that $0$ is in the interior of $P$
    allowed us to ignore $A_2$
    in the representation~\eqref{eq:matricial-representation}.)

    So,
    we just need to show that $P$ has integer vertices.
    Since $(P^*)^* = P$,
    we may apply the same reasoning to $P^*$ to write
    \begin{equation*}
        P^* = \bigcap_{i = 1}^n \{x \in \mathbb R^d \langle a_i, x \rangle \leq 1 \}
    \end{equation*}
    for certain integers $a_1, \dots, a_n$.
    But these $a_i$ are precisely the vertices of $P$,
    being, thus, an integral polytope.
\end{proof}

Semi-reflexive polytopes