Minimal concept and reprex:
I have a vector of blue colors, a vector of red colors, and a 10x10 matrix resulting from mixing each. I want to use a machine learning approach in R to ask, "If I just use a diagonal matrix as input (made from taking the red-only values, blue-only values, and matrix diagonal), can I predict all the remaining values?" :
After a bit of research into several R packages and the literature, I am highly interested in trying to use a GAN for this problem (but open to any applicable solution).
The idea would be to use an approach that predicts the full matrix, and then compare the predicted matrix to the ground truth matrix. (I have ~100 ground truth matrices I could train on)
Min Reprex:
library(ggplot2)
library(reshape2)
#Create 10 values of red, 10 values of blue, and values from mixing each:
df_true <- expand.grid(blue=seq(0, 100, by=10), red=seq(0, 100, by=10))
df_true <- within(df_true, mix <- rgb(green=0, red=red, blue=blue, maxColorValue=100))
#Plot df_true:
ggplot(df_true, aes(x=factor(red), y=factor(blue))) +
geom_tile(aes(fill=mix), color="white") +
scale_fill_identity() +
xlab("red") +
ylab("blue")+
ggtitle("Ground Truth")
#Turn df_true into a matrix
mat_true <- dcast(df_true, blue~red)
rownames(mat_true) <- mat_true$blue
mat_true$blue <- NULL
mat_true <- as.matrix(mat_true)
#Construct a diagonal matrix which is what we want to use as input for the prediction:
#It will contain red-only values, blue-only values, and the diagonal
#First get the diagonal part:
tmp_diag <- data.frame("red"=as.numeric(colnames(mat_true)),
"blue"=as.numeric(rownames(mat_true)),
"mix"=diag(mat_true))
#Get the red-only values:
tmp_red <- data.frame("red"=as.numeric(colnames(mat_true)),
"blue"=0,
"mix"=mat_true[1,])
rownames(tmp_red) <- 1:nrow(tmp_red)
#Get the blue-only values:
tmp_blue <- data.frame("red"=0,
"blue"=as.numeric(rownames(mat_true)),
"mix"=mat_true[,1])
rownames(tmp_blue) <- 1:nrow(tmp_blue)
#Combine them to make the full diagonal matrix
diag_mat <- rbind(tmp_red, tmp_blue, tmp_diag)
ggplot(diag_mat, aes(x=factor(red), y=factor(blue))) +
geom_tile(aes(fill=mix), color="white") +
scale_fill_identity()+
xlab("red") +
ylab("blue")+
ggtitle("Diagonal (from Ground Truth)")