r""" Wasserstein Discriminant Analysis :ref:`[11] ` The function solves the following optimization problem: .. math:: \mathbf{P} = \mathop{\arg \min}_\mathbf{P} \quad \frac{\sum\limits_i W(P \mathbf{X}^i, P \mathbf{X}^i)}{\sum\limits_{i, j \neq i} W(P \m
(
X,
y,
p=2,
reg=1,
k=10,
solver=None,
sinkhorn_method="sinkhorn",
maxiter=100,
verbose=0,
P0=None,
normalize=False,
)
| 139 | |
| 140 | |
| 141 | def wda( |
| 142 | X, |
| 143 | y, |
| 144 | p=2, |
| 145 | reg=1, |
| 146 | k=10, |
| 147 | solver=None, |
| 148 | sinkhorn_method="sinkhorn", |
| 149 | maxiter=100, |
| 150 | verbose=0, |
| 151 | P0=None, |
| 152 | normalize=False, |
| 153 | ): |
| 154 | r""" |
| 155 | Wasserstein Discriminant Analysis :ref:`[11] <references-wda>` |
| 156 | |
| 157 | The function solves the following optimization problem: |
| 158 | |
| 159 | .. math:: |
| 160 | \mathbf{P} = \mathop{\arg \min}_\mathbf{P} \quad |
| 161 | \frac{\sum\limits_i W(P \mathbf{X}^i, P \mathbf{X}^i)}{\sum\limits_{i, j \neq i} W(P \mathbf{X}^i, P \mathbf{X}^j)} |
| 162 | |
| 163 | where : |
| 164 | |
| 165 | - :math:`P` is a linear projection operator in the Stiefel(`p`, `d`) manifold |
| 166 | - :math:`W` is entropic regularized Wasserstein distances |
| 167 | - :math:`\mathbf{X}^i` are samples in the dataset corresponding to class i |
| 168 | |
| 169 | **Choosing a Sinkhorn solver** |
| 170 | |
| 171 | By default and when using a regularization parameter that is not too small |
| 172 | the default sinkhorn solver should be enough. If you need to use a small |
| 173 | regularization to get sparse cost matrices, you should use the |
| 174 | :py:func:`ot.dr.sinkhorn_log` solver that will avoid numerical |
| 175 | errors, but can be slow in practice. |
| 176 | |
| 177 | Parameters |
| 178 | ---------- |
| 179 | X : ndarray, shape (n, d) |
| 180 | Training samples. |
| 181 | y : ndarray, shape (n,) |
| 182 | Labels for training samples. |
| 183 | p : int, optional |
| 184 | Size of dimensionality reduction. |
| 185 | reg : float, optional |
| 186 | Regularization term >0 (entropic regularization) |
| 187 | solver : None | str, optional |
| 188 | None for steepest descent or 'TrustRegions' for trust regions algorithm |
| 189 | else should be a pymanopt.solvers |
| 190 | sinkhorn_method : str |
| 191 | method used for the Sinkhorn solver, either 'sinkhorn' or 'sinkhorn_log' |
| 192 | P0 : ndarray, shape (d, p) |
| 193 | Initial starting point for projection. |
| 194 | normalize : bool, optional |
| 195 | Normalize the Wasserstaiun distance by the average distance on P0 (default : False) |
| 196 | verbose : int, optional |
| 197 | Print information along iterations. |
| 198 |
no test coverage detected