[81de4e]: / diag.disc.R

Download this file

23 lines (22 with data), 602 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
diag.disc <-
function (x, centroids, prior, weight)
{
if (!missing(weight)) {
posid <- (weight > 0)
if (any(posid)) {
weight <- sqrt(weight[posid])
centroids <- centroids[posid, , drop = FALSE] * weight
x <- x[posid, , drop = FALSE] * weight
}
else {
mat <- outer(rep(1, ncol(x)), log(prior), "*")
dimnames(mat) <- list(NULL, dimnames(centroids)[[2]])
return(mat)
}
}
dd <- t(x) %*% centroids
dd0 <- drop(rep(1, nrow(centroids)) %*% (centroids^2))/2 -
log(prior)
names(dd0) <- NULL
scale(dd, dd0, FALSE)
}