fcmlcode icon indicating copy to clipboard operation
fcmlcode copied to clipboard

A bug in plotcc.R

Open reza-bagheri opened this issue 7 years ago • 1 comments

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.

reza-bagheri avatar Dec 15 '18 08:12 reza-bagheri

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)))

reza-bagheri avatar Dec 18 '18 01:12 reza-bagheri