Description Usage Details Value See Also Examples
Functions that assign values and functions needed by MSS.snow
1 2 3 4 |
Please see MSS.snow
and examples.
Nothing. The central role of these functions is the creation of four functions required by MSS.snow
: FUN.MH
, FUN.GP
, FUN.I
, and FUN.EXIT
. These four functions are assigned to the Global Environment. This fun.load
suite of functions also passes needed objects (out-of-scope) to snowfall
threads if the global user-made variable run.parallel
is set to TRUE
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | ### Here's an itty bitty example:
### we use stochastic search to find the minimum number in a vector
### GP isn't used here, and hence neither are p.ndx.ls nor f.d
### however, we still need to create them since MSS.snow requires their existence
## Not run:
fun.load.simpleExample <- function() {
if( run.parallel ) {
sfExport("xx")
}
p.ndx.ls <- list( c(1) )
p.ndx.ls <<- p.ndx.ls
f.d <- list( dlog.norm )
f.d <<- f.d
FUN.MH <- function(jj, GP.mx, X) {
our.cost <- sample(xx, 1)
}
FUN.MH <<- FUN.MH
FUN.GP <- NULL
FUN.GP <<- FUN.GP
FUN.I <- function(envmh, X) {
cat( "Hello, I have found an even smaller number in xx ---> ", envmh$current.best, "\n" )
}
FUN.I <<- FUN.I
FUN.EXIT <- function(envmh, X) {
cat( "Done", "\n" )
}
FUN.EXIT <<- FUN.EXIT
}
xx <- 1:600
GP <- c(1)
run.parallel <- TRUE
sfInit(TRUE, 2)
MH.source <- fun.load.simpleExample
MH.source()
MSS.snow(MH.source, Inf, p.ndx.ls, f.d, matrix(1, nrow=28), 28, 7)
sfStop()
### Here's another itty bitty example:
### we use stochastic search to find the mean of a vector
### i.e., the argmin? of sum ( x - ? )^2
fun.load.simpleExample2 <- function() {
if( run.parallel ) {
sfExport("xx")
}
p.ndx.ls <- list( c(1) )
p.ndx.ls <<- p.ndx.ls
f.d <- list( unif.mh )
f.d <<- f.d
FUN.MH <- function(jj, GP.mx, X) {
our.cost <- sum( ( xx - GP.mx[jj, 1] )^2 )
return(our.cost)
}
FUN.MH <<- FUN.MH
FUN.GP <- NULL
FUN.GP <<- FUN.GP
FUN.I <- function(envmh, X) {
cat( "Improvement ---> ", envmh$current.best, " ---- " , envmh$GP, "\n" )
}
FUN.I <<- FUN.I
FUN.EXIT <- function(envmh, X) {
our.cost <- envmh$current.best
GP <- envmh$GP
cat( "Done", "\n" )
cat( envmh$GP, our.cost, "\n" )
}
FUN.EXIT <<- FUN.EXIT
}
##set.seed(99999)
xx <- rnorm(300, 5, 10)
GP <- c(1)
run.parallel <- TRUE
sfInit(TRUE, 2)
MH.source <- fun.load.simpleExample2
MH.source()
MSS.snow(MH.source, Inf, p.ndx.ls, f.d, matrix(1/10, nrow=140, ncol=length(GP)), 140, 14)
sfStop()
##### in fact:
mean(xx)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.