[Yuima-commits] r677 - pkg/yuima/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 17 15:26:50 CEST 2018


Author: lorenzo
Date: 2018-09-17 15:26:49 +0200 (Mon, 17 Sep 2018)
New Revision: 677

Modified:
   pkg/yuima/R/simulateForPpr.R
Log:
Improved Simulation PPR

Modified: pkg/yuima/R/simulateForPpr.R
===================================================================
--- pkg/yuima/R/simulateForPpr.R	2018-09-16 23:53:08 UTC (rev 676)
+++ pkg/yuima/R/simulateForPpr.R	2018-09-17 13:26:49 UTC (rev 677)
@@ -203,7 +203,7 @@
   return(object)
 }
 
-eulerPPR<-function(xinit,yuima,Initial,Terminal, dW, env){
+eulerPPR<-function(xinit,yuima,Initial,Terminal, dW, n, env){
   
   sdeModel<-yuima at model
   
@@ -216,7 +216,7 @@
   # Terminal <- yuima at sampling@Terminal[1]
   # Initial <- yuima at sampling@Initial[1]
   
-  n <- yuima at sampling@n[1]
+  #n <- ceiling((Terminal-Initial)/yuima at sampling@delta)
   dL <- env$dL
   
   if(length(unique(as.character(xinit)))==1 &&
@@ -295,7 +295,7 @@
       return(tmp)
     }
     
-    X_mat <- matrix(0, d.size, n+1)
+    X_mat <- matrix(0, d.size, (n+1))
     X_mat[,1] <- dX
     
     if(has.drift){  
@@ -327,6 +327,9 @@
     if(is.null(dim(dZ)))
       dZ <- matrix(dZ,nrow=1)
     for(i in 1:n){
+      # if(i==720 & n==720){
+      #   aa<-NULL
+      # }
       assign(sdeModel at jump.variable, dZ[,i], env)
       
       if(sdeModel at J.flag){
@@ -437,9 +440,15 @@
     assign("dL",Noise.Laux,myenv)
     
     
+    condMatrdW <- is.matrix(dW)
+    if(condMatrdW){
+      dimdW <- dim(dW)[2]
+    }else{
+      dimdW <- length(dW)
+    }
     
     CovariateSim<- eulerPPR(xinit=xinit,yuima=object,dW=dW, 
-             Initial=samp at Initial,Terminal=samp at Terminal,
+             Initial=samp at Initial,Terminal=samp at Terminal,n=samp at n,
              env=myenv)
     rownames(CovariateSim)<- Model at solve.variable
     assign("info.PPR", object at PPR, myenv)
@@ -453,6 +462,10 @@
       }
     }
     
+    dimNoise<-dim(Noise.Laux)
+    dimCovariateSim <- dim(CovariateSim)
+    
+    
     ExprHaz <- constHazIntPr(g.Fun = object at gFun@formula,
        Kern.Fun = object at Kernel, covariates = object at PPR@covariates,
        counting.var = object at PPR@counting.var)$Intens
@@ -519,8 +532,7 @@
         while(cond[j]>0 && noExit[j]){
           lambda<-compErrHazR4(samp, Kern, capitalTime=samp at grid[[1]][inter_i[j]], 
                                Model, myenv, ExprHaz, Time=jumpT, dN, Index, j)
-          # lambda<-hawkesInt(mu=mu, alpha=alpha, beta=beta,
-          #                   timet=grid[i], JumpT=jumpT)
+    
           incrlambda <- lambda*delta
           HazardRate <- HazardRate+incrlambda
           cond[j] <- const[j]-HazardRate
@@ -533,22 +545,11 @@
             
             if (dimCov>0){
               for(j in c(1:dimCov)){
-                # my.covdata <- simMod at data@original.data[1:i,object at PPR@covariates[j]]
-                # names(my.covdata) <-simMod at sampling@grid[[1]][1:i]
-                # 
-                # assign(object at PPR@covariates[j],
-                #        my.covdata,
-                #        envir = my.env)
-                
                 assign(object at PPR@covariates[j],
                        as.numeric(CovariateSim[object at PPR@covariates[j],1:inter_i[j]]),
                        envir = myenv)
               }
             }  
-            
-            
-            # Line 354 necessary for the development of the code.
-            # cat("\n ", i, grid[i])
           }
         }
       }
@@ -570,12 +571,29 @@
             dN <- cbind(dN,dumdN)
           }
           cat("\n ", i, grid[i])
-          assign("dL",Noise.Laux,myenv)
           
-          CovariateSim<- eulerPPR(xinit=xinit,yuima=object,dW=dW,
-                                  Initial=samp at Initial,Terminal=samp at Terminal,
-                                  env=myenv)
-           
+          # assign("dL",Noise.Laux,myenv)
+          # 
+          # CovariateSim<- eulerPPR(xinit=xinit,yuima=object,dW=dW,
+          #                         Initial=samp at Initial,Terminal=samp at Terminal,
+          #                         env=myenv)
+          
+          assign("dL",Noise.Laux[,c((i-1):dimNoise[2])],myenv)
+          xinit <- CovariateSim[,i-1]
+
+
+          if(condMatrdW){
+            CovariateSim[,(i-1):dimCovariateSim[2]] <- eulerPPR(xinit=xinit,
+              yuima=object,dW=dW[,(i-1):dimdW],
+              Initial=samp at grid[[1]][i-1],Terminal=samp at Terminal,n=(samp at n-(i-1)+1),
+              env=myenv)
+          }else{
+            CovariateSim[,(i-1):dimCovariateSim[2]] <- eulerPPR(xinit=xinit,
+              yuima=object, dW=dW[(i-1):dimdW],
+             Initial=samp at grid[[1]][i-1],Terminal=samp at Terminal,n=(samp at n-(i-1)+1),
+             env=myenv)
+          }
+          
           rownames(CovariateSim)<- Model at solve.variable
           
           



More information about the Yuima-commits mailing list