[Yuima-commits] r127 - in pkg/yuima: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 28 13:19:34 CEST 2010


Author: abrouste
Date: 2010-09-28 13:19:34 +0200 (Tue, 28 Sep 2010)
New Revision: 127

Added:
   pkg/yuima/R/WoodChanfGn.R
Modified:
   pkg/yuima/DESCRIPTION
   pkg/yuima/R/CholeskyfGn.R
   pkg/yuima/R/simulate.R
Log:
add WoodChan.R

Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION	2010-09-17 10:15:35 UTC (rev 126)
+++ pkg/yuima/DESCRIPTION	2010-09-28 11:19:34 UTC (rev 127)
@@ -1,8 +1,8 @@
 Package: yuima
 Type: Package
 Title: The YUIMA Project package (unstable version)
-Version: 0.1.16
-Date: 2010-09-17
+Version: 0.1.176
+Date: 2010-09-28
 Depends: methods, zoo, stats4, utils
 Suggests: cubature, mvtnorm
 Author: YUIMA Project Team.

Modified: pkg/yuima/R/CholeskyfGn.R
===================================================================
--- pkg/yuima/R/CholeskyfGn.R	2010-09-17 10:15:35 UTC (rev 126)
+++ pkg/yuima/R/CholeskyfGn.R	2010-09-28 11:19:34 UTC (rev 127)
@@ -1,14 +1,10 @@
-CholeskyfGn <-
-function(mesh, H, dim)
-{
-
 ##--------------------------------------------------------------------------
 ## Author : Alexandre Brouste
-## Project: Yuima and Fieldsim
+## Project: Yuima
 ##--------------------------------------------------------------------------
 
 ##--------------------------------------------------------------------------
-## Input        :         mesh : mesh grid where the fBm is evaluated
+## Input                  mesh : mesh grid where the fBm is evaluated
 ##                        H    : self-similarity parameter 
 ##                        dim  : valued in R^dim
 ##      		 
@@ -18,26 +14,39 @@
 ##			  decomposition of the covariance matrix of the fGn.
 ##--------------------------------------------------------------------------
 
-##---------------------------------------------------------
-## Complexity O(N^3) via method chol
+##--------------------------------------------------------------------------
+## Complexity O(N^3) via method chol.... mais mieux pour dim different
 ## Taille memoire N^2
 ## -------------------------------------------------------------------------
-                     
+
+
+CholeskyfGn <- function( mesh , H , dim ){
+
+	
+H2 <- 2*H
+mesh<-mesh[[1]]	
 N<-length(mesh)-2 # N+1 is the size of the fGn sample to be simulated
 fGn<-matrix(0,dim,N+1)
-	for (k in 1:dim){
+
+	
+	
 matcov <- matrix(0,N+1,N+1) # Covariance matrix of the fGn
-H2 <- 2*H
+
 		
-	for (i in (1:(N+1))) {
-		j <- i:(N+1)
-		matcov[i, j]<- 0.5 * (abs(mesh[i+1]-mesh[j])^H2 + abs(mesh[i]-mesh[j+1])^H2 - abs(mesh[i] - mesh[j])^H2-abs(mesh[i+1] - mesh[j+1])^H2)
-		matcov[j, i]<- matcov[i, j]
-	}
-	L <- chol(matcov)
+for (i in (1:(N+1))) {
+	j <- i:(N+1)
+	matcov[i, j]<- 0.5 * (abs(mesh[i+1]-mesh[j])^H2 + abs(mesh[i]-mesh[j+1])^H2 - abs(mesh[i] - mesh[j])^H2-abs(mesh[i+1] - mesh[j+1])^H2)
+	matcov[j, i]<- matcov[i, j]
+}
+	
+L <- chol(matcov)
+	
+for (k in 1:dim){
 	Z <- rnorm(N+1)
 	fGn[k,] <- t(L) %*% Z
-	}	
+}	
 		
-	return(fGn)
+return(fGn)
+
+
 }
\ No newline at end of file

Added: pkg/yuima/R/WoodChanfGn.R
===================================================================
--- pkg/yuima/R/WoodChanfGn.R	                        (rev 0)
+++ pkg/yuima/R/WoodChanfGn.R	2010-09-28 11:19:34 UTC (rev 127)
@@ -0,0 +1,64 @@
+WoodChanfGn <- 
+function( mesh , H , dim )
+{
+
+##--------------------------------------------------------------------------
+## Author : Alexandre Brouste
+## Project: Yuima
+##--------------------------------------------------------------------------
+
+##--------------------------------------------------------------------------
+## Input                  mesh : mesh grid where the fBm is evaluated
+##                        H    : self-similarity parameter 
+##                        dim  : valued in R^dim
+##      		 
+##
+## Output       :         
+##--------------------------------------------------------------------------
+
+##--------------------------------------------------------------------------
+## Complexity ?
+## -------------------------------------------------------------------------
+
+	
+	
+	mesh<-mesh[[1]]
+	
+	N<-length(mesh)-2 # N+1 is the size of the fGn sample to be simulated
+	fGn<-matrix(0,dim,N+1)
+	T<-mesh[N+2]
+	
+	H2 <- 2*H
+	
+	k <- 0:N
+    autocov<-0.5 * (abs(k-1)^H2 - 2*(k)^H2 + (k+1)^H2) * (T/(N+2))^H2
+	# g(0),g(1),g(n-1),g(1)
+	
+	
+	ligne1C<-autocov[1 + c(0:N,(N-1):1)]
+	lambdak<-Re(fft(ligne1C,inverse = TRUE))
+	
+	
+	for (k in 1:dim){
+		
+	zr <- rnorm(N+1)
+    zi <- rnorm(N-1)
+	
+    zr[c(1,N+1)] <- zr[c(1,N+1)]*sqrt(2)
+    zr <- c(zr[1:(N+1)], zr[N:2])
+    zi <- c(0,zi,0,-zi[(N-1):1])
+	
+    z <- Re(fft((zr + 1i* zi) * sqrt(lambdak), inverse = TRUE))
+	
+    fGn[k,]<-z[1:(N+1)] / (2*sqrt(N))
+	
+	}	
+	
+	
+	
+#Traitement des zeros	
+#La matrice est définie positive (voir 17)	
+	
+return(fGn)
+		
+}


Property changes on: pkg/yuima/R/WoodChanfGn.R
___________________________________________________________________
Added: svn:executable
   + *

Modified: pkg/yuima/R/simulate.R
===================================================================
--- pkg/yuima/R/simulate.R	2010-09-17 10:15:35 UTC (rev 126)
+++ pkg/yuima/R/simulate.R	2010-09-28 11:19:34 UTC (rev 127)
@@ -13,7 +13,7 @@
 
 setGeneric("simulate",
 	function(object, nsim=1, seed=NULL, xinit, true.parameter, space.discretized=FALSE, 
-		increment.W=NULL, increment.L=NULL, methodfGn="Cholesky", 
+		increment.W=NULL, increment.L=NULL, methodfGn="WoodChan", 
 		sampling=sampling, subsampling=subsampling, ...
 #		Initial = 0, Terminal = 1, n = 100, delta, 
 #		grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
@@ -26,7 +26,7 @@
 setMethod("simulate", "yuima.model",
  function(object, nsim=1, seed=NULL, xinit, true.parameter, 
 	space.discretized=FALSE, increment.W=NULL, increment.L=NULL,
-	methodfGn="Cholesky",
+	methodfGn="WoodChan",
 	sampling, subsampling,
 #Initial = 0, Terminal = 1, n = 100, delta, 
 #	grid, random = FALSE, sdelta=as.numeric(NULL), 
@@ -54,7 +54,7 @@
 setMethod("simulate", "yuima",
  function(object, nsim=1, seed=NULL, xinit, true.parameter, 
 	space.discretized=FALSE, increment.W=NULL, increment.L=NULL,
-	methodfGn="Cholesky",
+	methodfGn="WoodChan",
 	sampling, subsampling,
 	Initial = 0, Terminal = 1, n = 100, delta, 
 	grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
@@ -190,11 +190,14 @@
 	 if( sdeModel at hurst!=0.5 ){ 
 	
 		grid<-sampling2grid(yuima at sampling)	
-		if(methodfGn=="Cholesky"){
+		isregular<-yuima at sampling@regular 
+		 
+		
+		if((!isregular) || (methodfGn=="Cholesky")){
 			dW<-CholeskyfGn(grid, sdeModel at hurst,r.size)
+			yuima.warn("Cholesky method for simulating fGn has been used.")
 		} else {
-			yuima.warn("Not done presently.")
-			return(NULL)	
+			dW<-WoodChanfGn(grid, sdeModel at hurst,r.size)
 		}
 						
 	} else {



More information about the Yuima-commits mailing list