fcmlcode
fcmlcode copied to clipboard
A bug in plotcc.R
In plotcc.R file in the folder R/chapter5/, you have used:
contour(gridvalsX,gridvalsY,matrix(Probs,nrow=dim(Xv)[[1]],ncol=dim(Xv)[[2]],byrow=TRUE),add=TRUE)
However, it should be:
contour(gridvalsX,gridvalsY,matrix(Probs,nrow=dim(Xv)[[2]],ncol=dim(Xv)[[1]],byrow=TRUE),add=TRUE)
That is because in the meshgrid output, the rows of the output array X are copies of the vector gridvalsX, so the length of gridvalsX is equal to the number of columns in mesh$X which is dim(Xv)[[2]], and length of gridvalsY is equal to the number of rows in mesh$X which is dim(Xv)[[1]]. The code runs since both gridvalsX and gridvalsY have the same dimension, however, if you make them different, you get an error.
There is also a bug in the line that calculates the Gaussian:
const = -log(2*pi) - log(det(tempc))
In fact it should be the square root of the determinant of the covariance matrix, so it sholud be:
const = -log(2*pi) - log(sqrt(det(tempc)))