# Canonical Dependence Simulations

#### 2020-06-22

require(mgc)
require(ggplot2)
n=400
d=1
plot_sim <- function(X, Y, name) {
if (!is.null(dim(Y))) {
Y <- Y[, 1]
}
data <- data.frame(x1=X[,1], y=Y)
ggplot(data, aes(x=x1, y=y)) +
geom_point() +
xlab("x") +
ylab("y") +
ggtitle(name) +
theme_bw()
}

plot_sim_func <- function(X, Y, Xf, Yf, name, geom='line') {
if (!is.null(dim(Y))) {
Y <- Y[, 1]
Yf <- Yf[, 1]
}
if (geom == 'points') {
funcgeom <- geom_point
} else {
funcgeom <- geom_line
}
data <- data.frame(x1=X[,1], y=Y)
data_func <- data.frame(x1=Xf[,1], y=Yf)
ggplot(data, aes(x=x1, y=y)) +
funcgeom(data=data_func, aes(x=x1, y=y), color='red', size=3) +
geom_point() +
xlab("x") +
ylab("y") +
ggtitle(name) +
theme_bw()
}

In this notebook, we will review the simulation algorithms provided in the mgc paper. All simulations will be n=400 examples in d=1 dimensions, since some of the plots do not look obviously of the given simulation type in higher dimensions. The simulation is plotted along with the true distribution of the given simulation where possible.

# Linear

data <- mgc.sims.linear(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.linear(n, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Linear Simulation")

# Exponential

data <- mgc.sims.exp(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.exp(n, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Exponential Simulation")

# Cubic

data <- mgc.sims.cubic(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.cubic(n, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Cubic Simulation")

# Joint-Normal

data <- mgc.sims.joint(n, d)
X <- data$X; Y <- data$Y
plot_sim(X, Y, "Joint-Normal Simulation")

# Step

data <- mgc.sims.step(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.step(n, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Step-Fn Simulation")

data <- mgc.sims.quad(n, d)
X <- data$X; Y <- data$Y
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Quadratic Simulation")

# W-Shape

data <- mgc.sims.wshape(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.wshape(n, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "W Simulation")

# Spiral

data <- mgc.sims.spiral(n, d)
X <- data$X; Y <- data$Y
func <- mgc.sims.spiral(n=1000, d, eps=0)
Xf <- func$X; Yf <- func$Y
plot_sim_func(X, Y, Xf, Yf, "Spiral Simulation", geom='points')

# Uncorrelated Bernoulli

data <- mgc.sims.ubern(n, d)
X <- data$X; Y <- data$Y
plot_sim(X, Y, "Uncorrelated Bernoulli Simulation")