# NOT RUN {
op <- par(no.readonly = TRUE)
set.seed(1)
### Generate data from a simple 10 component mixture model in 10 dimensions:
### Determine means of components
mu <- matrix(runif(100), ncol = 10)
### Determine scales of components (diagonal elements of covariance)
covs <- matrix(rexp(100), ncol = 10)/10
### Determine cluster indicator matrix
I <- t(rmultinom(2000, 1, 1:10))
### Determine mean and residual matrix
M <- I%*%mu
R <- matrix(rnorm(20000), 2000, 10)*(I%*%covs)
### Data is given by the sum of these
X <- M + R
### Find the minimum density hyperplane separator and plot
### the projected data as well as the PCA plot for comparison
mdh <- fk_mdh(X)
par(mfrow = c(2, 2))
plot(X%*%mdh$v, X%*%eigen(cov(X))$vectors[,2], xlab = 'mdh vector',
ylab = '2nd principal component', main = 'MDH solution')
abline(v = mdh$b, col = 2)
plot(X%*%eigen(cov(X))$vectors[,1:2], xlab = '1st principal component',
ylab = '2nd principal component', main = 'PCA plot')
plot(fk_density(X%*%mdh$v), type = 'l', xlab = 'x', ylab = 'f(x)')
abline(v = mdh$b, col = 2)
plot(fk_density(X%*%eigen(cov(X))$vectors[,1]), type = 'l',
xlab = 'x', ylab = 'f(x)')
par(op)
# }
Run the code above in your browser using DataCamp Workspace