Skip to content

Commit

Permalink
format fignettes etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-r committed Jun 21, 2018
1 parent a6e7f9a commit 5e35860
Show file tree
Hide file tree
Showing 18 changed files with 440 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ Suggests:
testthat,
roxygen2,
plyr
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
VignetteBuilder: knitr
62 changes: 31 additions & 31 deletions inst/doc/tree_structured_paramsets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ We implemented ParamSetTree as an alternative to ParamSetFlat to accomodate diff
Each separate hyper-parameter has a unique identifier called "id" which is defined inside
the ParamSimple(ParamCategorical, ParamReal, ..etc). These "id"s are extracted from ParamSimple and used as the unique identifier as the node in the tree as well.

If a hyper-parameter has a dependency, "gamma" for example, we write its dependency in the form of ```depend = list(id = "kernel", val = "rbf")``` which means that "gamma" only makes sense if the "kernel" hyper-parameter takes the value of "rbf".
If a hyper-parameter has a dependency, "gamma" for example, we write its dependency in the form of `depend = list(id = "kernel", val = "rbf")` which means that "gamma" only makes sense if the "kernel" hyper-parameter takes the value of "rbf".

In future versions of this package, firstly we might eliminate the unique id limitation since two identical leave node ids could be differenciated by the two different paths of the tree which lead to this two leave nodes. Secondly, we will have a more general dependency representation like in the ParamSetFlat. For example, if the parent node takes a range of values which could also activiate the child node, but not only an equal relation.

The user could define the following tree based hyper-parameter set, where `ParamTreeDn` means define Node and `ParamTreeFac` defines the ParamSetTree.

```{r example1}
library(phng)
pst = ParamTreeFac(
ParamCategorical$new(id = "model", values = c("SVM", "RF")),
makeCondTreeNode(ParamReal$new(id = "C", lower = 0, upper = 100), depend = list(id = "model", val = "SVM")),
makeCondTreeNode(ParamCategorical$new(id = "kernel", values = c("rbf", "poly")), depend = list(id = "model", val = "SVM")),
makeCondTreeNode(ParamReal$new(id = "gamma", lower = 0, upper = 100), depend = list(id = "kernel", val = "rbf")),
makeCondTreeNode(ParamInt$new(id = "n", lower = 1L, upper = 10L), depend = list(id = "kernel", val = "poly"))
)
pst$sample()
pst$toStringVal()
```{r example1}
library(phng)
pst = ParamTreeFac(
ParamCategorical$new(id = "model", values = c("SVM", "RF")),
makeCondTreeNode(ParamReal$new(id = "C", lower = 0, upper = 100), depend = list(id = "model", val = "SVM")),
makeCondTreeNode(ParamCategorical$new(id = "kernel", values = c("rbf", "poly")), depend = list(id = "model", val = "SVM")),
makeCondTreeNode(ParamReal$new(id = "gamma", lower = 0, upper = 100), depend = list(id = "kernel", val = "rbf")),
makeCondTreeNode(ParamInt$new(id = "n", lower = 1L, upper = 10L), depend = list(id = "kernel", val = "poly"))
)
pst$sample()
pst$toStringVal()
```
## Advanced features
We also provide the user with a "Functional API" which means the user could program at runtime a dynamic structure of the tree.
Expand All @@ -54,24 +54,24 @@ Here we introduce the concept of mandatory child node and conditional child node
Secondly, we introduce the concept of ParamHandle, which takes argument of `node` and `depend`. It is basically representing a node in the tree structure which contains pointers to its mandatory child nodes and conditional child nodes.

```{r example2}
ps = ParamHandle$new(node = ParamCategorical$new(id = "Model", values = c("SVM", "RF")))
ps$setRoot(ps) # set the current node to be the root node
temp_ntree = ParamHandle$new(node = ParamInt$new(id = "n_tree", lower = 1L, upper = 10L), depend = list(id = "Model", val = "RF"))
ntree = ps$addCondChild(temp_ntree) # the condition is contained in temp_ntree§depend already
temp = ParamHandle$new(node = ParamReal$new(id = "C", lower = 0, upper = 100), depend = list(id = "Model", val = "SVM"))
c = ps$addCondChild(temp)
temp = ParamHandle$new(node = ParamCategorical$new(id = "kernel", values = c("rbf", "poly")), depend = list(id = "Model", val = "SVM"))
kernel = ps$addCondChild(temp)
temp = ParamHandle$new(node = ParamReal$new(id = "gamma", lower = 0, upper = 100), depend = list(id = "kernel", val = "rbf"))
gamma = kernel$addCondChild(temp)
temp = ParamHandle$new(node = ParamInt$new(id = "n", lower = 1L, upper = 10L), depend = list(id = "kernel", val = "poly"))
poly = kernel$addCondChild(temp)
list.flat = ps$visitor$toFlat()
ps$toStringVal()
ps$sample()
ps$toStringVal() # after sampling, the string might be different
list.flat = ps$visitor$toFlat()
poly$getRoot$sample() # use the root to sample
ps$toStringVal()
ps = ParamHandle$new(node = ParamCategorical$new(id = "Model", values = c("SVM", "RF")))
ps$setRoot(ps) # set the current node to be the root node
temp_ntree = ParamHandle$new(node = ParamInt$new(id = "n_tree", lower = 1L, upper = 10L), depend = list(id = "Model", val = "RF"))
ntree = ps$addCondChild(temp_ntree) # the condition is contained in temp_ntree§depend already
temp = ParamHandle$new(node = ParamReal$new(id = "C", lower = 0, upper = 100), depend = list(id = "Model", val = "SVM"))
c = ps$addCondChild(temp)
temp = ParamHandle$new(node = ParamCategorical$new(id = "kernel", values = c("rbf", "poly")), depend = list(id = "Model", val = "SVM"))
kernel = ps$addCondChild(temp)
temp = ParamHandle$new(node = ParamReal$new(id = "gamma", lower = 0, upper = 100), depend = list(id = "kernel", val = "rbf"))
gamma = kernel$addCondChild(temp)
temp = ParamHandle$new(node = ParamInt$new(id = "n", lower = 1L, upper = 10L), depend = list(id = "kernel", val = "poly"))
poly = kernel$addCondChild(temp)
list.flat = ps$visitor$toFlat()
ps$toStringVal()
ps$sample()
ps$toStringVal() # after sampling, the string might be different
list.flat = ps$visitor$toFlat()
poly$getRoot$sample() # use the root to sample
ps$toStringVal()
```

2 changes: 1 addition & 1 deletion man/OptPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/ParamBase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion man/ParamCategorical.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion man/ParamFlag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/ParamHandle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion man/ParamInt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ParamNode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5e35860

Please sign in to comment.