# (C) Petteri Pajunen 2006 # X11(width=5,height=5) # postscript("fixed.ps") cat("SLT posterior for 0-1 loss\n") cat("Number of training vectors (m)?") m <- scan(n=1,quiet=TRUE) cat("How many vectors to classify (n)?") n <- scan(n=1,quiet=TRUE) cat("Training error (s)?") s <- scan(n=1,quiet=TRUE) samples <- 200 pc <- matrix(0,samples-1,1) pr <- matrix(0,samples-1,1) lh <- matrix(0,samples-1,1) xc <- (1:(samples-1))/samples for (ic in 1:(samples-1)) { c <- ic/samples c2 <- c*n a1 <- (s*m)*log(c)+(m*(1-s))*log(1-c) # this is log-likelihood binom <- sum(log((n-c2+1):n))-sum(log(1:c2)) # log-prior pc[ic] <- exp(binom+a1) pr[ic] <- exp(binom) lh[ic] <- exp(a1) } pc <- pc/sum(pc) lh <- lh/sum(lh) pr <- pr/sum(pr) str <- paste("s=",s,", m=",m,", n=",n) plot(xc,(pc),type="l",lwd=3,main=str) lines(xc,(pr),type="l",lwd=2,col="red") lines(xc,(lh),type="l",lwd=2,col="blue") text(0.7,max(pc),"POSTERIOR p(c|s,...)") text(0.7,max(pc)*0.9,"LIKELIHOOD p(s|c,..)",col="blue") text(0.7,max(pc)*0.8,"PRIOR p(c)",col="red") scan(quiet=TRUE) dev.off()