[adegenet-commits] r341 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 2 17:58:08 CEST 2009


Author: jombart
Date: 2009-06-02 17:58:08 +0200 (Tue, 02 Jun 2009)
New Revision: 341

Modified:
   pkg/R/seqTrack.R
Log:
new outputs for optimize.seqTrack


Modified: pkg/R/seqTrack.R
===================================================================
--- pkg/R/seqTrack.R	2009-06-02 08:49:12 UTC (rev 340)
+++ pkg/R/seqTrack.R	2009-06-02 15:58:08 UTC (rev 341)
@@ -434,16 +434,9 @@
 
     ## AUXILIARY FUNCTIONS ##
 
-    ## FIND INITIAL SEQTRACK RESULT ##
-    res.ini <- seqTrack(seq.names, seq.dates, W, optim=c("min","max"))
-
-    ## to compare results
-    use.new.res <- function(res.old, res.new){
-        if(optim=="min"){
-            return(sum(res.old$weight, na.rm=TRUE) > sum(res.new$weight, na.rm=TRUE))
-        } else {
-            return(sum(res.old$weight, na.rm=TRUE) < sum(res.new$weight, na.rm=TRUE))
-        }
+    ## to compare results -> returns a list of length two: logical, and the value of the res
+    val.res <- function(res){
+        return(sum(res$weight, na.rm=TRUE))
     }
 
 
@@ -456,10 +449,16 @@
     ## and allows not to handle huge objects
     ## (which would grow exponentially)
 
-    res.best <- res.ini # initialization
-    valRes <- numeric(nsim)
+    ##    res.best <- res.ini # initialization
 
 
+    ## DEFINE OUTPUTS ##
+    ances <- integer(0)
+    date <- character(0)
+    ances.date <- character(0)
+    valRes <- numeric(0)
+
+
     ## DEFAULT CASE: NO MISSING DATES
     if(!any(isMissDate)){
         for(i in 1:nsim){
@@ -467,9 +466,12 @@
                 .rTimeSeq(n=NB.DATES.TO.SIM, mu0=mu0, L=seq.length, maxNbDays=RANGE.DATES)*24*3600
             myDates <- as.POSIXct(round(myDates, units="days"))
             res.new <- seqTrack(seq.names=seq.names, seq.dates=myDates, W=W, optim=optim, proxMat=proxMat, ...)
-            valRes[i] <- sum(res.new$weight,na.rm=TRUE)
-            if(use.new.res(res.best, res.new)){
-                res.best <- res.new
+            temp <- val.res(res.new)
+            if(ifelse(optim=="min", temp < thres, temp > thres)){
+                ances <- cbind(ances, res.new$ances)
+                date <- cbind(date, res.new$date)
+                ances.date <- cbind(ances.date, res.new$ances.date)
+                valRes <- c(valRes, temp)
             }
         }
     }



More information about the adegenet-commits mailing list