[Yuima-commits] r27 - in pkg/yuima: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 24 18:55:08 CET 2009


Author: iacus
Date: 2009-11-24 18:55:08 +0100 (Tue, 24 Nov 2009)
New Revision: 27

Modified:
   pkg/yuima/R/sim.euler.R
   pkg/yuima/R/sim.euler.space.discretized.R
   pkg/yuima/R/simulate.R
   pkg/yuima/man/simulate.Rd
Log:
added env to sim euler and space discretized

Modified: pkg/yuima/R/sim.euler.R
===================================================================
--- pkg/yuima/R/sim.euler.R	2009-11-24 17:03:09 UTC (rev 26)
+++ pkg/yuima/R/sim.euler.R	2009-11-24 17:55:08 UTC (rev 27)
@@ -26,23 +26,23 @@
   p.b <- function(t, X=numeric(d.size)){
     ##:: assign names of variables
     for(i in 1:length(modelstate)){
-      assign(modelstate[i], X[i])
+      assign(modelstate[i], X[i], env)
     }
-    assign(modeltime, t)
+    assign(modeltime, t, env)
     ##:: solve diffusion term
     if(has.drift){
       tmp <- matrix(0, d.size, r.size+1)
       for(i in 1:d.size){
-        tmp[i,1] <- eval(V0[i])
+        tmp[i,1] <- eval(V0[i], env)
         for(j in 1:r.size){
-          tmp[i,j+1] <- eval(V[[i]][j])
+          tmp[i,j+1] <- eval(V[[i]][j],env)
         }
       }
     }else{  ##:: no drift term (faster)
       tmp <- matrix(0, d.size, r.size)
       for(i in 1:d.size){
         for(j in 1:r.size){
-          tmp[i,j] <- eval(V[[i]][j])
+          tmp[i,j] <- eval(V[[i]][j],env)
         }
       }
     }
@@ -83,9 +83,9 @@
       if(has.drift){
         pbdata <- matrix(0, d.size*(r.size+1), t.size)
         for(i in 1:d.size){
-          pbdata[(i-1)*(r.size+1)+1, ] <- eval(V0[i])
+          pbdata[(i-1)*(r.size+1)+1, ] <- eval(V0[i], env)
           for(j in 1:r.size){
-            pbdata[(i-1)*(r.size+1)+j+1, ] <- eval(V[[i]][j])
+            pbdata[(i-1)*(r.size+1)+j+1, ] <- eval(V[[i]][j], env)
           }
         }
         dim(pbdata)<-(c(r.size+1, d.size*t.size))
@@ -93,7 +93,7 @@
         pbdata <- matrix(0, d.size*r.size, t.size)
         for(i in 1:d.size){
           for(j in 1:r.size){
-            pbdata[(i-1)*r.size+j, ] <- eval(V[[i]][j])
+            pbdata[(i-1)*r.size+j, ] <- eval(V[[i]][j], env)
           }
         }
         dim(pbdata)<-(c(r.size, d.size*t.size))
@@ -116,12 +116,12 @@
     ##:: function to solve c(x,z)
     p.b.j <- function(t, X=numeric(d.size)){
       for(i in 1:length(modelstate)){
-        assign(modelstate[i], X[i])
+        assign(modelstate[i], X[i], env)
       }
-      assign(modeltime, t)
+      assign(modeltime, t, env)
       tmp <- numeric(d.size)
       for(i in 1:d.size){
-        tmp[i] <-  eval(JP[i])
+        tmp[i] <-  eval(JP[i], env)
       }
       return(tmp)
     }

Modified: pkg/yuima/R/sim.euler.space.discretized.R
===================================================================
--- pkg/yuima/R/sim.euler.space.discretized.R	2009-11-24 17:03:09 UTC (rev 26)
+++ pkg/yuima/R/sim.euler.space.discretized.R	2009-11-24 17:55:08 UTC (rev 27)
@@ -16,10 +16,10 @@
 	
 ##:: set time step	
 	delta <- Terminal/division 
+
 	
 	
 	
-	
 ##:: using Space-discretized Euler-Maruyama method
 	
 
@@ -79,14 +79,14 @@
     p.b <- function(t, X=numeric(d.size)){
       ##:: assign names of variables
       for(i in 1:length(modelstate)){
-        assign(modelstate[i], X[i])
+        assign(modelstate[i], X[i], env)
       }
-      assign(modeltime,t)
+      assign(modeltime, t, env)
       tmp <- matrix(0, d.size, r.size+1)
       for(i in 1:d.size){
-        tmp[i,1] <- eval(V0[i])
+        tmp[i,1] <- eval(V0[i],env)
         for(j in 1:r.size){
-          tmp[i,j+1] <- eval(V[[i]][j])
+          tmp[i,j+1] <- eval(V[[i]][j], env)
         }
       }
       return(tmp)

Modified: pkg/yuima/R/simulate.R
===================================================================
--- pkg/yuima/R/simulate.R	2009-11-24 17:03:09 UTC (rev 26)
+++ pkg/yuima/R/simulate.R	2009-11-24 17:55:08 UTC (rev 27)
@@ -67,7 +67,7 @@
   if(par.len>0){
 	for(i in 1:par.len){
 	 pars <- sdeModel at parameter@all[i]
-	 assign(sdeModel at parameter@all[i], true.parameter[i], yuimaEnv)
+	 assign(sdeModel at parameter@all[i], true.parameter[[i]], yuimaEnv)
 	}
   }
 

Modified: pkg/yuima/man/simulate.Rd
===================================================================
--- pkg/yuima/man/simulate.Rd	2009-11-24 17:03:09 UTC (rev 26)
+++ pkg/yuima/man/simulate.Rd	2009-11-24 17:55:08 UTC (rev 27)
@@ -8,7 +8,7 @@
 \arguments{
   \item{object}{an \code{yuima} object.}
   \item{xinit}{initial value vector of state variables.}
-  \item{true.parameter}{initial value vector of parameters.}
+  \item{true.parameter}{named list of parameters.}
   \item{space.discretized}{flag to switch to space-discretized Euler
 	Maruyama method.}
   \item{increment.W}{to specify Wiener increment for each time tics in advance.}
@@ -47,6 +47,20 @@
 ou <- simulate(ou, xinit=1)
 plot(ou)
 
+
+
+# Path-simulation for 1-dim diffusion process. 
+# dXt = theta*Xt*dt + dWt
+mod1 <- setModel(drift="theta*y", diffusion=1, solve.variable=c("y"))
+str(mod1)
+ou1 <- setYuima(model=mod1, sampling=samp)
+
+# Solve SDEs using Euler-Maruyama method. 
+ou1 <- simulate(ou, xinit=1, true.p = list(theta=-1))
+plot(ou1)
+
+
+
 # A multi-dimensional (correlated) diffusion process. 
 # To describe the following model: 
 # X=(X1,X2,X3); dXt = U(t,Xt)dt + V(t)dWt



More information about the Yuima-commits mailing list