I'm trying to implement Integer Programming for Nearest Neighbor Classifier in python using cvxpy
.
Short intro
Given a dataset of n
points with a color (red or blue) we would like to choose the minimal number of candidate points, s.t for each point that isn`t a candidate, its closest candidate has the same color.
My flow
Given a set of n
points (with colors) define an indicator vector I
(|I| = n
),
I_i = 1 if and only if vertex i is chosen as a candidate
In addition, I defined two more vectors, named as A
and B
(|A| = |B| = n
) as follow:
A_i = the distance between v_i to it's closest candidate with the **same** color
B_i = the distance between v_i to it's closest candidate with a **different** color
Therefore, I have n
constrains which are:
B_i > A_i
for any i
My target is to minimize the sum of vector I
(which represents the number of candidates)
My Issue
Its seems that the vectors A
, B
are changing because they affected by I
, since when a candidate is chosen, it is affecting its entry in I
which affects A
and B
and the constrains are dependent on those vectors..
Any suggestions?
Thanks !