我试图用cvxpy
实现python中最近邻分类器的整数编程.
简短介绍
给定一个包含n
个 colored颜色 (红色或蓝色)的点的数据集,我们希望 Select 最少数量的候选点,s.t对于每个不是候选点的点,其最近的候选点具有相同的 colored颜色 .
我的流动
给定一组n
个点(带 colored颜色 ),定义一个指示向量I
(|I| = n
),
I_i = 1 if and only if vertex i is chosen as a candidate
此外,我还定义了另外两个向量,分别命名为A
和B
(|A| = |B| = n
),如下所示:
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
因此,我有n
个约束条件:
我的目标是最小化向量I
之和(代表候选数量)
我的问题
向量A
、B
似乎在变化,因为它们受到I
的影响,因为当 Select 一个候选者时,它会影响其在I
中的条目,而这会影响A
和B
,约束取决于这些向量..
有什么建议吗?
谢谢