[Yuima-commits] r49 - in pkg/yuima: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Dec 22 07:09:41 CET 2009
Author: iacus
Date: 2009-12-22 07:09:41 +0100 (Tue, 22 Dec 2009)
New Revision: 49
Added:
pkg/yuima/R/subsampling.R
pkg/yuima/man/subsampling.Rd
Modified:
pkg/yuima/DESCRIPTION
pkg/yuima/NAMESPACE
pkg/yuima/R/AllClasses.R
pkg/yuima/R/simulate.R
pkg/yuima/R/yuima.sampling.R
pkg/yuima/man/setSampling.Rd
pkg/yuima/man/simulate.Rd
pkg/yuima/man/yuima-class.Rd
pkg/yuima/man/yuima.model-class.Rd
pkg/yuima/man/yuima.sampling-class.Rd
Log:
generalized simulate, added subsampling, etc
Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/DESCRIPTION 2009-12-22 06:09:41 UTC (rev 49)
@@ -1,8 +1,8 @@
Package: yuima
Type: Package
Title: The YUIMA Project package
-Version: 0.0.79
-Date: 2009-12-20
+Version: 0.0.80
+Date: 2009-12-22
Depends: methods, zoo
Author: YUIMA Project Team.
Maintainer: Stefano M. Iacus <stefano.iacus at R-project.org>
Modified: pkg/yuima/NAMESPACE
===================================================================
--- pkg/yuima/NAMESPACE 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/NAMESPACE 2009-12-22 06:09:41 UTC (rev 49)
@@ -19,15 +19,11 @@
"plot",
## "time",
## "end",
-
"simulate",
"cce",
"poisson.random.sampling",
-
"get.zoo.data",
-
"initialize",
-
"ql",
"rql",
"ml.ql",
@@ -52,6 +48,7 @@
#export(end)
export(simulate) # simulates couple of processes
+export(subsampling)
export(cce)
export(poisson.random.sampling)
Modified: pkg/yuima/R/AllClasses.R
===================================================================
--- pkg/yuima/R/AllClasses.R 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/R/AllClasses.R 2009-12-22 06:09:41 UTC (rev 49)
@@ -58,8 +58,11 @@
delta = "numeric",
grid = "numeric",
random = "ANY",
- scale = "ANY",
- regular = "logical"
+ regular = "logical",
+ sdelta = "numeric",
+ sgrid = "numeric",
+ oindex = "numeric",
+ interpolation = "character"
)
)
Modified: pkg/yuima/R/simulate.R
===================================================================
--- pkg/yuima/R/simulate.R 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/R/simulate.R 2009-12-22 06:09:41 UTC (rev 49)
@@ -9,15 +9,54 @@
##:: function simulate
##:: solves SDE and returns result
+subsampling <- function(x,y) return(x)
+
setGeneric("simulate",
- function(object, nsim, seed, xinit, true.parameter, space.discretized=FALSE, increment.W=NULL, increment.L=NULL, methodfGn="Cholesky")
+ function(object, nsim, seed, xinit, true.parameter, space.discretized=FALSE,
+ increment.W=NULL, increment.L=NULL, methodfGn="Cholesky",
+ sampling=sampling, subsampling=subsampling,
+ Initial = 0, Terminal = 1, n = 100, delta = 0.1,
+ grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none")
standardGeneric("simulate")
- )
+ )
+
+setMethod("simulate", "yuima.model",
+ function(object, nsim=1, seed=NULL, xinit, true.parameter,
+ space.discretized=FALSE, increment.W=NULL, increment.L=NULL,
+ methodfGn="Cholesky",
+ sampling, subsampling,
+ Initial = 0, Terminal = 1, n = 100, delta = 0.1,
+ grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none"){
+
+ tmpsamp <- NULL
+ if(missing(sampling)){
+ tmpsamp <- setSampling(Initial = Initial, Terminal = Terminal, n = n,
+ delta = delta, grid = grid, random = random, sdelta=sdelta,
+ sgrid=sgrid, interpolation=interpolation)
+ } else {
+ tmpsamp <- sampling
+ }
+ tmpyuima <- setYuima(model=object, sampling=tmpsamp)
+ out <- simulate(tmpyuima, nsim=nsim, seed=seed, xinit=xinit,
+ true.parameter=true.parameter,
+ space.discretized=space.discretized,
+ increment.W=increment.W, increment.L=increment.L,
+ methodfGn=methodfGn, subsampling=subsampling)
+ return(out)
+})
+
setMethod("simulate", "yuima",
- function(object, nsim=1, seed=NULL, xinit, true.parameter, space.discretized=FALSE, increment.W=NULL, increment.L=NULL,methodfGn="Cholesky"){
+ function(object, nsim=1, seed=NULL, xinit, true.parameter,
+ space.discretized=FALSE, increment.W=NULL, increment.L=NULL,
+ methodfGn="Cholesky",
+ sampling, subsampling,
+ Initial = 0, Terminal = 1, n = 100, delta = 0.1,
+ grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none"){
-
##:: errors checks
##:1: error on yuima model
@@ -27,7 +66,23 @@
cat("\nyuima object is missing.\n")
return(NULL)
}
-
+
+ tmpsamp <- NULL
+ if(is.null(yuima at sampling)){
+ if(missing(sampling)){
+ tmpsamp <- setSampling(Initial = Initial,
+ Terminal = Terminal, n = n, delta = delta,
+ grid = grid, random = random, sdelta=sdelta,
+ sgrid=sgrid, interpolation=interpolation)
+ } else {
+ tmpsamp <- sampling
+ }
+ } else {
+ tmpsamp <- yuima at sampling
+ }
+
+ yuima at sampling <- tmpsamp
+
sdeModel <- yuima at model
Terminal <- yuima at sampling@Terminal[1]
n <- yuima at sampling@n[1]
@@ -80,7 +135,7 @@
}
##:: Error check for increment specified version.
- if(!missing(increment.W)){
+ if(!missing(increment.W) & !is.null(increment.W)){
if(space.discretized == TRUE){
cat("\nParameter increment must be invalid if space.discretized=TRUE.\n")
return(NULL)
@@ -88,13 +143,13 @@
cat("\nLength of increment's row must be same as yuima at model@noise.number.\n")
return(NULL)
}else if(dim(increment.W)[2] != n){
- cat("\nLength of increment's column must be same as yuima at sampling@n[1].\n")
+ cat("\nLength of increment's column must be same as sampling at n[1].\n")
return(NULL)
}
}
##:: Error check for increment specified version.
- if(!missing(increment.L)){
+ if(!missing(increment.L) & !is.null(increment.L)){
if(space.discretized == TRUE){
cat("\nParameter increment must be invalid if space.discretized=TRUE.\n")
return(NULL)
@@ -102,7 +157,7 @@
cat("\nLength of increment's row must be same as yuima at model@noise.number.\n")
return(NULL)
}else if(dim(increment.L)[2] != n){
- cat("\nLength of increment's column must be same as yuima at sampling@n[1].\n")
+ cat("\nLength of increment's column must be same as sampling at n[1].\n")
return(NULL)
}
}
@@ -120,10 +175,8 @@
##:: using Euler-Maruyama method
delta <- Terminal/n
-
-
- if(missing(increment.W)){
+ if(missing(increment.W) | is.null(increment.W)){
if( sdeModel at hurst!=0.5 ){
grid<-sampling2grid(yuima at sampling)
@@ -142,7 +195,11 @@
} else {
dW <- increment.W
}
-
+
yuima at data <- euler(xinit, yuima, dW, yuimaEnv)
- return(yuima)
+
+ if(missing(subsampling))
+ return(yuima)
+ subsampling(yuima, subsampling)
+
})
Added: pkg/yuima/R/subsampling.R
===================================================================
--- pkg/yuima/R/subsampling.R (rev 0)
+++ pkg/yuima/R/subsampling.R 2009-12-22 06:09:41 UTC (rev 49)
@@ -0,0 +1,13 @@
+## We have splitted the simulate function into blocks to allow for future
+## methods to be added. S.M.I. & A.B.
+## Interface to simulate() changed to match the S3 generic funciton in the
+## package stats
+## added an environment to let R find the proper values defined in the main
+## body of the function, which in turn calls different simulation methods
+## All new simulation methods should look into the yuimaEnv for local variables
+## when they need to "eval" R expressions
+
+##:: function simulate
+##:: solves SDE and returns result
+subsampling <- function(x,y) return(x)
+
Property changes on: pkg/yuima/R/subsampling.R
___________________________________________________________________
Name: svn:executable
+ *
Modified: pkg/yuima/R/yuima.sampling.R
===================================================================
--- pkg/yuima/R/yuima.sampling.R 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/R/yuima.sampling.R 2009-12-22 06:09:41 UTC (rev 49)
@@ -6,10 +6,12 @@
setMethod("initialize", "yuima.sampling",
function(.Object, Initial, Terminal, n, delta, grid, random,
- scale, regular){
- .Object at scale <- 1
+ regular, sdelta, sgrid, oindex, interpolation){
+ .Object at sdelta <- as.numeric(NULL)
+ .Object at sgrid <- as.numeric(NULL)
+ .Object at oindex <- as.numeric(NULL)
+ .Object at interpolation <- "none"
if(length(grid)>0){
-
testInitial<-(min(grid)==Initial)
testTerminal<-(max(grid)==Terminal)
testn<-(abs(n-diff(range(grid))/mean(diff(grid))+1)<10^(-10))
@@ -76,9 +78,11 @@
})
setSampling <- function(Initial=0, Terminal=1, n=100, delta=0.1,
- grid=as.numeric(NULL), random=FALSE, scale=1){
+ grid=as.numeric(NULL), random=FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none" ){
return(new("yuima.sampling", Initial=Initial, Terminal=Terminal,
n=n, delta=delta, grid=grid, random=random,
- scale=scale, regular=TRUE))
+ regular=TRUE, sdelta=sdelta, sgrid=sgrid,
+ interpolation=interpolation))
}
Modified: pkg/yuima/man/setSampling.Rd
===================================================================
--- pkg/yuima/man/setSampling.Rd 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/man/setSampling.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -9,16 +9,20 @@
}
\usage{
setSampling(Initial = 0, Terminal = 1, n = 100, delta = 0.1,
- grid = as.numeric(NULL), random = FALSE, scale=1)
+ grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none" )
}
\arguments{
\item{Initial}{Initial time of the grid.}
\item{Terminal}{Terminal time of the grid.}
\item{n}{number of time intervals.}
- \item{delta}{mesh size in case of regular grid.}
+ \item{delta}{mesh size in case of regular time grid.}
\item{grid}{a grid of times for the simulation, possibly empty.}
\item{random}{specify if it is random sampling. See Details.}
- \item{scale}{by default 1. NOT YET IN USE.}
+ \item{sdelta}{mesh size in case of regular space grid.}
+ \item{sgrid}{a grid in space for the simulation, possibly empty.}
+ \item{interpolation}{a rule of interpolation in case of subsampling.
+ By default, no interpolation. See Details.}
}
\details{
The function creates an object of type
@@ -27,14 +31,41 @@
\item{\code{Initial}:}{initial time of the grid.}
\item{\code{Terminal}:}{terminal time fo the grid.}
\item{\code{n}:}{the number of observations - 1.}
- \item{\code{delta}:}{in case of a regular grid is the mesh.}
+ \item{\code{delta}:}{in case of a regular time grid it is the mesh.}
\item{\code{grid}:}{the grid of times.}
\item{\code{random}:}{either \code{FALSE} or the distribution
of the random times.}
- \item{\code{scale}:}{by default 1. NOT YET IN USE.}
\item{\code{regular}:}{indicator of whether the grid is regular or not.
For internal use only.}
+ \item{\code{sdelta}:}{in case of a regular space grid it is the mesh.}
+ \item{\code{sgrid}:}{the grid in space.}
+ \item{\code{oindex}:}{in case of interpolation, a vector of indexes
+ corresponding to the original observations used for the approximation.}
+ \item{\code{interpolation}:}{the name of the interpolation method used.}
}
+
+In case of subsampling, the observations are subsampled on some given
+\code{grid}/\code{sgrid} or according to some \code{random} times. When
+the original observations do not exist at a give point of the grid they are
+obtained by some approximation method. Available methods are \code{"pt"} or
+\code{"previous tick"} observation method, \code{"nt"} or \code{"next tick"}
+observation method, or by l\code{"linear"} interpolation.
+In case of interpolation, the slot \code{oindex} contains the vector of indexes
+corresponding to the original observations used for the approximation. For the
+linear method the index corresponds to the left-most observation.
+
+The slot \code{random} is used as information in case a \code{grid} is
+already determined (e.g. \code{n} or \code{delta}, etc. ot the \code{grid}
+itself are given) or if some subsampling has occurred or if some particular
+method which causes a random grid is used in simulation (for example the
+space discretized Euler scheme). The slot \code{random} contains a list
+of two elements \code{distr} and \code{scale}, where \code{distr} is a
+the distribution of independent random times and \code{scale} is either a
+scaling constant or a scaling function.
+If the \code{grid} of times is deterministic, then \code{random} is \code{FALSE}.
+
+If not given, the slot \code{grid} is always filled after the call to the
+function \code{\link{simulate}}.
}
\value{
An object of type \code{\link{yuima.sampling-class}}.
Modified: pkg/yuima/man/simulate.Rd
===================================================================
--- pkg/yuima/man/simulate.Rd 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/man/simulate.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -4,10 +4,15 @@
\description{Simulate multi-dimensional stochastic processes.}
\usage{
simulate(object, nsim, seed, xinit, true.parameter, space.discretized = FALSE,
- increment.W = NULL, increment.L = NULL, methodfGn = "Cholesky")
+ increment.W = NULL, increment.L = NULL, methodfGn = "Cholesky",
+ sampling, subsampling,
+ Initial = 0, Terminal = 1, n = 100, delta = 0.1,
+ grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL),
+ sgrid=as.numeric(NULL), interpolation="none")
}
\arguments{
- \item{object}{an \code{\link{yuima-class}} object.}
+ \item{object}{an \code{\link{yuima-class}} or
+ \code{\link{yuima.model-class}} object.}
\item{xinit}{initial value vector of state variables.}
\item{true.parameter}{named list of parameters.}
\item{space.discretized}{flag to switch to space-discretized Euler
@@ -19,6 +24,18 @@
\item{seed}{Not used yet. Included only to match the standard genenirc in
package \code{stats}.}
\item{methodfGn}{simulation methods for fractional Gaussian noise.}
+ \item{Initial}{Initial time of the grid.}
+ \item{Terminal}{Terminal time of the grid.}
+ \item{n}{number of time intervals.}
+ \item{delta}{mesh size in case of regular time grid.}
+ \item{grid}{a grid of times for the simulation, possibly empty.}
+ \item{random}{specify if it is random sampling. See Details.}
+ \item{sdelta}{mesh size in case of regular space grid.}
+ \item{sgrid}{a grid in space for the simulation, possibly empty.}
+ \item{interpolation}{a rule of interpolation in case of subsampling.
+ By default, no interpolation. See Details.}
+ \item{sampling}{a \code{\link{yuima.sampling-class}} object.}
+ \item{subsampling}{a \code{\link{yuima.sampling-class}} object.}
}
\details{
\code{simulate} is a function to solve SDE using the Euler-Maruyama
@@ -28,9 +45,18 @@
It simulates solutions of stochastic differential equations with Gaussian noise,
fractional Gaussian noise awith/without jumps.
+
+If a \code{\link{yuima-class}} object is passed as input, then the sampling
+information is taken from the slot \code{sampling} of the object.
+If a \code{\link{yuima.model-class}} object or a
+\code{\link{yuima-class}} object with missing \code{sampling} slot is passed
+as input the \code{sampling} argument is used. If this argument is missing
+then the sampling structure is constructed from \code{Initial}, \code{Terminal},
+etc. arguments (see \code{\link{setSampling}} for details on how to use these
+arguments).
}
\value{
- \item{yuima}{A multi-dimensional \code{yuima} object(time series object).}
+ \item{yuima}{a \code{yuima-class} object.}
}
\author{The YUIMA Project Team}
\note{There may be missing information in the simulate description.
@@ -51,11 +77,23 @@
ou <- setYuima(model=mod, sampling=samp)
# Solve SDEs using Euler-Maruyama method.
+par(mfrow=c(3,1))
ou <- simulate(ou, xinit=1)
plot(ou)
+set.seed(123)
+ouB <- simulate(mod, xinit=1,sampling=samp)
+plot(ouB)
+
+set.seed(123)
+ouC <- simulate(mod, xinit=1, Terminal=1, n=1000)
+plot(ouC)
+
+par(mfrow=c(1,1))
+
+
# Path-simulation for 1-dim diffusion process.
# dXt = theta*Xt*dt + dWt
mod1 <- setModel(drift="theta*y", diffusion=1, solve.variable=c("y"))
Added: pkg/yuima/man/subsampling.Rd
===================================================================
--- pkg/yuima/man/subsampling.Rd (rev 0)
+++ pkg/yuima/man/subsampling.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -0,0 +1,19 @@
+\name{subsampling}
+\alias{subsampling}
+\title{subsampling }
+\description{subsampling }
+\usage{
+subsampling(x,y)
+}
+\arguments{
+ \item{x}{an \code{\link{yuima-class}} or
+ \code{\link{yuima.model-class}} object.}
+ \item{y}{initial value vector of state variables.}
+ }
+\value{
+ \item{yuima}{a \code{yuima-class} object.}
+}
+\author{The YUIMA Project Team}
+\note{This is curently an empty function. To be implemented soon.
+}
+\keyword{ts}
Property changes on: pkg/yuima/man/subsampling.Rd
___________________________________________________________________
Name: svn:executable
+ *
Modified: pkg/yuima/man/yuima-class.Rd
===================================================================
--- pkg/yuima/man/yuima-class.Rd 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/man/yuima-class.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -71,7 +71,8 @@
\item{cce}{\code{signature(x = "yuima")}: calculates the asyncronous
covariance estimator on the data contained in \code{x at data@zoo.data}.
For more details see \code{\link{cce}}.}
-
+ \item{simulate}{simulation method. For more information see
+ \code{\link{simulate}}.}
}
}
\author{The YUIMA Project Team}
Modified: pkg/yuima/man/yuima.model-class.Rd
===================================================================
--- pkg/yuima/man/yuima.model-class.Rd 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/man/yuima.model-class.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -4,6 +4,7 @@
\alias{initialize,yuima.model-method}
\alias{initialize,model.parameter-method}
\alias{limiting.gamma,yuima.model-method}
+\alias{simulate,yuima.model-method}
%%\alias{setSampling,yuima.model-method}
\title{Classes for the mathematical description of stochastic differential equations}
Modified: pkg/yuima/man/yuima.sampling-class.Rd
===================================================================
--- pkg/yuima/man/yuima.sampling-class.Rd 2009-12-20 10:29:27 UTC (rev 48)
+++ pkg/yuima/man/yuima.sampling-class.Rd 2009-12-22 06:09:41 UTC (rev 49)
@@ -15,14 +15,19 @@
\item{\code{grid}:}{the grid of times.}
\item{\code{random}:}{either \code{FALSE} or the distribution
of the random times.}
- \item{\code{scale}:}{by default 1. NOT YET IN USE.}
\item{\code{regular}:}{indicator of whether the grid is regular or not.
For internal use only.}
+ \item{\code{sdelta}:}{in case of a regular space grid it is the mesh.}
+ \item{\code{sgrid}:}{the grid in space.}
+ \item{\code{oindex}:}{in case of interpolation, a vector of indexes
+ corresponding to the original observations used for the approximation.}
+ \item{\code{interpolation}:}{the name of the interpolation method used.}
}
}
\details{
This object is created by \code{\link{setSampling}} or as a result of a
-simulation scheme by the \code{\link{simulate}} function.
+simulation scheme by the \code{\link{simulate}} function or after
+subsampling via the function \code{\link{subsampling}}.
}
\author{The YUIMA Project Team}
\keyword{classes}
More information about the Yuima-commits
mailing list