Skip to content

Commit b213d7f

Browse files
committed
update
1 parent f49800f commit b213d7f

30 files changed

+343
-108
lines changed

ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
2013-05-13: Ver. 0.1-5
1+
2013-06-24: Ver. 0.1-5
22
* Add high-level functions "pmclust" and "pkmeans".
33
* Add man page and vignettes.
44
* Add PiLow to generate.MixSim.
5+
* Add GBD data type.
56

67
2013-03-25: Ver. 0.1-4
78
* Add dmat_* functions/methods to fully utilize pbdR capability, only the

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: pmclust
22
Version: 0.1-5
3-
Date: 2013-05-13
3+
Date: 2013-06-24
44
Title: Parallel Model-Based Clustering
55
Authors@R: c(person("Wei-Chen", "Chen", role = c("aut", "cre"), email =
66
"[email protected]"), person("George", "Ostrouchov", role = "aut"))
@@ -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-19 20:37:06 UTC; snoweye
28+
Packaged: 2013-06-25 18:48:18 UTC; snoweye
2929
Author: Wei-Chen Chen [aut, cre],
3030
George Ostrouchov [aut]
3131
Maintainer: Wei-Chen Chen <[email protected]>

NAMESPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export(
8282
"kmeans.update.class.dmat",
8383

8484
### Utility functions.
85-
"get.N.CLASS.dmat"
85+
"get.N.CLASS.dmat",
86+
87+
### GBD functions.
88+
### Global objects.
89+
"set.global.gbd"
8690
)
8791

8892
S3method(print, pmclust)

R/00_pmclust.r

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pmclust <- function(X = NULL, K = 2, MU = NULL,
44
algorithm = .PMC.CT$algorithm, RndEM.iter = .PMC.CT$RndEM.iter,
55
CONTROL = .PMC.CT$CONTROL, method.own.X = .PMC.CT$method.own.X,
66
rank.own.X = .SPMD.CT$rank.source, comm = .SPMD.CT$comm){
7-
if(is.null(X)){
7+
if(comm.all(is.null(X))){
88
# Check global matrix.
99
A <- exists("X.spmd", envir = .GlobalEnv)
1010
B <- exists("X.dmat", envir = .GlobalEnv)
1111
if((!A) & (!B)){
12-
if(! algorithm[1] %in% .PMC.CT$algorithm.spmd){
12+
if(! algorithm[1] %in% .PMC.CT$algorithm.gbd){
1313
comm.stop("A global X.spmd is required in .GlobalEnv.")
1414
}
1515
if(! algorithm[1] %in% .PMC.CT$algorithm.dmat){
@@ -34,7 +34,7 @@ pmclust <- function(X = NULL, K = 2, MU = NULL,
3434
}
3535
}
3636

37-
if(algorithm[1] %in% .PMC.CT$algorithm.spmd){
37+
if(algorithm[1] %in% .PMC.CT$algorithm.gbd){
3838
ret <- pmclust.internal(X, K,
3939
MU = MU,
4040
algorithm = algorithm[1],
@@ -69,12 +69,12 @@ pkmeans <- function(X = NULL, K = 2, MU = NULL,
6969
algorithm = c("kmeans", "kmeans.dmat"),
7070
CONTROL = .PMC.CT$CONTROL, method.own.X = .PMC.CT$method.own.X,
7171
rank.own.X = .SPMD.CT$rank.source, comm = .SPMD.CT$comm){
72-
if(is.null(X)){
72+
if(comm.all(is.null(X))){
7373
# Check global matrix.
7474
A <- exists("X.spmd", envir = .GlobalEnv)
7575
B <- exists("X.dmat", envir = .GlobalEnv)
7676
if((!A) & (!B)){
77-
if(! algorithm[1] %in% .PMC.CT$algorithm.spmd){
77+
if(! algorithm[1] %in% .PMC.CT$algorithm.gbd){
7878
comm.stop("A global X.spmd is required in .GlobalEnv.")
7979
}
8080
if(! algorithm[1] %in% .PMC.CT$algorithm.dmat){

R/00_pmclust_internal.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
### For general internal methods.
22

33
pmclust.internal <- function(X = NULL, K = 2, MU = NULL,
4-
algorithm = .PMC.CT$algorithm.spmd, RndEM.iter = .PMC.CT$RndEM.iter,
4+
algorithm = .PMC.CT$algorithm.gbd, RndEM.iter = .PMC.CT$RndEM.iter,
55
CONTROL = .PMC.CT$CONTROL, method.own.X = .PMC.CT$method.own.X,
66
rank.own.X = .SPMD.CT$rank.source, comm = .SPMD.CT$comm){
77
# Check.
8-
if(! (algorithm[1] %in% .PMC.CT$algorithm.spmd)){
8+
if(! (algorithm[1] %in% .PMC.CT$algorithm.gbd)){
99
comm.stop("The algorithm is not supported")
1010
}
1111
if(! (method.own.X[1] %in% .PMC.CT$method.own.X)){
1212
comm.stop("The method.own.X is not found.")
1313
}
1414

1515
# Check X.
16-
if(is.null(X)){
16+
if(comm.all(is.null(X))){
1717
if(exists("X.dmat", envir = .GlobalEnv)){
18-
# Assign X to .pmclustEnv and convert to gbdr.
18+
# Assign X to .pmclustEnv and convert to spmdr.
1919
convert.data(.GlobalEnv$X.dmat, method.own.X[1], rank.own.X, comm)
2020
} else{
2121
# Assume X.spmd in .GlobalEnv and no need for converting or check.
@@ -27,14 +27,14 @@ pmclust.internal <- function(X = NULL, K = 2, MU = NULL,
2727

2828
# Set global variables.
2929
PARAM.org <- set.global(K = K, RndEM.iter = RndEM.iter)
30-
if(!is.null(CONTROL)){
30+
if(! comm.all(is.null(CONTROL))){
3131
tmp <- .pmclustEnv$CONTROL[!(names(.pmclustEnv$CONTROL) %in%
3232
names(CONTROL))]
3333
.pmclustEnv$CONTROL <- c(tmp, CONTROL)
3434
}
3535

3636
# Initialization for algorithms.
37-
if(! is.null(MU)){
37+
if(! comm.all(is.null(MU))){
3838
if(algorithm[1] != "kmeans"){
3939
PARAM.org <- initial.em(PARAM.org, MU = MU)
4040
} else{

R/00_pmclust_internal_dmat.r

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pmclust.internal.dmat <- function(X = NULL, K = 2, MU = NULL,
1010
}
1111

1212
# Check X.
13-
if(is.null(X)){
13+
if(comm.all(is.null(X))){
1414
if(! is.ddmatrix(.GlobalEnv$X.dmat)){
1515
comm.stop("X.dmat is not a ddmatrix.")
1616
} else{
@@ -27,14 +27,14 @@ pmclust.internal.dmat <- function(X = NULL, K = 2, MU = NULL,
2727

2828
# Set global variables.
2929
# PARAM.org <- set.global.dmat(K = K, RndEM.iter = RndEM.iter)
30-
if(!is.null(CONTROL)){
30+
if(! comm.all(is.null(CONTROL))){
3131
tmp <- .pmclustEnv$CONTROL[!(names(.pmclustEnv$CONTROL) %in%
3232
names(CONTROL))]
3333
.pmclustEnv$CONTROL <- c(tmp, CONTROL)
3434
}
3535

3636
# Initialization for algorithms.
37-
if(! is.null(MU)){
37+
if(! comm.all(is.null(MU))){
3838
if(algorithm[1] != "kmeans.dmat"){
3939
PARAM.org <- initial.em.dmat(PARAM.org, MU = MU)
4040
} else{
@@ -56,7 +56,7 @@ pmclust.internal.dmat <- function(X = NULL, K = 2, MU = NULL,
5656
# "apecma.dmat" = apecma.step.dmat,
5757
"kmeans.dmat" = kmeans.step.dmat,
5858
NULL)
59-
if(is.null(method.step)){
59+
if(comm.all(is.null(method.step))){
6060
comm.stop("Algorithm is not found.")
6161
}
6262
PARAM.new <- method.step(PARAM.org)

R/01_as_dmat.r

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### Convert X.gbd to X.dmat
1+
### Convert X.spmd to X.dmat
22

3-
as.dmat <- function(X.gbd, bldim = .BLDIM, ICTXT = .ICTXT,
3+
as.dmat <- function(X.spmd, bldim = .BLDIM, ICTXT = .ICTXT,
44
comm = .SPMD.CT$comm){
5-
X.gbd <- load.balance(X.gbd, comm = comm)
5+
X.spmd <- load.balance(X.spmd, comm = comm)
66

7-
N.gbd <- nrow(X.gbd)
8-
p <- ncol(X.gbd)
9-
N <- spmd.allreduce.integer(N.gbd, integer(1), op = "sum")
7+
N.spmd <- nrow(X.spmd)
8+
p <- ncol(X.spmd)
9+
N <- spmd.allreduce.integer(N.spmd, integer(1), op = "sum")
1010

11-
X.dmat <- ddmatrix(0, N, p, bldim = c(N.gbd, p), CTXT = 2)
12-
X.dmat@Data <- X.gbd
11+
X.dmat <- ddmatrix(0, N, p, bldim = c(N.spmd, p), CTXT = 2)
12+
X.dmat@Data <- X.spmd
1313
X.dmat <- redistribute(X.dmat, bldim = bldim, ICTXT = ICTXT)
1414

1515
X.dmat

R/02_convert_data.r

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ convert.data <- function(X, method.own.X = .PMC.CT$method.own.X,
99
if(is.ddmatrix(X)){
1010
# For a ddmatrix.
1111

12-
.pmclustEnv$X.spmd <- as.gbd(X, comm = comm)
12+
.pmclustEnv$X.spmd <- as.spmd(X, comm = comm)
1313
} else{
14-
# for a GBD matrix.
14+
# for a spmd matrix.
1515

1616
if(is.null(X)){
1717
X <- matrix(0, nrow = 0, ncol = 0)
1818
}
1919

20-
if(method.own.X[1] == "gbdr"){
21-
# For GBD row-major
20+
if(method.own.X[1] %in% c("gbdr", "spmdr")){
21+
# For spmd row-major
2222

2323
p <- ncol(X)
2424
p.all <- spmd.allgather.integer(p, integer(COMM.SIZE), comm = comm)
@@ -57,7 +57,7 @@ convert.data <- function(X, method.own.X = .PMC.CT$method.own.X,
5757
p <- spmd.bcast.integer(as.integer(p), rank.source = rank.own.X,
5858
comm = comm)
5959
if(p == -1){
60-
comm.stop("X should be a matrix in rank 0.")
60+
comm.stop("X should be a matrix in rank.own.X.")
6161
} else{
6262
if(COMM.RANK != rank.own.X){
6363
X <- matrix(0, nrow = 0, ncol = p)

R/02_load_balance.r

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
### This file contains functions to load balance of data X.spmd.
22

33
balance.info <- function(X.spmd, comm = .SPMD.CT$comm,
4-
gbd.major = 1, method = c("block.cyclic", "block0")){
4+
spmd.major = 1, method = c("block.cyclic", "block0")){
55
COMM.SIZE <- spmd.comm.size(comm)
66
COMM.RANK <- spmd.comm.rank(comm)
77

88
if(!is.matrix(X.spmd)){
99
X.spmd <- as.matrix(X.spmd)
1010
}
1111

12-
if(gbd.major == 1){
12+
if(spmd.major == 1){
1313
N.spmd <- nrow(X.spmd)
14-
} else if(gbd.major == 2){
14+
} else if(spmd.major == 2){
1515
N.spmd <- ncol(X.spmd)
1616
} else{
17-
stop("gbd.major = 1 or 2.")
17+
stop("spmd.major = 1 or 2.")
1818
}
1919
N.allspmd <- spmd.allgather.integer(as.integer(N.spmd), integer(COMM.SIZE),
2020
comm = comm)
@@ -60,31 +60,31 @@ balance.info <- function(X.spmd, comm = .SPMD.CT$comm,
6060
belong = rank.belong[rank.belong == COMM.RANK])
6161

6262
list(send = send.info, recv = recv.info, N.allspmd = N.allspmd,
63-
new.N.allspmd = new.N.allspmd, gbd.major = gbd.major)
63+
new.N.allspmd = new.N.allspmd, spmd.major = spmd.major)
6464
} # End of balance.info()
6565

6666

6767
load.balance <- function(X.spmd, bal.info = NULL, comm = .SPMD.CT$comm,
68-
gbd.major = 1){
68+
spmd.major = 1){
6969
COMM.RANK <- spmd.comm.rank(comm)
7070
if(is.null(bal.info)){
71-
bal.info <- balance.info(X.spmd, comm = comm, gbd.major = gbd.major)
71+
bal.info <- balance.info(X.spmd, comm = comm, spmd.major = spmd.major)
7272
}
7373

7474
if(!is.matrix(X.spmd)){
7575
X.spmd <- as.matrix(X.spmd)
7676
}
77-
if(gbd.major == 1){
77+
if(spmd.major == 1){
7878
p <- ncol(X.spmd)
79-
} else if(gbd.major == 2){
79+
} else if(spmd.major == 2){
8080
p <- nrow(X.spmd)
8181
} else{
82-
stop("gbd.major = 1 or 2.")
82+
stop("spmd.major = 1 or 2.")
8383
}
8484

8585
send.to <- as.integer(unique(bal.info$send$belong))
8686
if(length(send.to) > 0){
87-
if(gbd.major == 1){
87+
if(spmd.major == 1){
8888
for(i in send.to){
8989
if(i != COMM.RANK){
9090
tmp <- matrix(X.spmd[bal.info$send$belong == i,], ncol = p)
@@ -104,7 +104,7 @@ load.balance <- function(X.spmd, bal.info = NULL, comm = .SPMD.CT$comm,
104104
recv.from <- as.integer(unique(bal.info$recv$org))
105105
if(length(recv.from) > 0){
106106
ret <- NULL
107-
if(gbd.major == 1){
107+
if(spmd.major == 1){
108108
for(i in recv.from){
109109
if(i != COMM.RANK){
110110
tmp <- recv(rank.source = i, tag = i, comm = comm)
@@ -130,7 +130,7 @@ load.balance <- function(X.spmd, bal.info = NULL, comm = .SPMD.CT$comm,
130130
}
131131

132132
if(bal.info$new.N.allspmd[spmd.comm.rank(comm) + 1] == 0){
133-
if(gbd.major == 1){
133+
if(spmd.major == 1){
134134
ret <- matrix(0, nrow = 0, ncol = p)
135135
} else{
136136
ret <- matrix(0, nrow = p, ncol = 0)
@@ -148,7 +148,7 @@ unload.balance <- function(new.X.spmd, bal.info, comm = .SPMD.CT$comm){
148148
belong = bal.info$send$org),
149149
N.allspmd = bal.info$new.N.allspmd,
150150
new.N.allspmd = bal.info$N.allspmd,
151-
gbd.major = bal.info$gbd.major)
151+
spmd.major = bal.info$spmd.major)
152152
load.balance(new.X.spmd, bal.info = rev.bal.info, comm = comm)
153153
} # End of unload.balance().
154154

R/dmat_em_initial.r

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ initial.em.dmat <- function(PARAM, MU = NULL){
2424
# -1.3357516, 0.5336209, 1.2700404,
2525
# -1.3110521, 0.2632600, 1.7063794
2626
# )
27-
PARAM$MU <- c(
28-
0.2328901, 0.7281706, -1.0026075,
29-
-0.6238820, -0.2584021, 0.8862744,
30-
0.4944164, 0.7662080, -1.2993873,
31-
0.4674663, 0.7461591, -1.2516524
32-
)
33-
PARAM$MU <- matrix(PARAM$MU, nrow = 4)
27+
#PARAM$MU <- c(
28+
# 0.2328901, 0.7281706, -1.0026075,
29+
# -0.6238820, -0.2584021, 0.8862744,
30+
# 0.4944164, 0.7662080, -1.2993873,
31+
# 0.4674663, 0.7461591, -1.2516524
32+
#)
33+
#PARAM$MU <- matrix(PARAM$MU, nrow = 4)
3434

3535
e.step.dmat(PARAM)
3636
PARAM <- em.onestep.dmat(PARAM)

0 commit comments

Comments
 (0)