Skip to content

Commit 1f6a8cb

Browse files
committed
updates
1 parent 73a5331 commit 1f6a8cb

File tree

8 files changed

+51
-3
lines changed

8 files changed

+51
-3
lines changed

R/00_pmclust_reduceK.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ pmclust.reduceK <- function(X = NULL, K = 2, MU = NULL,
1313
### Repeat if error occurs.
1414
repeat{
1515
if(ret$check$convergence == 99 && K > 1){
16-
### Drop the smallest class or
16+
### Drop specific i.k if available or
17+
### drop the smallest class or
1718
### drop the class with the smallest eta among all small classes or
1819
### drop all classes with 0 elements.
1920
PARAM.new <- ret$param
20-
i.k <- which(ret$n.class == min(ret$n.class))
21+
if(.pmclustEnv$CONTROL$stop.at.fail && .pmclustEnv$FAIL.i.k > 0){
22+
i.k <- .pmclustEnv$FAIL.i.k
23+
} else{
24+
i.k <- which(ret$n.class == min(ret$n.class))
25+
}
2126
if(i.k > 1 && min(ret$n.class) > 0){
2227
i.k <- i.k[which.min(PARAM.new$ETA[i.k])]
2328
}

R/dmat_em_base.r

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ m.step.dmat <- function(PARAM){
227227
if(.pmclustEnv$CONTROL$debug > 2){
228228
comm.cat(" SIGMA[[", i.k, "]] has NaN. Updating is skipped.\n", sep = "", quiet = TRUE)
229229
}
230+
231+
.pmclustEnv$FAIL.i.k <- i.k # i.k is failed to update.
232+
if(.pmclustEnv$CONTROL$stop.at.fail){
233+
stop(paste("NaN occurs at", i.k))
234+
}
230235
}
231236
} else{
232237
if(.pmclustEnv$CONTROL$debug > 2){
@@ -270,6 +275,11 @@ em.step.dmat <- function(PARAM.org){
270275
time.start <- proc.time()
271276
}
272277

278+
### This is used to record which i.k may be failed to update.
279+
.pmclustEnv$FAIL.i.k <- 0
280+
281+
### Start EM next in DMAT format.
282+
273283
### WCC: original
274284
PARAM.new <- try(em.onestep.dmat(PARAM.org))
275285
### WCC: temp

R/pm_aecm_base.r

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ cm.step.spmd.SIGMA <- function(PARAM){
5555
if(.pmclustEnv$CONTROL$debug > 2){
5656
comm.cat(" SIGMA[[", i.k, "]] has NaN. Updating is skipped\n", sep = "", quiet = TRUE)
5757
}
58+
59+
.pmclustEnv$FAIL.i.k <- i.k # i.k is failed to update.
60+
if(.pmclustEnv$CONTROL$stop.at.fail){
61+
stop(paste("NaN occurs at", i.k))
62+
}
5863
}
5964
} else{
6065
if(.pmclustEnv$CONTROL$debug > 2){
@@ -92,6 +97,10 @@ aecm.step.spmd <- function(PARAM.org){
9297
time.start <- proc.time()
9398
}
9499

100+
### This is used to record which i.k may be failed to update.
101+
.pmclustEnv$FAIL.i.k <- 0
102+
103+
### Start AECM here.
95104
PARAM.new <- try(aecm.onestep.spmd(PARAM.org))
96105
if(comm.any(class(PARAM.new) == "try-error")){
97106
comm.cat("Results of previous iterations are returned.\n", quiet = TRUE)

R/pm_apecm_base.r

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ apecm.step.spmd <- function(PARAM.org){
133133
time.start <- proc.time()
134134
}
135135

136+
### This is used to record which i.k may be failed to update.
137+
.pmclustEnv$FAIL.i.k <- 0
138+
139+
### Start APECM here.
136140
PARAM.new <- try(apecm.onestep.spmd(PARAM.org))
137141
if(comm.any(class(PARAM.new) == "try-error")){
138142
comm.cat("Results of previous iterations are returned.\n", quiet = TRUE)

R/pm_apecma_base.r

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ cm.step.spmd.MU.SIGMA.k <- function(PARAM, i.k){
5252
if(.pmclustEnv$CONTROL$debug > 2){
5353
comm.cat(" SIGMA[[", i.k, "]] has NaN. Updating is skipped.\n", sep = "", quiet = TRUE)
5454
}
55+
56+
.pmclustEnv$FAIL.i.k <- i.k # i.k is failed to update.
57+
if(.pmclustEnv$CONTROL$stop.at.fail){
58+
stop(paste("NaN occurs at", i.k))
59+
}
5560
}
5661
} else{
5762
if(.pmclustEnv$CONTROL$debug > 2){
@@ -87,6 +92,10 @@ apecma.step.spmd <- function(PARAM.org){
8792
time.start <- proc.time()
8893
}
8994

95+
### This is used to record which i.k may be failed to update.
96+
.pmclustEnv$FAIL.i.k <- 0
97+
98+
### Start APECMA here.
9099
PARAM.new <- try(apecma.onestep.spmd(PARAM.org))
91100
if(comm.any(class(PARAM.new) == "try-error")){
92101
comm.cat("Results of previous iterations are returned.\n", quiet =TRUE)

R/pm_em_base.r

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ m.step.spmd <- function(PARAM){
102102
if(.pmclustEnv$CONTROL$debug > 2){
103103
comm.cat(" SIGMA[[", i.k, "]] has NaN. Updating is skipped.\n", sep = "", quiet = TRUE)
104104
}
105+
106+
.pmclustEnv$FAIL.i.k <- i.k # i.k is failed to update.
107+
if(.pmclustEnv$CONTROL$stop.at.fail){
108+
stop(paste("NaN occurs at", i.k))
109+
}
105110
}
106111
} else{
107112
if(.pmclustEnv$CONTROL$debug > 2){
@@ -175,6 +180,10 @@ em.step.spmd <- function(PARAM.org){
175180
time.start <- proc.time()
176181
}
177182

183+
### This is used to record which i.k may be failed to update.
184+
.pmclustEnv$FAIL.i.k <- 0
185+
186+
### Start EM here.
178187
PARAM.new <- try(em.onestep.spmd(PARAM.org))
179188
if(comm.any(class(PARAM.new) == "try-error")){
180189
comm.cat("Results of previous iterations are returned.\n", quiet = TRUE)

data/control.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
exp.min = log(.Machine$double.xmin),
1616
exp.max = log(.Machine$double.xmax),
1717
U.max = 1e+4,
18-
U.min = 1e-6
18+
U.min = 1e-6,
19+
stop.at.fail = TRUE
1920
)
2021
)
2122

man/13_d.control.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
\code{exp.max} \tab maximum exponent (\code{log(.Machine$double.xmax)}) \cr
3131
\code{U.min} \tab minimum of diagonal of \code{\link[base]{chol}} \cr
3232
\code{U.max} \tab maximum of diagonal of \code{\link[base]{chol}} \cr
33+
\code{stop.at.fail} \tab stop iterations when fails such as NaN \cr
3334
}
3435
These elements govern the computing including number of iterations,
3536
convergent criteria, ill conditions, and numerical issues.

0 commit comments

Comments
 (0)