Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions docs/javascripts/selectortabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// set default strategy
let problemDescription = new Map([
["objective", "single-objective"],
["tasks", "single-task"],
["domain", "simple-domain"],
])

const strategyMap = new Map([
["single-objective__single-task__simple-domain", ["SoboStrategy", ""]],
["single-objective__single-task__many-categorical-features", ["EntingStrategy", ""]],
["single-objective__multi-task__simple-domain", ["SoboStrategy", "MultiTaskGPSurrogate"]],
["single-objective__multi-fidelity__simple-domain", ["MultiFidelity", ""]],

["multi-objective__single-task__simple-domain", ["MoboStrategy", ""]],
])

const getSurrogateCode = (surrogateDataModel) => {
if (surrogateDataModel === "") {
return ""
}
return `
# define the surrogate data model
surrogate_data_model = BotorchSurrogates(surrogates=[
${surrogateDataModel}(
inputs=domain.inputs,
outputs=domain.outputs,
)
])
`}

const getStrategyComment = (strategyDataModel) => {
return (strategyDataModel !== "EntingStrategy") ? "" : `
# the default GP surrogate is slow to optimize when many discrete features are present
# the ENTMOOT model can optimize over domains with many categories`
}

const getStrategyCode = () => {
const dataModels = strategyMap.get([...problemDescription.values()].join("__"))
if (dataModels === undefined) {
return hljs.highlight("# There isn't currently a BoFire model that works for this problem.", {language: "python"})
}

const [strategyDataModel, surrogateDataModel] = dataModels
const requiresSurrogate = (surrogateDataModel !== "")
const surrogateImport = (!requiresSurrogate) ? "" : `
from bofire.data_models.surrogates.api import ${surrogateDataModel}`

const strategyComment = getStrategyComment(strategyDataModel)
const surrogateCode = getSurrogateCode(surrogateDataModel)

return hljs.highlight(
`from bofire.data_models.strategies.api import ${strategyDataModel} ${surrogateImport}
import bofire.strategies.api as strategies
${surrogateCode}
# define the strategy data model ${strategyComment}
strategy_data_model = ${strategyDataModel}(
domain=domain${!requiresSurrogate ? "" : `
surrogate=surrogate_data_model`}
)

# create an instance of the functional strategy
# to understand the difference between data models and functional components,
# see https://experimental-design.github.io/bofire/data_models_functionals/
strategy = strategies.map(strategy_data_model)
`, { language : "python"}
)
}

const updateStrategyCodeBlock = () => {
const codeBlock = document.getElementById("stategyTemplate")
codeBlock.innerHTML = getStrategyCode().value
}

const tabSync = () => {
const tabs = document.querySelectorAll(".tabbed-set > input")
for (const tab of tabs) {
tab.addEventListener("click", () => {
const current = document.querySelector(`label[for=${tab.id}]`)
const pos = current.getBoundingClientRect().top
// const labels = document.querySelectorAll('.tabbed-set > label, .tabbed-alternate > .tabbed-labels > label')

const updatedGroup = tab.parentElement.id
// const updatedGroup = selectorTabStrategies[tab.id]
problemDescription.set(updatedGroup, tab.id)
updateStrategyCodeBlock()

// Preserve scroll position
const delta = (current.getBoundingClientRect().top) - pos
window.scrollBy(0, delta)
})
}
}

document$.subscribe(function() {
["objective", "tasks", "domain"].forEach(k => {
document.querySelector(`#${k}-marker`).nextElementSibling.setAttribute("id", k)
})
tabSync()
updateStrategyCodeBlock()
})
33 changes: 33 additions & 0 deletions docs/userguide_strategies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Strategies

<!--
https://github.com/sgbaird/honegumi
https://github.com/facebook/Ax/issues/1479
-->

In BoFire, a `Strategy` provides an interface for proposing new experiments.
Below, we provide a tool for suggesting the most appropriate strategy for your
Bayesian optimization problem. Our tool is inspired by [honegumi](https://github.com/sgbaird/honegumi).

<div class="tab-marker" id="objective-marker"> </div>

=== "Single Objective"

=== "Multi Objective"

<div class="tab-marker" id="tasks-marker"> </div>

===! "Single Task"

=== "Multi Task"

=== "Multi Fidelity"

<div class="tab-marker" id="domain-marker"> </div>

===! "Simple Domain"

=== "Many categorical features"


<pre><code id="stategyTemplate"> </ code><pre>
9 changes: 9 additions & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- Notebook page: getting_started.ipynb
- Examples: examples.md
- Data Models vs Functional Components: data_models_functionals.md
- Strategies: userguide_strategies.md
- Surrogate Models: userguide_surrogates.md
- API Reference:
- Domain: ref-domain.md
Expand Down Expand Up @@ -60,10 +61,18 @@ markdown_extensions:
- pymdownx.details
- pymdownx.highlight
- pymdownx.inlinehilite
- pymdownx.tabbed:
alternate_style: true
slugify: !!python/object/apply:pymdownx.slugs.slugify {kwds: {case: lower}}
- admonition

extra_css:
- https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.11.1/build/styles/default.min.css

extra_javascript:
- https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@latest/build/highlight.min.js
- javascripts/mathjax.js
- javascripts/selectortabs.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

extra:
Expand Down