Skip to content

Commit 826aa26

Browse files
committed
update
1 parent b213d7f commit 826aa26

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ URL: http://r-pbd.org/
2525
BugReports: http://group.r-pbd.org/
2626
MailingList: Please send questions and comments regarding pbdR to
2727
28-
Packaged: 2013-06-25 18:48:18 UTC; snoweye
28+
Packaged: 2013-06-27 20:30:11 UTC; snoweye
2929
Author: Wei-Chen Chen [aut, cre],
3030
George Ostrouchov [aut]
3131
Maintainer: Wei-Chen Chen <[email protected]>

R/01_as_dmat.r

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ as.dmat <- function(X.spmd, bldim = .BLDIM, ICTXT = .ICTXT,
66

77
N.spmd <- nrow(X.spmd)
88
p <- ncol(X.spmd)
9-
N <- spmd.allreduce.integer(N.spmd, integer(1), op = "sum")
10-
11-
X.dmat <- ddmatrix(0, N, p, bldim = c(N.spmd, p), CTXT = 2)
9+
N <- spmd.allreduce.integer(N.spmd, integer(1), op = "sum", comm = comm)
10+
N.block.row <- spmd.allreduce.integer(N.spmd, integer(1), op = "max",
11+
comm = comm)
12+
X.dmat <- ddmatrix(0, N, p, bldim = c(N.block.row, p), ICTXT = 2)
1213
X.dmat@Data <- X.spmd
1314
X.dmat <- redistribute(X.dmat, bldim = bldim, ICTXT = ICTXT)
1415

R/dmat_00_readme.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cat('
2727
# W.dmat: double ddmatrix[N, K], conditional log posterior probability.
2828
# W.dmat.rowSums: double ddmatrix[N, 1], log density for each observations.
2929
# U.dmat: double ddmatrix[N, K], W.spmd plus log eta.
30-
# CLASS.dmat: double ddmatrix[N, 1], classification of observations.
30+
# CLASS: double ddmatrix[N, 1], classification of observations.
3131
# CHECK: list[4], for output.
3232
# - algorithm: string[1], "em.dmat" or "kmeans.dmat".
3333
# - i.iter: integer[1], current iteration.
@@ -56,7 +56,7 @@ cat('
5656
5757
### Output:
5858
# (different)
59-
# CLASS.dmat
59+
# CLASS
6060
# (rank = 0, only, identical)
6161
# PARAM, CHECK
6262
')

R/dmat_em_base.r

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,11 @@ em.onestep.dmat <- function(PARAM){
337337
### Obtain classifications.
338338
em.update.class.dmat <- function(){
339339
### WCC: original
340-
.pmclustEnv$CLASS.dmat <- apply(.pmclustEnv$Z.dmat, 1, which.max)
340+
# .pmclustEnv$CLASS.dmat <- apply(.pmclustEnv$Z.dmat, 1, which.max)
341341
### WCC: temp dmat
342-
# tmp.1 <- apply(.pmclustEnv$Z.dmat, 1, which.max)
343-
# .pmclustEnv$CLASS.dmat <- tmp.1
342+
tmp.1 <- as.matrix(.pmclustEnv$Z.dmat)
343+
tmp.2 <- unlist(apply(tmp.1, 1, which.max))
344+
.pmclustEnv$CLASS <- tmp.2 # This is not a ddmatrix
344345
### WCC: temp spmd
345346
# tmp.1 <- as.matrix(.pmclustEnv$Z.dmat)
346347
# tmp.2 <- matrix(apply(tmp.1, 1, which.max), ncol = 1)

R/dmat_em_tools.r

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
### This function collects N.CLASS
44
get.N.CLASS.dmat <- function(K){
5-
tabulate(as.vector(.pmclustEnv$CLASS.dmat), nbins = K)
5+
tabulate(as.vector(.pmclustEnv$CLASS), nbins = K) # This is not a ddmatrix.
66
} # End of get.N.CLASS.dmat().
77

8-
98
get.CLASS <- function(PARAM){
10-
A <- exists("CLASS.dmat", envir = .pmclustEnv)
9+
A <- exists("CLASS", envir = .pmclustEnv)
1110
B <- exists("CLASS.spmd", envir = .pmclustEnv)
1211

1312
if(A & B){
14-
comm.stop("CLASS.spmd and CLASS.dmat both exist in .pmclustEnv")
13+
comm.stop("CLASS and CLASS.spmd both exist in .pmclustEnv")
1514
} else{
1615
if(A){
1716
ret <- spmd.allgather.integer(as.integer(.pmclustEnv$CLASS.spmd),
1817
integer(PARAM$N))
1918
ret <- unlist(ret)
20-
}
21-
if(B){
22-
ret <- as.integer(as.vector(.pmclustEnv$CLASS.dmat))
19+
} else if(B){
20+
ret <- as.integer(.pmclustEnv$CLASS)
21+
} else{
22+
comm.stop("CLASS and CLASS.spmd do not exist in .pmclustEnv")
2323
}
2424
}
2525

2626
ret
2727
} # End of get.CLASS().
28-

R/dmat_kmeans_base.r

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ kmeans.m.step.dmat <- function(PARAM){
3030
# tmp <- as.vector(colMeans(X.dmat[.pmclustEnv$CLASS.dmat == i.k,]))
3131
# PARAM$MU[, i.k] <- as.vector(tmp)
3232
### WCC: temp
33-
tmp.1 <- .pmclustEnv$CLASS.dmat == i.k
33+
tmp.1 <- .pmclustEnv$CLASS == i.k # This is not a ddmatrix.
3434
tmp.2 <- X.dmat[tmp.1,]
3535
tmp.3 <- colMeans(tmp.2)
3636
tmp.4 <- as.vector(tmp.3)
@@ -46,10 +46,11 @@ kmeans.logL.step.dmat <- function(){
4646
# tmp.diff <- sum(.pmclustEnv$CLASS.dmat != tmp)
4747
# .pmclustEnv$CLASS.dmat <- tmp
4848
### WCC: temp
49-
tmp.1 <- apply(.pmclustEnv$Z.dmat, 1, which.min)
50-
tmp.2 <- .pmclustEnv$CLASS.dmat != tmp.1
51-
tmp.diff <- sum(tmp.2)
52-
.pmclustEnv$CLASS.dmat <- tmp.1
49+
tmp.1 <- as.matrix(.pmclustEnv$Z.dmat)
50+
tmp.2 <- unlist(apply(tmp.1, 1, which.min))
51+
tmp.3 <- .pmclustEnv$CLASS != tmp.2 # This is not a ddmatrix.
52+
tmp.diff <- sum(tmp.3)
53+
.pmclustEnv$CLASS <- tmp.2
5354

5455
as.integer(tmp.diff)
5556
} # End of kmeans.logL.step.dmat().
@@ -139,8 +140,9 @@ kmeans.update.class.dmat <- function(){
139140
### WCC: original
140141
# .pmclustEnv$CLASS.dmat <- apply(.pmclustEnv$Z.dmat, 1, which.min)
141142
### WCC: temp
142-
tmp.1 <- apply(.pmclustEnv$Z.dmat, 1, which.min)
143-
.pmclustEnv$CLASS.dmat <- tmp.1
143+
tmp.1 <- as.matrix(.pmclustEnv$Z.dmat)
144+
tmp.2 <- unlist(apply(tmp.1, 1, which.min))
145+
.pmclustEnv$CLASS <- tmp.2 # This is not a ddmatrix
144146

145147
invisible()
146148
} # End of kmeans.update.class.dmat().

R/dmat_kmeans_initial.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ initial.center.dmat <- function(PARAM, MU = NULL){
3636
}
3737

3838
### WCC: original
39-
.pmclustEnv$CLASS.dmat <- apply(.pmclustEnv$Z.dmat, 1, which.max)
39+
# .pmclustEnv$CLASS.dmat <- apply(.pmclustEnv$Z.dmat, 1, which.max)
4040
### WCC: temp
41-
# tmp.1 <- apply(.pmclustEnv$Z.dmat, 1, which.max)
42-
# .pmclustEnv$CLASS.dmat <- tmp.1
41+
tmp.1 <- as.matrix(.pmclustEnv$Z.dmat)
42+
.pmclustEnv$CLASS <- unlist(apply(tmp.1, 1, which.max))
4343

4444
PARAM
4545
} # End of initial.center.dmat().

R/dmat_my_tools.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ set.global.dmat <- function(K = 2, X.dmat = NULL, PARAM = NULL,
5858
.pmclustEnv$U.dmat <- ddmatrix(0, N, K)
5959

6060
# .pmclustEnv$CLASS.dmat <- ddmatrix(0, N, 1)
61-
.pmclustEnv$CLASS.dmat <- rep(0, N)
61+
.pmclustEnv$CLASS <- rep(0, N) # This is not a ddmatrix.
6262

6363
.pmclustEnv$CHECK <- list(algorithm = algorithm[1],
6464
i.iter = 0, abs.err = Inf,

0 commit comments

Comments
 (0)