Maximum Margin Projection (MMP) is a supervised linear method that maximizes the margin
between positive and negative examples at each local neighborhood based on
same- and different-class neighborhoods depending on class labels.

```
do.mmp(
X,
label,
ndim = 2,
preprocess = c("center", "scale", "cscale", "decorrelate", "whiten"),
numk = max(ceiling(nrow(X)/10), 2),
alpha = 0.5,
gamma = 50
)
```

## Arguments

- X
an \((n\times p)\) matrix or data frame whose rows are observations.

- label
a length-\(n\) vector of data class labels.

- ndim
an integer-valued target dimension.

- preprocess
an additional option for preprocessing the data.
Default is "center". See also `aux.preprocess`

for more details.

- numk
the number of neighboring points.

- alpha
balancing parameter in \([0,1]\).

- gamma
weight for same-label data points with large magnitude.

## Value

a named list containing

- Y
an \((n\times ndim)\) matrix whose rows are embedded observations.

- trfinfo
a list containing information for out-of-sample prediction.

- projection
a \((p\times ndim)\) whose columns are basis for projection.

## References

Xiaofei He, Deng Cai, Jiawei Han (2008).
“Learning a Maximum Margin Subspace for Image Retrieval.”
*IEEE Transactions on Knowledge and Data Engineering*, **20**(2), 189--201.

## Examples

```
## generate data of 3 types with clear difference
dt1 = aux.gensamples(n=20)-100
dt2 = aux.gensamples(n=20)
dt3 = aux.gensamples(n=20)+100
## merge the data and create a label correspondingly
X = rbind(dt1,dt2,dt3)
label = rep(1:3, each=20)
## copy a label and let 20% of elements be missing
nlabel = length(label)
nmissing = round(nlabel*0.20)
label_missing = label
label_missing[sample(1:nlabel, nmissing)]=NA
## compare with PCA case for full-label case
## for missing label case from MMP computation
out1 = do.pca(X, ndim=2)
out2 = do.mmp(X, label_missing, numk=10)
## visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(out1$Y, col=label, main="PCA projection")
plot(out2$Y, col=label, main="20% missing labels")
par(opar)
```