Last data update: 2014.03.03

R: Group experiments.
getIndexR Documentation

Group experiments.

Description

Creates a list of factor to use in functions like tapply, by or aggregate.

Usage

getIndex(reg, ids, by.prob = FALSE, by.algo = FALSE, by.repl = FALSE,
  by.prob.pars, by.algo.pars, enclos = parent.frame())

Arguments

reg

[ExperimentRegistry]
Registry.

ids

[integer]
If not missing, restict grouping to this subset of experiment ids.

by.prob

[logical]
Group experiments by problem. Default is FALSE.

by.algo

[logical]
Group experiments by algorithm. Default is FALSE.

by.repl

[logical]
Group experiments by replication. Default is FALSE.

by.prob.pars

[R expression]
If not missing, group experiments by this R expression. The expression is evaluated in the environment of problem parameters and converted to a factor using as.factor.

by.algo.pars

[R expression]
If not missing, group experiments by this R expression. The expression is evaluated in the environment of algorithm parameters and converted to a factor using as.factor.

enclos

[environment]
Enclosing frame for evaluation of parameters used by by.prob.pars and by.algo.pars, see eval. Defaults to the parent frame.

Value

[list]. List of factors.

Examples

# create a registry and add problems and algorithms
reg = makeExperimentRegistry("getIndex", file.dir = tempfile(""))
addProblem(reg, "prob", static = 1)
addAlgorithm(reg, "f0", function(static, dynamic) static)
addAlgorithm(reg, "f1", function(static, dynamic, i, k) static * i^k)
ad = list(makeDesign("f0"), makeDesign("f1", exhaustive = list(i = 1:5, k = 1:3)))
addExperiments(reg, algo.designs = ad)
submitJobs(reg)

# get grouped job ids
ids = getJobIds(reg)
by(ids, getIndex(reg, by.prob = TRUE, by.algo = TRUE), identity)
ids = findExperiments(reg, algo.pattern = "f1")
by(ids, getIndex(reg, ids, by.algo.pars = (k == 1)), identity)

# groupwise reduction
ids = findExperiments(reg, algo.pattern = "f1")
showStatus(reg, ids)
f = function(aggr, job, res) aggr + res
by(ids, getIndex(reg, ids, by.algo.pars = k), reduceResults, reg = reg, fun = f)
by(ids, getIndex(reg, ids, by.algo.pars = i), reduceResults, reg = reg, fun = f)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BatchExperiments)
Loading required package: BatchJobs
Loading required package: BBmisc
Sourcing configuration file: '/home/ddbj/local/lib64/R/library/BatchJobs/etc/BatchJobs_global_config.R'
BatchJobs configuration:
  cluster functions: Interactive
  mail.from: 
  mail.to: 
  mail.start: none
  mail.done: none
  mail.error: none
  default.resources: 
  debug: FALSE
  raise.warnings: FALSE
  staged.queries: TRUE
  max.concurrent.jobs: Inf
  fs.timeout: NA

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BatchExperiments/getIndex.Rd_%03d_medium.png", width=480, height=480)
> ### Name: getIndex
> ### Title: Group experiments.
> ### Aliases: getIndex
> 
> ### ** Examples
> 
> # create a registry and add problems and algorithms
> reg = makeExperimentRegistry("getIndex", file.dir = tempfile(""))
Creating dir: /tmp/RtmpPyQ6wk/39c83588a0bb
Saving registry: /tmp/RtmpPyQ6wk/39c83588a0bb/registry.RData
> addProblem(reg, "prob", static = 1)
Writing problem files: /tmp/RtmpPyQ6wk/39c83588a0bb/problems/prob_static.RData, /tmp/RtmpPyQ6wk/39c83588a0bb/problems/prob_dynamic.RData
> addAlgorithm(reg, "f0", function(static, dynamic) static)
Writing algorithm file: /tmp/RtmpPyQ6wk/39c83588a0bb/algorithms/f0.RData
> addAlgorithm(reg, "f1", function(static, dynamic, i, k) static * i^k)
Writing algorithm file: /tmp/RtmpPyQ6wk/39c83588a0bb/algorithms/f1.RData
> ad = list(makeDesign("f0"), makeDesign("f1", exhaustive = list(i = 1:5, k = 1:3)))
> addExperiments(reg, algo.designs = ad)
Adding 16 experiments / 16 jobs to DB.
> submitJobs(reg)
Saving conf: /tmp/RtmpPyQ6wk/39c83588a0bb/conf.RData
Submitting 16 chunks / 16 jobs.
Cluster functions: Interactive.
Auto-mailer settings: start=none, done=none, error=none.
Writing 16 R scripts...
 SubmitJobs |+                                                |   0% (00:00:00) SubmitJobs |+                                                |   0% (00:00:00) SubmitJobs |+++                                              |   6% (00:00:00) SubmitJobs |++++++                                           |  12% (00:00:00) SubmitJobs |+++++++++                                        |  19% (00:00:04) SubmitJobs |++++++++++++                                     |  25% (00:00:03) SubmitJobs |+++++++++++++++                                  |  31% (00:00:02) SubmitJobs |++++++++++++++++++                               |  38% (00:00:01) SubmitJobs |+++++++++++++++++++++                            |  44% (00:00:01) SubmitJobs |++++++++++++++++++++++++                         |  50% (00:00:01) SubmitJobs |++++++++++++++++++++++++++++                     |  56% (00:00:00) SubmitJobs |+++++++++++++++++++++++++++++++                  |  62% (00:00:01) SubmitJobs |++++++++++++++++++++++++++++++++++               |  69% (00:00:00) SubmitJobs |+++++++++++++++++++++++++++++++++++++            |  75% (00:00:00) SubmitJobs |++++++++++++++++++++++++++++++++++++++++         |  81% (00:00:00) SubmitJobs |+++++++++++++++++++++++++++++++++++++++++++      |  88% (00:00:00) SubmitJobs |++++++++++++++++++++++++++++++++++++++++++++++   |  94% (00:00:00) SubmitJobs |+++++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Sending 16 submit messages...
Might take some time, do not interrupt this!
> 
> # get grouped job ids
> ids = getJobIds(reg)
> by(ids, getIndex(reg, by.prob = TRUE, by.algo = TRUE), identity)
prob: prob
algo: f0
[1] 1
------------------------------------------------------------ 
prob: prob
algo: f1
 [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
> ids = findExperiments(reg, algo.pattern = "f1")
> by(ids, getIndex(reg, ids, by.algo.pars = (k == 1)), identity)
algo.pars: (k == 1): FALSE
 [1]  7  8  9 10 11 12 13 14 15 16
------------------------------------------------------------ 
algo.pars: (k == 1): TRUE
[1] 2 3 4 5 6
> 
> # groupwise reduction
> ids = findExperiments(reg, algo.pattern = "f1")
> showStatus(reg, ids)
Syncing registry ...
Status for 15 jobs at 2016-07-04 15:12:50
Submitted: 15 (100.00%)
Started:   15 (100.00%)
Running:    0 (  0.00%)
Done:      15 (100.00%)
Errors:     0 (  0.00%)
Expired:    0 (  0.00%)
Time: min=0.00s avg=0.07s max=1.00s
> f = function(aggr, job, res) aggr + res
> by(ids, getIndex(reg, ids, by.algo.pars = k), reduceResults, reg = reg, fun = f)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++                                     |  20% (00:00:00) reduceResults |++++++++++++++++++                            |  40% (00:00:00) reduceResults |++++++++++++++++++++++++++++                  |  60% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++++++++         |  80% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++                                     |  20% (00:00:00) reduceResults |++++++++++++++++++                            |  40% (00:00:00) reduceResults |++++++++++++++++++++++++++++                  |  60% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++++++++         |  80% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++                                     |  20% (00:00:00) reduceResults |++++++++++++++++++                            |  40% (00:00:00) reduceResults |++++++++++++++++++++++++++++                  |  60% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++++++++         |  80% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
algo.pars: k: 1
[1] 15
------------------------------------------------------------ 
algo.pars: k: 2
[1] 55
------------------------------------------------------------ 
algo.pars: k: 3
[1] 225
> by(ids, getIndex(reg, ids, by.algo.pars = i), reduceResults, reg = reg, fun = f)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++++++++                               |  33% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++               |  67% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++++++++                               |  33% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++               |  67% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++++++++                               |  33% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++               |  67% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++++++++                               |  33% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++               |  67% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
Reducing 
 reduceResults |+                                             |   0% (00:00:00) reduceResults |+++++++++++++++                               |  33% (00:00:00) reduceResults |+++++++++++++++++++++++++++++++               |  67% (00:00:00) reduceResults |++++++++++++++++++++++++++++++++++++++++++++++| 100% (00:00:00)
algo.pars: i: 1
[1] 3
------------------------------------------------------------ 
algo.pars: i: 2
[1] 14
------------------------------------------------------------ 
algo.pars: i: 3
[1] 39
------------------------------------------------------------ 
algo.pars: i: 4
[1] 84
------------------------------------------------------------ 
algo.pars: i: 5
[1] 155
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>