[Rsiena-commits] r303 - / pkg/RSiena pkg/RSiena/R pkg/RSiena/man pkg/RSiena/tests pkg/RSienaTest pkg/RSienaTest/R pkg/RSienaTest/man pkg/RSienaTest/tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 13 22:55:45 CEST 2016
Author: gvegayon
Date: 2016-10-13 22:55:45 +0200 (Thu, 13 Oct 2016)
New Revision: 303
Modified:
/
pkg/RSiena/ChangeLog
pkg/RSiena/DESCRIPTION
pkg/RSiena/R/robmon.r
pkg/RSiena/R/siena07.r
pkg/RSiena/man/RSiena-package.Rd
pkg/RSiena/man/siena07.Rd
pkg/RSiena/tests/parallel.R
pkg/RSienaTest/ChangeLog
pkg/RSienaTest/DESCRIPTION
pkg/RSienaTest/R/robmon.r
pkg/RSienaTest/R/siena07.r
pkg/RSienaTest/man/RSiena-package.Rd
pkg/RSienaTest/man/siena07.Rd
pkg/RSienaTest/tests/parallel.R
Log:
siena07 now allows passing a cluster via -cl-, so users won't depend on the function to create a cluster, providing flexibility.
Property changes on:
___________________________________________________________________
Added: svn:ignore
+ .Rproj.user
.Rhistory
.RData
.Ruserdata
Modified: pkg/RSiena/ChangeLog
===================================================================
--- pkg/RSiena/ChangeLog 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/ChangeLog 2016-10-13 20:55:45 UTC (rev 303)
@@ -1,3 +1,12 @@
+2016-10-13 R-Forge Revision 303
+Changes in RSiena and RSienaTest (George Vega Yon):
+ * R/robmon.r: New argument -cl- allows users passing their own cluster,
+ creating a new cluster only if length(cl) == 0.
+ * R/siena07.r: Same as in robmon. Now, if the user passes -cl-, the cluster
+ is closed only if length(cl) == 0.
+ * man/siena07.Rd: Including the new -cl- option in the manual.
+ * tests/parallel.R: Adding new test using the new -cl- option.
+
2016-10-10 R-Forge Revision 302
Changes in RSiena and RSienaTest:
* Capitalization error corrected in CovariateDegreeFunction.cpp.
Modified: pkg/RSiena/DESCRIPTION
===================================================================
--- pkg/RSiena/DESCRIPTION 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/DESCRIPTION 2016-10-13 20:55:45 UTC (rev 303)
@@ -1,8 +1,8 @@
Package: RSiena
Type: Package
Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.1-302
-Date: 2016-10-10
+Version: 1.1-303
+Date: 2016-10-13
Author: Ruth Ripley, Krists Boitmanis, Tom A.B. Snijders, Felix Schoenenberger
Depends: R (>= 2.15.0), utils
Imports: Matrix, tcltk, lattice, parallel, MASS, methods
Modified: pkg/RSiena/R/robmon.r
===================================================================
--- pkg/RSiena/R/robmon.r 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/R/robmon.r 2016-10-13 20:55:45 UTC (rev 303)
@@ -13,7 +13,7 @@
## returns updated z
##@robmon siena07 Controls MOM process
robmon <- function(z, x, useCluster, nbrNodes, initC, clusterString,
- clusterIter, clusterType, ...)
+ clusterIter, clusterType, cl, ...)
{
z$FinDiff.method<- x$FinDiff.method
z$n <- 0
@@ -69,17 +69,21 @@
{
stop("Not enough observations to use the nodes")
}
- unlink("cluster.out")
- if (clusterType == "FORK")
- {
- cl <- makeCluster(nbrNodes, type = clusterType,
- outfile = "cluster.out")
+
+ if (!length(cl)) {
+ unlink("cluster.out")
+ if (clusterType == "FORK")
+ {
+ cl <- makeCluster(nbrNodes, type = clusterType,
+ outfile = "cluster.out")
+ }
+ else
+ {
+ cl <- makeCluster(clusterString, type = clusterType,
+ outfile = "cluster.out")
+ }
}
- else
- {
- cl <- makeCluster(clusterString, type = clusterType,
- outfile = "cluster.out")
- }
+
clusterCall(cl, library, pkgname, character.only = TRUE)
##parLapply(cl, c('f1','f2'), sink)
z$oldRandomNumbers <- .Random.seed
Modified: pkg/RSiena/R/siena07.r
===================================================================
--- pkg/RSiena/R/siena07.r 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/R/siena07.r 2016-10-13 20:55:45 UTC (rev 303)
@@ -15,7 +15,7 @@
useCluster = FALSE, nbrNodes = 2, initC=TRUE,
clusterString=rep("localhost", nbrNodes), tt=NULL,
parallelTesting=FALSE, clusterIter=!x$maxlike,
- clusterType=c("PSOCK", "FORK"), ...)
+ clusterType=c("PSOCK", "FORK"), cl=NULL, ...)
{
exitfn <- function()
{
@@ -29,23 +29,36 @@
}
on.exit(exitfn())
-
+ # If the user is passing clusters through -cl- then change the
+ # useCluster to TRUE, and assign the -nbrNodes- to number of nodes
+ if (!useCluster & length(cl))
+ {
+ useCluster <- TRUE
+ nbrNodes <- length(cl)
+ }
+
+
time0 <- proc.time()['elapsed']
z <- NULL ## z is the object for all control information which may change.
## x is designed to be readonly. Only z is returned.
z$x <- x
- if (useCluster)
+ if (useCluster)
{
if (parallelTesting)
{
stop("cannot parallel test with multiple processes")
}
- clusterType <- match.arg(clusterType)
- if (.Platform$OS.type == "windows" && clusterType != "PSOCK")
- {
- stop("cannot use forking processes on Windows")
- }
+
+ if (!length(cl))
+ {
+ clusterType <- match.arg(clusterType)
+ if (.Platform$OS.type == "windows" && clusterType != "PSOCK")
+ {
+ stop("cannot use forking processes on Windows")
+ }
+ }
+
# The possibility to use snow now has been dropped
# because RSiena requires R >= 2.15.0
# and snow is superseded.
@@ -159,17 +172,20 @@
}
z <- robmon(z, x, useCluster, nbrNodes, initC, clusterString,
- clusterIter, clusterType, ...)
+ clusterIter, clusterType, cl, ...)
time1 <- proc.time()['elapsed']
Report(c("Total computation time", round(time1 - time0, digits=2),
"seconds.\n"), outf)
if (useCluster)
- {
+ {
+ # Only stop cluster if it wasn't provided by the user
+ if (!length(cl))
stopCluster(z$cl)
- ## need to reset the random number type to the normal one
- assign(".Random.seed", z$oldRandomNumbers, pos=1)
+
+ ## need to reset the random number type to the normal one
+ assign(".Random.seed", z$oldRandomNumbers, pos=1)
}
class(z) <- "sienaFit"
Modified: pkg/RSiena/man/RSiena-package.Rd
===================================================================
--- pkg/RSiena/man/RSiena-package.Rd 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/man/RSiena-package.Rd 2016-10-13 20:55:45 UTC (rev 303)
@@ -44,8 +44,8 @@
\tabular{ll}{
Package: \tab RSiena\cr
Type: \tab Package\cr
-Version: \tab 1.1-302\cr
-Date: \tab 2016-10-10\cr
+Version: \tab 1.1-303\cr
+Date: \tab 2016-10-13\cr
Depends: \tab R (>= 3.0.0)\cr
Imports: \tab Matrix\cr
Suggests: \tab tcltk, network, codetools, lattice, MASS, parallel,
@@ -76,7 +76,7 @@
The statistical evaluation of social network dynamics.
\emph{Sociological Methodology}, 31, 361-395.
\item Snijders, Tom A.B., van de Bunt, Gerhard G., and
- Steglich, Christian E.G. (2010).
+ Steglich, Christian E.G. (2010).
Introduction to actor-based models for network dynamics.
\emph{Social Networks}, 32, 44-60.
\item Snijders, Tom A.B., Steglich, Christian E.G., and Schweinberger,
Modified: pkg/RSiena/man/siena07.Rd
===================================================================
--- pkg/RSiena/man/siena07.Rd 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/man/siena07.Rd 2016-10-13 20:55:45 UTC (rev 303)
@@ -15,7 +15,7 @@
useCluster=FALSE, nbrNodes=2, initC=TRUE,
clusterString=rep("localhost", nbrNodes), tt=NULL,
parallelTesting=FALSE, clusterIter=!x$maxlike,
- clusterType=c("PSOCK", "FORK"), ...)
+ clusterType=c("PSOCK", "FORK"), cl=NULL, ...)
}
\arguments{
\item{x}{A control object, of class \code{\link{sienaAlgorithm} }}
@@ -45,6 +45,7 @@
"PSOCK". On a single non-Windows machine may be "FORK", and
subprocesses will be formed by forking. If "PSOCK", subprocesses are
formed using \R scripts.}
+ \item{cl}{An object of class c("SOCKcluster", "cluster").}
\item{\dots}{Arguments for the simulation function, see
\code{\link{simstats0c}}:
usually, \code{data} and \code{effects}, as in the examples below;\cr
Modified: pkg/RSiena/tests/parallel.R
===================================================================
--- pkg/RSiena/tests/parallel.R 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSiena/tests/parallel.R 2016-10-13 20:55:45 UTC (rev 303)
@@ -94,3 +94,27 @@
ans
tt <- sienaTimeTest(ans)
tt
+
+##test13
+print('test13')
+library(parallel)
+cl <- makeForkCluster(2)
+system.time({
+ans <- siena07(sienaModelCreate(n3=50, nsub=2,seed=1, projname="test13a"),
+ data=mydata, effects=myeff, batch=TRUE, silent=TRUE, cl = cl)
+})
+
+ans
+
+system.time({
+ans <- siena07(sienaModelCreate(n3=50, nsub=2,seed=1, projname="test13b"),
+ data=mydata, effects=myeff, batch=TRUE, silent=TRUE,
+ useCluster = TRUE, nbrNodes = 2, clusterType = "FORK")
+})
+ans
+
+
+tt <- sienaTimeTest(ans)
+tt
+
+stopCluster(cl)
Modified: pkg/RSienaTest/ChangeLog
===================================================================
--- pkg/RSienaTest/ChangeLog 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/ChangeLog 2016-10-13 20:55:45 UTC (rev 303)
@@ -1,3 +1,12 @@
+2016-10-13 R-Forge Revision 303
+Changes in RSiena and RSienaTest (George Vega Yon):
+ * R/robmon.r: New argument -cl- allows users passing their own cluster,
+ creating a new cluster only if length(cl) == 0.
+ * R/siena07.r: Same as in robmon. Now, if the user passes -cl-, the cluster
+ is closed only if length(cl) == 0.
+ * man/siena07.Rd: Including the new -cl- option in the manual.
+ * tests/parallel.R: Adding new test using the new -cl- option.
+
2016-10-10 R-Forge Revision 302
Changes in RSiena and RSienaTest:
* Capitalization error corrected in CovariateDegreeFunction.cpp.
Modified: pkg/RSienaTest/DESCRIPTION
===================================================================
--- pkg/RSienaTest/DESCRIPTION 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/DESCRIPTION 2016-10-13 20:55:45 UTC (rev 303)
@@ -1,8 +1,8 @@
Package: RSienaTest
Type: Package
Title: Siena - Simulation Investigation for Empirical Network Analysis
-Version: 1.1-302
-Date: 2016-10-10
+Version: 1.1-303
+Date: 2016-10-13
Author: Ruth Ripley, Krists Boitmanis, Tom A.B. Snijders, Felix Schoenenberger
Depends: R (>= 2.15.0), utils
Imports: Matrix, tcltk, lattice, parallel, MASS, RUnit, methods
Modified: pkg/RSienaTest/R/robmon.r
===================================================================
--- pkg/RSienaTest/R/robmon.r 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/R/robmon.r 2016-10-13 20:55:45 UTC (rev 303)
@@ -13,7 +13,7 @@
## returns updated z
##@robmon siena07 Controls MOM process
robmon <- function(z, x, useCluster, nbrNodes, initC, clusterString,
- clusterIter, clusterType, ...)
+ clusterIter, clusterType, cl, ...)
{
z$FinDiff.method<- x$FinDiff.method
z$n <- 0
@@ -69,17 +69,19 @@
{
stop("Not enough observations to use the nodes")
}
- unlink("cluster.out")
- if (clusterType == "FORK")
- {
- cl <- makeCluster(nbrNodes, type = clusterType,
- outfile = "cluster.out")
+ if (!length(cl)) {
+ unlink("cluster.out")
+ if (clusterType == "FORK")
+ {
+ cl <- makeCluster(nbrNodes, type = clusterType,
+ outfile = "cluster.out")
+ }
+ else
+ {
+ cl <- makeCluster(clusterString, type = clusterType,
+ outfile = "cluster.out")
+ }
}
- else
- {
- cl <- makeCluster(clusterString, type = clusterType,
- outfile = "cluster.out")
- }
clusterCall(cl, library, pkgname, character.only = TRUE)
##parLapply(cl, c('f1','f2'), sink)
z$oldRandomNumbers <- .Random.seed
Modified: pkg/RSienaTest/R/siena07.r
===================================================================
--- pkg/RSienaTest/R/siena07.r 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/R/siena07.r 2016-10-13 20:55:45 UTC (rev 303)
@@ -17,7 +17,7 @@
parallelTesting=FALSE, clusterIter=!x$maxlike,
clusterType=c("PSOCK", "FORK"),
logLevelConsole='WARNING', logLevelFile='INFO',
- logIncludeLocation=F, ...)
+ logIncludeLocation=F, cl=NULL,...)
{
sienaSetupLogger(logLevelConsole=logLevelConsole,
logLevelFile=logLevelFile,
@@ -35,6 +35,15 @@
RNGkind("default")
}
on.exit(exitfn())
+
+ # If the user is passing clusters through -cl- then change the
+ # useCluster to TRUE, and assign the -nbrNodes- to number of nodes
+ if (!useCluster & length(cl))
+ {
+ useCluster <- TRUE
+ nbrNodes <- length(cl)
+ }
+
time0 <- proc.time()['elapsed']
z <- NULL ## z is the object for all control information which may change.
## x is designed to be readonly. Only z is returned.
@@ -46,11 +55,15 @@
{
stop("cannot parallel test with multiple processes")
}
- clusterType <- match.arg(clusterType)
- if (.Platform$OS.type == "windows" && clusterType != "PSOCK")
- {
- stop("cannot use forking processes on Windows")
- }
+
+ if (!length(cl))
+ {
+ clusterType <- match.arg(clusterType)
+ if (.Platform$OS.type == "windows" && clusterType != "PSOCK")
+ {
+ stop("cannot use forking processes on Windows")
+ }
+ }
# The possibility to use snow now has been dropped
# because RSiena requires R >= 2.15.0
# and snow is superseded.
@@ -163,7 +176,7 @@
}
z <- robmon(z, x, useCluster, nbrNodes, initC, clusterString,
- clusterIter, clusterType, ...)
+ clusterIter, clusterType, cl, ...)
time1 <- proc.time()['elapsed']
Report(c("Total computation time", round(time1 - time0, digits=2),
@@ -171,7 +184,10 @@
if (useCluster)
{
- stopCluster(z$cl)
+ # Only stop cluster if it wasn't provided by the user
+ if (!length(cl))
+ stopCluster(z$cl)
+
## need to reset the random number type to the normal one
assign(".Random.seed", z$oldRandomNumbers, pos=1)
}
Modified: pkg/RSienaTest/man/RSiena-package.Rd
===================================================================
--- pkg/RSienaTest/man/RSiena-package.Rd 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/man/RSiena-package.Rd 2016-10-13 20:55:45 UTC (rev 303)
@@ -46,8 +46,8 @@
\tabular{ll}{
Package: \tab RSienaTest\cr
Type: \tab Package\cr
-Version: \tab 1.1-301\cr
-Date: \tab 2016-10-09\cr
+Version: \tab 1.1-303\cr
+Date: \tab 2016-10-13\cr
Depends: \tab R (>= 3.0.0)\cr
Imports: \tab Matrix\cr
Suggests: \tab tcltk, network, codetools, lattice, MASS, parallel,
Modified: pkg/RSienaTest/man/siena07.Rd
===================================================================
--- pkg/RSienaTest/man/siena07.Rd 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/man/siena07.Rd 2016-10-13 20:55:45 UTC (rev 303)
@@ -17,7 +17,7 @@
parallelTesting=FALSE, clusterIter=!x$maxlike,
clusterType=c("PSOCK", "FORK"),
logLevelConsole='WARNING', logLevelFile='INFO',
- logIncludeLocation=F, ...)
+ logIncludeLocation=F, cl=NULL, ...)
}
\arguments{
\item{x}{A control object, of class \code{\link{sienaAlgorithm} }}
@@ -56,6 +56,7 @@
\item{logIncludeLocation}{
When \code{TRUE} also log the code location (file, method, line) where the
logging message originated.}
+ \item{cl}{An object of class c("SOCKcluster", "cluster").}
\item{\dots}{Arguments for the simulation function, see
\code{\link{simstats0c}}:
usually, \code{data} and \code{effects}, as in the examples below;\cr
Modified: pkg/RSienaTest/tests/parallel.R
===================================================================
--- pkg/RSienaTest/tests/parallel.R 2016-10-10 16:17:10 UTC (rev 302)
+++ pkg/RSienaTest/tests/parallel.R 2016-10-13 20:55:45 UTC (rev 303)
@@ -105,3 +105,27 @@
eff <- includeEffects(eff, recip)
(eff <- includeEffects(eff, recip, realrecip, persistrecip, type='gmm'))
(ans <- sienacpp(algo, data=dataset, effects=eff))
+
+##test14
+print('test14')
+library(parallel)
+cl <- makeForkCluster(2)
+system.time({
+ ans <- siena07(sienaModelCreate(n3=50, nsub=2,seed=1, projname="test14a"),
+ data=mydata, effects=myeff, batch=TRUE, silent=TRUE, cl = cl)
+})
+
+ans
+
+system.time({
+ ans <- siena07(sienaModelCreate(n3=50, nsub=2,seed=1, projname="test14b"),
+ data=mydata, effects=myeff, batch=TRUE, silent=TRUE,
+ useCluster = TRUE, nbrNodes = 2, clusterType = "FORK")
+})
+ans
+
+
+tt <- sienaTimeTest(ans)
+tt
+
+stopCluster(cl)
More information about the Rsiena-commits
mailing list