[Robast-commits] r556 - in branches/robast-0.9/pkg/RobExtremes: R inst/AddMaterial/interpolation man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 25 04:27:21 CET 2013
Author: ruckdeschel
Date: 2013-01-25 04:27:21 +0100 (Fri, 25 Jan 2013)
New Revision: 556
Added:
branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationsmanipulations.R
Modified:
branches/robast-0.9/pkg/RobExtremes/R/recomputeInterpolators.R
branches/robast-0.9/pkg/RobExtremes/R/sysdata.rda
branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationscripts.R
branches/robast-0.9/pkg/RobExtremes/man/internal-interpolate.Rd
Log:
RobExtremes: produced Weibull and GEV grids (in part; RMXE still missing; MBRE-GEV gave problems)
Modified: branches/robast-0.9/pkg/RobExtremes/R/recomputeInterpolators.R
===================================================================
--- branches/robast-0.9/pkg/RobExtremes/R/recomputeInterpolators.R 2013-01-24 23:11:08 UTC (rev 555)
+++ branches/robast-0.9/pkg/RobExtremes/R/recomputeInterpolators.R 2013-01-25 03:27:21 UTC (rev 556)
@@ -1,6 +1,6 @@
.recomputeInterpolators <- function(sysdataFiles, sysRdaFolder = ".",
others = FALSE, onlyothers = FALSE,
- overwrite = TRUE, integrateto = FALSE,
+ translate = TRUE, overwrite = TRUE, integrateto = FALSE,
onlyCurrent = FALSE, withPrint =TRUE,
withSmooth = TRUE,
debug = FALSE){
@@ -8,7 +8,7 @@
wprint <- function(...){ if (withPrint) print(...)}
sam <- new.env()
- for(File in sysdataFiles) load(File, envir = sam)
+ for(File in sysdataFiles) .mergeF(File, envir = sam)
keep <- if(getRversion()>="2.16") "N" else "O"
todo <- if(getRversion()>="2.16") "O" else "N"
@@ -95,6 +95,7 @@
lsA <- ls(all.names=T,envir=only.grid)
wprint(lsA)
+ if(translate)
for(what in whatIsThereAlready.O){
wprint("translating foreign to current architecture")
what.N <- sub(paste("\\.", todo, "$", sep=""),
@@ -150,7 +151,57 @@
}
}
+.renameGridName <- function(gridnam, namOld, namNew, rdafileOld, rdafileNew){
+ nE <- new.env()
+ load(rdafileOld,envir=nE)
+ what <- ls(all.names=TRUE,envir=nE)
+ a <- get(gridnam, envir=nE)
+ na <- names(a)
+ wi <- which(namOld==na)
+ na[wi] <- namNew
+ names(a) <- na
+ assign(gridnam,a,envir=nE)
+ save(list=what, file=rdafileNew, envir=nE)
+}
+
+.mergeF <- function(file,envir){
+ envir2 <- new.env()
+ load(file,envir=envir2)
+ what1 <- ls(all.names=TRUE,envir=envir)
+ what2 <- ls(all.names=TRUE,envir=envir2)
+ for(w2 in what2){
+ wG2 <- get(w2, envir=envir2)
+ if(w2 %in% what1){
+ wG1 <- get(w2, envir=envir)
+ for(Fam1 in names(wG1)){
+ if( ! Fam1 %in% names(wG2)) wG2[[Fam1]] <- wG1[[Fam1]]
+ }
+ }
+ assign(w2,wG2,envir=envir)
+ }
+ return(invisible(NULL))
+}
if(FALSE){
+ a <- NULL; a[["TU"]] = 2
+ save(a,file="testA.Rdata")
+ a <- NULL; a[["HU"]] = 3
+ nE <- new.env(); assign("a",a,envir=nE)
+ .mergeF("testA.Rdata",nE)
+ get("a",envir=nE)
+}
+
+.copyGrid <- function(grid, gridnam, namOld, namNew, rdafileOld, rdafileNew){
+ nE <- new.env()
+ load(fileOld,envir=nE)
+ gr <- get(gridnam,envir=nE)
+ gr[[namNew]] <- gr[[namOld]]
+ gr[[namNew]]$grid <- grid
+ assign(gridnam,gr,envir=nE)
+ what <- ls(envir=nE, all.names = TRUE)
+ save(list=what, file= fileNew, envir=nE)
+}
+
+if(FALSE){
source("makegridlist.R")
.myFolder <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
source(file.path(.myFolder,"RobExtremes/R","recomputeinterpolators.R"))
Modified: branches/robast-0.9/pkg/RobExtremes/R/sysdata.rda
===================================================================
(Binary files differ)
Modified: branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationscripts.R
===================================================================
--- branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationscripts.R 2013-01-24 23:11:08 UTC (rev 555)
+++ branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationscripts.R 2013-01-25 03:27:21 UTC (rev 556)
@@ -105,21 +105,22 @@
### -> change this according to where you checked out the svn repo:
.basepath <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
## <-
-.saveInterpGrid <- .saveInterpGrid
+.saveInterpGrid <- RobExtremes:::.saveInterpGrid
.svInt <- RobExtremes:::.svInt
.OMSE.xi <- RobExtremes:::.OMSE.xi
.MBRE.xi <- RobExtremes:::.MBRE.xi
.RMXE.xi <- RobExtremes:::.RMXE.xi
.modify.xi.PFam.call <- RobExtremes:::.modify.xi.PFam.call
.myFolder <- file.path(.basepath,"RobExtremes/R")
+.myFolder0 <- file.path(.basepath,"RobExtremesBuffer/tmp0")
.myFolder1 <- file.path(.basepath,"RobExtremesBuffer/tmp1")
.myFolder2 <- file.path(.basepath,"RobExtremesBuffer/tmp2")
.myFolder3 <- file.path(.basepath,"RobExtremesBuffer/tmp3")
chkExist <- function(fN) if(!file.exists(fN)) dir.create(fN, recursive = TRUE)
-sapply(c(.myFolder1,.myFolder2,.myFolder3), chkExist)
+sapply(c(.myFolder0,.myFolder1,.myFolder2,.myFolder3), chkExist)
PF <- WeibullFamily()
.saveInterpGrid(getShapeGrid(gridsize=500, cutoff.at.0=0.005),
- sysRdaFolder = .myFolder, accuracy = 5000,upp=10,
+ sysRdaFolder = .myFolder0, accuracy = 5000,upp=10,
PFam = PF)
## to make this parallel, we write the results to different folders:
.svInt(.OMSE.xi, ".OMSE", PFam = PF, sysRdafolder = .myFolder1)
@@ -127,8 +128,8 @@
.svInt(.RMXE.xi, ".RMXE", PFam = PF, sysRdafolder = .myFolder3)
### merge and thin out results on R-3.0.0
-rdafiles <- file.path(c(myFolder,.myFolder1,myFolder2,.myFolder3),"sysdata.rda")
-.recomputeInterpolators("sysdata.rda", sysRdaFolder = myFolder)
+rdafiles <- file.path(c(.myFolder,.myFolder1,.myFolder2,.myFolder3),"sysdata.rda")
+.recomputeInterpolators(rdafiles, sysRdaFolder = myFolder)
### close R session;
## R CMD build RobExtremes
##---------------------------------------------------------------------
@@ -136,7 +137,7 @@
##---------------------------------------------------------------------
## install new versions of distr-family and robast-family of pkgs
## install RobExtremes from source on R-2.15.2
-require(RobExtremes); RobExtremes:::.recomputeInterpolators(rdafiles, sysRdaFolder = .myFolder)
+require(RobExtremes); RobExtremes:::.recomputeInterpolators(rdafiles[1], sysRdaFolder = .myFolder)
### close R session;
## R CMD build RobExtremes
## R CMD install RobExtremes from source
@@ -164,15 +165,15 @@
### -> change this according to where you checked out the svn repo:
.basepath <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
## <-
-.myFolder <- file.path(.basepath,"RobExtremes/R")
+.myFolder0 <- file.path(.basepath,"RobExtremesBuffer/tmp0")
.myFolder1 <- file.path(.basepath,"RobExtremesBuffer/tmp1")
.myFolder2 <- file.path(.basepath,"RobExtremesBuffer/tmp2")
.myFolder3 <- file.path(.basepath,"RobExtremesBuffer/tmp3")
chkExist <- function(fN) if(!file.exists(fN)) dir.create(fN, recursive = TRUE)
-sapply(c(.myFolder1,.myFolder2,.myFolder3), chkExist)
+sapply(c(.myFolder0,.myFolder1,.myFolder2,.myFolder3), chkExist)
PF <- GammaFamily()
.saveInterpGrid(getShapeGrid(gridsize=500, cutoff.at.0=0.005),
- sysRdaFolder = .myFolder, accuracy = 5000,upp=10,
+ sysRdaFolder = .myFolder0, accuracy = 5000,upp=10,
PFam = PF)
## to make this parallel, we write the results to different folders:
.svInt(.OMSE.xi, ".OMSE", PFam = PF, sysRdafolder = .myFolder1)
@@ -180,8 +181,8 @@
.svInt(.RMXE.xi, ".RMXE", PFam = PF, sysRdafolder = .myFolder3)
### merge and thin out results on R-3.0.0
-rdafiles <- file.path(c(myFolder,.myFolder1,myFolder2,.myFolder3),"sysdata.rda")
-.recomputeInterpolators("sysdata.rda", sysRdaFolder = myFolder)
+rdafiles <- file.path(c(.myFolder,.myFolder1,.myFolder2,.myFolder3),"sysdata.rda")
+.recomputeInterpolators(rdafiles, sysRdaFolder = myFolder)
### close R session;
## R CMD build RobExtremes
##---------------------------------------------------------------------
@@ -189,7 +190,7 @@
##---------------------------------------------------------------------
## install new versions of distr-family and robast-family of pkgs
## install RobExtremes from source on R-2.15.2
-require(RobExtremes); RobExtremes:::.recomputeInterpolators(rdafiles, sysRdaFolder = .myFolder)
+require(RobExtremes); RobExtremes:::.recomputeInterpolators(rdafiles[1], sysRdaFolder = .myFolder)
### close R session;
## R CMD build RobExtremes
## R CMD install RobExtremes from source
Added: branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationsmanipulations.R
===================================================================
--- branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationsmanipulations.R (rev 0)
+++ branches/robast-0.9/pkg/RobExtremes/inst/AddMaterial/interpolation/interpolationsmanipulations.R 2013-01-25 03:27:21 UTC (rev 556)
@@ -0,0 +1,75 @@
+.basepath <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
+.myFolder <- file.path(.basepath,"RobExtremes/R")
+.myFolder1 <- file.path(.basepath,"RobExtremesBuffer/tmp1")
+.myFolder2 <- file.path(.basepath,"RobExtremesBuffer/tmp2")
+.myFolder3 <- file.path(.basepath,"RobExtremesBuffer/tmp3")
+.myFoldera <- file.path(.basepath,"RobExtremesBuffer/tmpa")
+rdafiles <- file.path(c(.myFolder,.myFolder1,.myFolder2,.myFolder3),"sysdata.rda")
+require(RobExtremes); RobExtremes:::.recomputeInterpolators(rdafiles[1], sysRdaFolder = .myFolder)
+
+
+require(RobExtremes)
+.basepath <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
+.myFolder <- file.path(.basepath,"RobExtremes/R")
+.myFolder0 <- file.path(.basepath,"RobExtremesBuffer/tmp0")
+.myFoldera <- file.path(.basepath,"RobExtremesBuffer/tmpa")
+fo=file.path(.myFolder0,"sysdata.rda")
+fn=file.path(.myFolder,"sysdata-1.rda")
+fi=file.path(.myFolder,"sysdata.rda")
+PF <- GEVFamily()
+
+RobExtremes:::.renameGridName(".SnGrids.N","Generalized Pareto Family", name(PF),fo,fn)
+RobExtremes:::.recomputeInterpolators(c(fi,fn), sysRdaFolder = .myFoldera, overwrite=TRUE, translate=FALSE)
+ nE <- new.env()
+ load(file.path(.myFoldera,"sysdata.rda"),envir=nE)
+ ls(all.names=TRUE,envir=nE)
+ str(get(".SnGrids.N",envir=nE))
+ head(get(".SnGrids.N",envir=nE)[[1]]$grid)
+ nE <- new.env()
+ load(fn,envir=nE)
+ ls(all.names=TRUE,envir=nE)
+ str(get(".SnGrids.N",envir=nE))
+ head(get(".SnGrids.N",envir=nE)[[1]]$grid)
+ nE <- new.env()
+ load(fo,envir=nE)
+ ls(all.names=TRUE,envir=nE)
+ str(get(".SnGrids.N",envir=nE))
+ head(get(".SnGrids.N",envir=nE)[[1]]$grid)
+ nE <- new.env()
+ load(fi,envir=nE)
+ ls(all.names=TRUE,envir=nE)
+ str(get(".SnGrids.N",envir=nE))
+ head(get(".SnGrids.N",envir=nE)[[1]]$grid)
+
+
+assignInNamespace(".renameGridName",.renameGridName,ns="RobExtremes")
+
+.basepath <- "C:/rtest/RobASt/branches/robast-0.9/pkg"
+.myFolder <- file.path(.basepath,"RobExtremes/R")
+.myFolder0 <- file.path(.basepath,"RobExtremesBuffer/tmp0")
+.myFolder1 <- file.path(.basepath,"RobExtremesBuffer/tmp1")
+.myFolder2 <- file.path(.basepath,"RobExtremesBuffer/tmp2")
+.myFolder3 <- file.path(.basepath,"RobExtremesBuffer/tmp3")
+.myFoldera <- file.path(.basepath,"RobExtremesBuffer/tmpa")
+require(RobExtremes);
+fo=file.path(.myFolder0,"sysdata.rda")
+fn=file.path(.myFolder,"sysdata-1.rda")
+fn2=file.path(.myFoldera,"sysdata-1.rda")
+fi=file.path(.myFolder,"sysdata.rda")
+PF <- GEVFamily()
+nE <- new.env()
+load("MBRE.Rdata", envir=nE)
+ls(all=T, envir=nE)
+grid <- get("LMGrid", envir=nE)
+RobExtremes:::.copyGrid(grid, ".MBRE.N", name(PF), name(PF), fo, fn2)
+nE <- new.env()
+load(fn2, envir=nE)
+str(get(".MBRE.N",envir=nE))
+
+nE <- new.env()
+
+f <- function(a=1,env=nE){
+ assign("K",a,envir=env)
+}
+
+ls(envir=nE); f(); ls(envir=nE)
Modified: branches/robast-0.9/pkg/RobExtremes/man/internal-interpolate.Rd
===================================================================
--- branches/robast-0.9/pkg/RobExtremes/man/internal-interpolate.Rd 2013-01-24 23:11:08 UTC (rev 555)
+++ branches/robast-0.9/pkg/RobExtremes/man/internal-interpolate.Rd 2013-01-25 03:27:21 UTC (rev 556)
@@ -5,6 +5,9 @@
\alias{.OMSE.xi}
\alias{.MBEE.xi}
\alias{.getLMGrid}
+\alias{.mergeF}
+\alias{.copyGrid}
+\alias{.renameGridName}
\alias{.MakeGridList}
\alias{.saveInterpGrid}
\alias{.recomputeInterpolators}
@@ -42,9 +45,13 @@
sysRdafolder, PFam = GParetoFamily(shape=1,scale=2))
.recomputeInterpolators(sysdataFiles, sysRdaFolder = ".", others = FALSE,
- onlyothers = FALSE, overwrite = TRUE, integrateto = FALSE,
- onlyCurrent = FALSE, withPrint =TRUE, withSmooth = TRUE,
- debug = FALSE)
+ onlyothers = FALSE, translate = TRUE, overwrite = TRUE,
+ integrateto = FALSE, onlyCurrent = FALSE, withPrint =TRUE,
+ withSmooth = TRUE, debug = FALSE)
+
+.renameGridName(gridnam, namOld, namNew, rdafileOld, rdafileNew)
+.copyGrid(grid, gridnam, namOld, namNew, rdafileOld, rdafileNew)
+.mergeF(file,envir)
}
\arguments{
@@ -79,7 +86,9 @@
function to transform \code{Y} to desired return value. }
\item{sysdataFiles}{character; filenames of \file{sysdata.rda} files from
- where to extract the interpolation grids}
+ where to extract the interpolation grids. }
+ \item{overwrite}{logical; if \code{TRUE} foreign grids are translated
+ to current R version. }
\item{overwrite}{logical; if \code{TRUE} existing interpolation functions
for the current R version get recomputed.}
\item{others}{logical; if \code{TRUE} and in the \file{sysdata.rda} files
@@ -95,6 +104,17 @@
ending \code{.N}, \code{.O} and ``others'', these are merged. }
\item{debug}{logical; if \code{TRUE} the \file{sysdata.rda} file is not
created/overwritten in the end. }
+ \item{gridnam}{character; name of the grid to be renamed. }
+ \item{namOld}{character; name of the parametric family to be renamed (from). }
+ \item{namNew}{character; name of the parametric family to be renamed (to). }
+ \item{nam}{character; name of the parametric family to be manipulated. }
+ \item{grid}{matrix or array; grid to be inserted. }
+ \item{rdafileOld}{character; filename of the \file{sysdata.rda}-type file
+ to be read out.}
+ \item{rdafileNew}{character; filename of the \file{sysdata.rda}-type file
+ to be written on.}
+ \item{file}{character; the name of a file to be read out}
+ \item{envir}{an environment}
}
\details{
\code{.MBRE.xi} computes the Lagrange multipliers for the MBRE estimator,
@@ -124,6 +144,24 @@
\code{.recomputeInterpolators} recomputes the interpolating functions from
grids in existing \file{sysdata.rda} files -- either to translate them
to another R version, or to shrink the respective file.
+
+ \code{.renameGridName} is a utility to rename items from a grid. It takes
+ grid \code{gridnam} from file \code{rdafileOld} and takes
+ the name \code{namOld} of a respective item (i.e., a parametric family),
+ renames it to \code{namNew} and writes the result back
+ to file \code{rdafileNew}.
+
+ \code{.copyGrid} takes out a respective item \code{namOld} (i.e., a parametric
+ family) of grid \code{gridnam} from file \code{rdafileOld}
+ copies it to a new grid object onto item \code{namNew}, replaces
+ the respective grid-entry by \code{grid}, and saves the result to
+ to file \code{rdafileNew}.
+
+ \code{.mergeF} merges the contents of file \code{file} into environment
+ \code{envir} in the sense, that if both \code{file} and \code{envir}
+ contain a list object \code{a} also the items of \code{a} are merged,
+ where---as for objects themselves--- contents of \code{file} overwrite
+ contents of \code{envir}.
}
\note{These functions are only meant for the developers of package \pkg{RobExtremes}
(or respective packages).
@@ -154,6 +192,9 @@
in the return value of \code{.getLMGrid}. }
\item{.saveInterpGrid}{ \code{invisible(NULL)}}
\item{.svInt}{ \code{invisible(NULL)}}
+ \item{.renameGridName}{ \code{invisible(NULL)}}
+ \item{.mergeF}{ \code{invisible(NULL)}}
+ \item{.copyGrid}{ \code{invisible(NULL)}}
}
\seealso{\code{\link{interpolateSn}}}
\examples{
More information about the Robast-commits
mailing list