The Strategy: Choosing the Ritual
Interchangeable algorithms for statistical forecasting.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Interchangeable Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// R PATTERN //
library(R6)
# Strategy Interface
ScryingStrategy <- R6Class("ScryingStrategy",
public = list(
predict = function(data) stop("Not implemented")
)
)
# Concrete Strategies
BayesianScry <- R6Class("BayesianScry", inherit = ScryingStrategy,
public = list(
predict = function(data) {
paste("Using Bayesian priors on", data)
}
)
)
FrequentistScry <- R6Class("FrequentistScry", inherit = ScryingStrategy,
public = list(
predict = function(data) {
paste("Using Frequentist limits on", data)
}
)
)
# Context
Haruspex <- R6Class("Haruspex",
private = list(
strategy = NULL
),
public = list(
set_strategy = function(strategy) {
private$strategy <- strategy
},
foresee = function(data) {
private$strategy$predict(data)
}
)
)
Depending on the nature of the data anomaly, the Haruspex can swap between Bayesian or Frequentist strategies at runtime.
Runic Tags:
#R6
#Divination
#Behavioral
#Strategy