generate.ClP <- function(C, P) { # P is x coord (col), C is y coord (row), ClP[y, x]
ClP <- matrix(nrow=e_s,ncol=e_s);
for(i in unique(P)) for(j in unique(C)) ClP[j,i] <- 0;
for(j in seq(1, length(unique(P)))) {
e_p <- sort(unique(P)[j]);
C_p <- sort(C[P==e_p]);
freq <- t(as.data.frame(table(C_p))[,2]);
prob <- freq/sum(freq);
for(i in seq(1, length(unique(C_p)))) {
e_c <- unique(C_p)[i];
ClP[e_c, e_p] <- prob[i];
};
};
ClP;
};
nd.ClP <- function(ClP) {
l <- c();
for(i in seq(1, dim(ClP)[1])) {
nonna <- ClP[!is.na(ClP[,i]),i];
if(!identical(nonna, numeric(0))) l <- c(l, range(nonna)[1] == range(nonna)[2]);
};
range(l)[1] == TRUE && range(l)[2] == TRUE;
};
nd <- function(C, P) {
nd.ClP(generate.ClP(C, P));
};
entropy
<- function (n
) -n
* (1/n
) * log(1/n
);
mi <- function(C, P) {
result <- 0;
ClP <- generate.ClP(C,P);
for(i in 1:dim(ClP)[2]) {
a
<- ClP
[,i
] * log(ClP
[,i
]);a_ <- a[!is.nan(a) & !is.na(a)];
e <- entropy(length(unique(C)));
if(length(a_) > 0 && !is.nan(e))
result <- result + (e + sum(a_));
};
result;
};
args <- commandArgs(trailingOnly = TRUE)
success_count <- c();
for(choices in 1:10) {
success_count[choices] <- 0;
for(i in 1:1) {
e_s <- choices;
P1 <- sample(seq(1,e_s),e_s,replace=TRUE);
C1 <- sample(seq(1,e_s),e_s,replace=TRUE);
F1 <- sample(seq(1,e_s),e_s,replace=TRUE);
P1lC1 <- generate.ClP(P1, C1);
C1lP1 <- generate.ClP(C1, P1);
F1lC1 <- generate.ClP(F1, C1);
C1lF1 <- generate.ClP(C1, F1);
mi(C1,P1);
mi(P1,C1);
mi(F1,C1);
mi(C1,F1);
(round(mi(C1,P1)) < round(mi(C1,F1)));
(round(mi(F1,C1)) < round(mi(C1,F1)));
(round(mi(C1,P1)) < round(mi(C1,F1))) && (round(mi(F1,C1)) < round(mi(C1,F1)));
if ((round(mi(C1,P1)) < round(mi(C1,F1))) && (round(mi(F1,C1)) < round(mi(C1,F1)))) success_count[choices] <- success_count[choices] + 1;
}
}
success_count;
Z2VuZXJhdGUuQ2xQIDwtIGZ1bmN0aW9uKEMsIFApIHsgIyBQIGlzIHggY29vcmQgKGNvbCksIEMgaXMgeSBjb29yZCAocm93KSwgQ2xQW3ksIHhdCkNsUCA8LSBtYXRyaXgobnJvdz1lX3MsbmNvbD1lX3MpOwpmb3IoaSBpbiB1bmlxdWUoUCkpIGZvcihqIGluIHVuaXF1ZShDKSkgQ2xQW2osaV0gPC0gMDsKZm9yKGogaW4gc2VxKDEsIGxlbmd0aCh1bmlxdWUoUCkpKSkgewplX3AgPC0gc29ydCh1bmlxdWUoUClbal0pOwpDX3AgPC0gc29ydChDW1A9PWVfcF0pOwpmcmVxIDwtIHQoYXMuZGF0YS5mcmFtZSh0YWJsZShDX3ApKVssMl0pOwpwcm9iIDwtIGZyZXEvc3VtKGZyZXEpOwpmb3IoaSBpbiBzZXEoMSwgbGVuZ3RoKHVuaXF1ZShDX3ApKSkpIHsKIGVfYyA8LSB1bmlxdWUoQ19wKVtpXTsKIENsUFtlX2MsIGVfcF0gPC0gcHJvYltpXTsKfTsKfTsKQ2xQOwp9OwoKbmQuQ2xQIDwtIGZ1bmN0aW9uKENsUCkgewpsIDwtIGMoKTsgCmZvcihpIGluIHNlcSgxLCBkaW0oQ2xQKVsxXSkpIHsKbm9ubmEgPC0gQ2xQWyFpcy5uYShDbFBbLGldKSxpXTsKaWYoIWlkZW50aWNhbChub25uYSwgbnVtZXJpYygwKSkpIGwgPC0gYyhsLCByYW5nZShub25uYSlbMV0gPT0gcmFuZ2Uobm9ubmEpWzJdKTsgCn07CnJhbmdlKGwpWzFdID09IFRSVUUgJiYgcmFuZ2UobClbMl0gPT0gVFJVRTsgCn07CgpuZCA8LSBmdW5jdGlvbihDLCBQKSB7Cm5kLkNsUChnZW5lcmF0ZS5DbFAoQ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