# Minimize the number of unique elements in a vector

I was wondering if there is a simple or known way to minimize the number of unique elements in a decision variable (vector). Note that I'm not asking for minimization of nonzero elements (rank constraint). In particular I'm searching for a penalization (soft constraint) or hard constraint in the form $$f(x) <= n_{max}$$ where f() is what I'm searching for, x is the decision vector and n_max is the maximum number of unique elements that x is allowed to have.

EDIT: I am not trying to minimize the number of unique elements in a vector " per se", which of course is trivial. The question is related to minimizing the unique element in a vector of decision variables that is the solution to another optimization problem. Eg: $$argmin_{x} g(x)$$ s.t. $$x \in \mathbb{X}$$ $$\sum(unique(x))<n_{max }$$ Thank you for your time, Lorenzo

• Please re-write your question to make it more clear. "Minimization of the number of unique elements in a vector" is trivial (set all elements equal to the same value), which, obviously, is not what you are looking for. Similar comment for the constraint form you are considering since any trivial function such as $f(x)=0$ is valid. – Stelios Feb 28 '17 at 15:45
• Also, are the $x$ integers? If they are real numbers, then there cannot be a stable solution. – Wolfgang Bangerth Mar 1 '17 at 1:55
• Have a look at the edited question, thanks very much for your time. Lorenzo – Lorenzo Mar 1 '17 at 14:08

Inspired by the well-known approach of employing a regularization (penalty) term $\gamma ||\mathbf{x}||_1$ as a means of relaxing the requirement of minimum non-zero elements of vector $\mathbf{x}$ (e.g., see here), you could try using a regularization of the from $$\gamma ||\mathbf{x} - c\mathbf{1}||_1,$$ where $\mathbf{1}$ is the all-ones vector and $c\in \mathbb{R}$ (assuming the domain is the set of real-valued vectors). You would then solve the resulting problem with respect to both $\mathbf{x}$ and $c$.
• $\ell_1$ norm is def the way to go. Seems like total variation would work as well. – Richard Zhang Mar 2 '17 at 18:44