Skip to content

MindFoundry/optaas-r-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mind Foundry OPTaaS R Client

GitHub Release License: MIT tutorials-binder

OPTaaS (Optimization as a Service) is a general-purpose Bayesian optimizer developed by Mind Foundry which provides optimal hyper-parameter configurations via web-services. It can handle any parameter type and does not need to know the underlying process, models, or data.

This R client makes it easier to interact with the web service and integrate with your R code.

Installation

# install.packages("devtools")
devtools::install_github("MindFoundry/optaas-r-client")
library(optaas.client)

Usage

Connect to your OPTaaS server:

client <- OPTaaSClient$new("Your OPTaaS URL", "Your OPTaaS API Key")

Define your parameters:

parameters <- list(
    BoolParameter('my_bool'),
    CategoricalParameter('my_cat', values=list('a', 'b', 'c'), default='c'),
    ChoiceParameter('ints_or_floats', choices=list(
        GroupParameter('ints', items=list(
            IntParameter('my_int', minimum=0, maximum=20), 
            IntParameter('my_optional_int', minimum=-10, maximum=10, optional=TRUE)
        )),
        GroupParameter('floats', items=list(
            FloatParameter('float1', minimum=0, maximum=1),
            FloatParameter('float2', minimum=0.5, maximum=4.5)
        ))
    ))
)

Define your scoring function:

scoring_function <- function(my_bool, my_cat, ints_or_floats) {
    score <- if (isTRUE(my_bool)) 5 else -5
    score <- if (my_cat == 'a') score + 1 else score + 3
    if (!is.null(ints_or_floats$ints)) {
        score <- score + do.call(sum, ints_or_floats$ints)
    } else {
        score <- score * do.call(sum, ints_or_floats$floats)
    }
    score
}

Create your task:

task <- client$create_task(
    title="Dummy task",
    parameters=parameters,
    goal="min",  # optional (default is "max")
    min_known_score=-22, max_known_score=44  # optional
)

Run your task:

best_result <- task$run(scoring_function=scoring_function, number_of_iterations=20)

See also our tutorial notebooks.

Development

RStudio is recommended.

Each class/function should be documented using roxygen comments. Use Ctrl+Shift+D in RStudio to generate the Rd files.

To run tests: set env vars OPTAAS_URL and OPTAAS_API_KEY accordingly, then Ctrl+Shift+T.

To run all checks (including tests): Ctrl+Shift+E.

Deployment

For each production release, set the version in the DESCRIPTION file to match the version of the OPTaaS server and Python client. Then create a new GitHub Release with the same version.