| Title: | Relevance-Based Prediction for the 'RBP Math Engine' |
|---|---|
| Description: | Provides predict_psr(), predict_maxfit(), and predict_grid() for relevance-based prediction ('RBP') via the 'RBP Math Engine' C application binary interface ('ABI'). Returns a 'PredictionResults' nested list that mirrors the 'Python' 'rbp_engine' package. The package builds and installs without the private engine; prediction and insight entry points load the engine at runtime ('RBP_ENGINE_LIB' or a staged install under 'RBP_ENGINE_HOME' / /Library/rbp-engine). Licensing uses 'rbp-license-info' and standard license environment variables. |
| Authors: | Cambridge Sports Analytics [aut, cph], Cel Kulasekaran [cre] |
| Maintainer: | Cel Kulasekaran <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.4.0 |
| Built: | 2026-10-07 08:35:05 UTC |
| Source: | https://github.com/CambridgeSportsAnalytics/rbp-engine-r |
install_engine().Default prefix used by install_engine().
default_engine_home()default_engine_home()
A directory path.
default_engine_home()default_engine_home()
The open rbpengine package is a thin client. Predictions require the
private RBP Math Engine shared library (librbp_math_lib.dylib /
.so / rbp_math_lib.dll) plus platform companions (OpenBLAS/LAPACK where
needed) and a valid license.
engine_candidate_paths() engine_available() find_engine_path()engine_candidate_paths() engine_available() find_engine_path()
Discovery order (first path that loads and exposes the expected ABI symbols):
RBP_ENGINE_LIB (full path to the shared library)
RBP_ENGINE_HOME / lib/ (+ OS filename)
install_engine() prefix (default_engine_home())
Well-known install prefixes (/Library/rbp-engine/lib,
$HOME/.local/share/rbp-engine/lib, ...)
Developer cargo tree (RBP_MATH_LIB_ROOT, sibling rbp-math-lib/target,
or ../target when this package still sits next to a cargo workspace)
engine_available() returns a logical. engine_candidate_paths()
returns character paths that may be probed. find_engine_path() and
engine_load() return the loaded path (invisibly). engine_unload()
returns TRUE invisibly after releasing the loaded library.
ensure_engine() returns TRUE invisibly when the engine is available.
library_path(), abi_version(), install_engine()
engine_available() length(engine_candidate_paths()) >= 1engine_available() length(engine_candidate_paths()) >= 1
Load the engine shared library at an explicit path.
engine_load(path = NULL)engine_load(path = NULL)
path |
Full path to |
Invisibly, the path loaded.
Override with env RBP_ENGINE_RELEASES_URL (no trailing slash).
engine_releases_url()engine_releases_url()
Character scalar.
engine_releases_url()engine_releases_url()
manifest.json artifacts (macos-arm64, …).Platform id matching manifest.json artifacts (macos-arm64, …).
engine_runtime_id()engine_runtime_id()
Character scalar.
engine_runtime_id()engine_runtime_id()
install_engine() calls this before replacing a runtime that this session
already has mapped, so the file is not locked for the copy.
engine_unload()engine_unload()
Invisibly TRUE.
Called by prediction helpers. Safe to call repeatedly.
ensure_engine()ensure_engine()
Invisibly TRUE when available.
Matches the Python rbp_engine._license resolution order:
RBP_LICENSE
RBP_LICENSE_FILE
~/.rbp-engine/license.txt
/Library/rbp-engine/license.txt (macOS system install)
ensure_license_env()ensure_license_env()
Never errors. Called automatically from .onLoad.
The path adopted (invisibly), or NULL when the environment already
carries a license or no default file exists.
Same censor / scale / inversion knobs as PredictOptions, plus combination
search settings. Does not take verify_missing_data / missing_moments:
Grid chooses complete vs pairwise moments per combination.
GridOptions( threshold = c(0, 0.2, 0.5, 0.8), censor_type = "both", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", include_linear_regression = FALSE, verbose = FALSE, max_iter = 1000L, min_k = NULL, max_k = NULL, allowed_k = NULL, k = 1L, seed = 42L, retain_all = FALSE, retain_grid_objects = NULL, attribute_combi = NULL, required_attributes = NULL, attribute_groups = NULL, adjust_impact_for_missing = TRUE, inner_parallel = "auto" )GridOptions( threshold = c(0, 0.2, 0.5, 0.8), censor_type = "both", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", include_linear_regression = FALSE, verbose = FALSE, max_iter = 1000L, min_k = NULL, max_k = NULL, allowed_k = NULL, k = 1L, seed = 42L, retain_all = FALSE, retain_grid_objects = NULL, attribute_combi = NULL, required_attributes = NULL, attribute_groups = NULL, adjust_impact_for_missing = TRUE, inner_parallel = "auto" )
threshold |
Numeric vector of thresholds. Default |
censor_type |
|
censor_unit |
|
censor_operator |
Comparison vs threshold. Default |
prediction_scale |
|
adj_fit_multiplier |
|
inv_method |
|
include_linear_regression |
Logical; fills |
verbose |
Logical; engine diagnostics (default |
max_iter |
Combination search budget. |
min_k |
Minimum number of attributes turned on in a combination.
Combinations may be larger, up to |
max_k |
Maximum number of attributes turned on. Omit it to allow every
attribute. Set it equal to |
allowed_k |
Integer vector of exact combination sizes, such as
|
k |
Alias of |
seed |
RNG seed. |
retain_all |
Retain all grid cell objects. |
retain_grid_objects |
Character policy string (overrides |
attribute_combi |
Optional matrix of attribute combinations. Cannot
be combined with |
required_attributes |
Length-K 0/1 mask of attributes that are on in every generated combination. |
attribute_groups |
G by K 0/1 mask. Each row is a group of attributes selected together. |
adjust_impact_for_missing |
Logical; incomplete-column IOF/IOP vs a
μ+σZ include-k null (default |
inner_parallel |
|
A named list with class GridOptions.
GridOptions(min_k = 2L, max_iter = 100L)GridOptions(min_k = 2L, max_iter = 100L)
The open rbpengine package is a thin client. Predictions need the
private engine (shared library + companions + rbp-license-info). This
helper fetches the platform tarball from
https://docs.csanalytics.io/releases/ (or unpacks a local archive) into a
well-known prefix that engine_candidate_paths() already searches.
install_engine( version = "latest", dest = NULL, url = NULL, path = NULL, load = TRUE, quiet = FALSE )install_engine( version = "latest", dest = NULL, url = NULL, path = NULL, load = TRUE, quiet = FALSE )
version |
Math runtime to fetch ( |
dest |
Install prefix. Default is |
url |
Full URL of a |
path |
Local |
load |
If |
quiet |
Suppress download progress. |
This is a user-called step, never run at package install time and never
invoked from examples, tests, or vignettes (CRAN policy). Analogous to
pip install rbp-engine for the engine files only. Typical calls are
install_engine() for the latest math runtime for this machine,
install_engine(version = "1.3.7") to pin an rbp-math-lib tarball
(not the PyPI rbp-engine 2.x version), or
install_engine(path = "macos-arm64.tar.gz") for a local archive.
Calling it again upgrades in place. A library this session already loaded
from dest is unloaded first. A file another process still has mapped is
renamed aside and the new file is written under the original name, because
a loaded shared library cannot be overwritten in place.
The install prefix, invisibly.
ensure_engine(), engine_available(), uninstall_engine()
rbp-license-info CLI shipped with the engine runtime.Looks in the installed runtime bin/ (see install_engine()), well-known
prefixes, cargo target/, then PATH.
license_info(...)license_info(...)
... |
Arguments passed to the binary (character; e.g. |
Exit status (invisibly).
Human-readable description of where the license is coming from.
license_source()license_source()
A short character string such as "RBP_LICENSE (environment)",
"RBP_LICENSE_FILE=...", or a message indicating none is configured.
license_source()license_source()
Reads the RBP-ENGINE-VERSION= record compiled into the engine dll, dylib,
or so. This does not read package, config, or version files, and it does not
load the library, so a missing BLAS companion or a wrong-architecture binary
can still report the version baked into that file.
math_lib_version(path = NULL)math_lib_version(path = NULL)
path |
Optional full path to a shared library. When |
When path is omitted, RBP_ENGINE_LIB is the only file inspected if it is
set. Otherwise each existing file from engine_candidate_paths() is read
until one contains the record. A binary without that record is skipped, so an
older install does not hide a newer build. The filename depends on the OS:
librbp_math_lib.dylib (macOS), librbp_math_lib.so (Linux), or
rbp_math_lib.dll (Windows).
Prints one line to the terminal, rbp-math-lib <version> (<path>).
The semver string (for example "1.3.7"), invisibly.
engine_candidate_paths(), abi_version(), package_version_rbpengine()
Evaluates combinations of predictive attributes across relevance and
similarity thresholds, then forms a fit-weighted composite prediction for
circumstances theta. Combinations that fit this task more reliably pull
harder on the forecast. The result also includes variable-level Impact on
Fit and Impact on Prediction.
predict_grid(y, X, theta, options = NULL)predict_grid(y, X, theta, options = NULL)
y |
Numeric outcomes, length N. |
X |
Numeric matrix, N rows by K columns (R column-major is native). |
theta |
Circumstances vector, length K. |
options |
Optional PredictOptions, MaxFitOptions, or GridOptions. |
Recommended default path for analysis.
A nested list of class PredictionResults (same field layout as
Python rbp_engine.PredictionResults). Access fields with $, e.g.
result$yhat, result$insights$relevance.
PredictOptions(threshold = 0.5) if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) out <- predict_grid(y, X, theta, GridOptions(k = 1L, max_iter = 50L)) as.numeric(out$yhat[1]) best <- predict_maxfit(y, X, theta) res <- predict_psr(y, X, theta, PredictOptions(threshold = 0.5)) res$yhat }PredictOptions(threshold = 0.5) if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) out <- predict_grid(y, X, theta, GridOptions(k = 1L, max_iter = 50L)) as.numeric(out$yhat[1]) best <- predict_maxfit(y, X, theta) res <- predict_psr(y, X, theta, PredictOptions(threshold = 0.5)) res$yhat }
Searches candidate thresholds and returns the single winner on your objective: fit, adjusted fit, or k-fit (the default).
predict_maxfit(y, X, theta, options = NULL)predict_maxfit(y, X, theta, options = NULL)
y |
Numeric outcomes, length N. |
X |
Numeric matrix, N rows by K columns (R column-major is native). |
theta |
Circumstances vector, length K. |
options |
Optional PredictOptions, MaxFitOptions, or GridOptions. |
Useful when you want that maximum on one attribute set, without a full
combination grid. For primary analysis, prefer predict_grid(), which
diversifies across attribute combinations and thresholds, then blends by fit.
A nested list of class PredictionResults. yhat, fit, and
thresholds have length 1 (the winner).
if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) best <- predict_maxfit(y, X, theta) best$yhat best <- predict_maxfit(y, X, theta, MaxFitOptions(objective = "fit")) }if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) best <- predict_maxfit(y, X, theta) best$yhat best <- predict_maxfit(y, X, theta, MaxFitOptions(objective = "fit")) }
Forms a relevance-weighted forecast at the censoring thresholds you choose. The prediction uses the informative, relevant subset of the sample, rather than treating every past observation equally.
predict_psr(y, X, theta, options = NULL)predict_psr(y, X, theta, options = NULL)
y |
Numeric outcomes, length N. |
X |
Numeric matrix, N rows by K columns (R column-major is native). |
theta |
Circumstances vector, length K. |
options |
Optional PredictOptions, MaxFitOptions, or GridOptions. |
This is the evaluation inside each Grid cell and inside MaxFit. Use
predict_psr() when the attribute set and thresholds are already fixed.
For primary analysis, prefer predict_grid().
Named predict_psr (not predict) so base R's stats::predict is not masked.
A nested list of class PredictionResults. yhat has one prediction
per threshold.
if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) res <- predict_psr(y, X, theta, PredictOptions(threshold = 0.5)) res$yhat }if (engine_available()) { set.seed(1) N <- 40; K <- 3 X <- matrix(rnorm(N * K), N, K) y <- rnorm(N) theta <- colMeans(X) res <- predict_psr(y, X, theta, PredictOptions(threshold = 0.5)) res$yhat }
Mirrors Python PredictOptions, MaxFitOptions, and GridOptions.
Pass the list to predict_psr, predict_maxfit, or predict_grid.
Fields set to NULL are omitted so the engine applies its defaults.
PredictOptions( threshold = NULL, censor_type = "relevance", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", verify_missing_data = FALSE, include_linear_regression = FALSE, verbose = FALSE ) MaxFitOptions( threshold = c(0, 0.2, 0.5, 0.8), censor_type = "both", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", verify_missing_data = FALSE, include_linear_regression = FALSE, verbose = FALSE, objective = "kfit", inner_parallel = "auto" )PredictOptions( threshold = NULL, censor_type = "relevance", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", verify_missing_data = FALSE, include_linear_regression = FALSE, verbose = FALSE ) MaxFitOptions( threshold = c(0, 0.2, 0.5, 0.8), censor_type = "both", censor_unit = "percent", censor_operator = "greater_than_or_equal_to", prediction_scale = "response", adj_fit_multiplier = "k", inv_method = "gaussian", verify_missing_data = FALSE, include_linear_regression = FALSE, verbose = FALSE, objective = "kfit", inner_parallel = "auto" )
threshold |
Numeric vector of thresholds, or |
censor_type |
Character: |
censor_unit |
|
censor_operator |
Comparison vs threshold. Default |
prediction_scale |
|
adj_fit_multiplier |
|
inv_method |
|
verify_missing_data |
Logical. Predict / MaxFit only (not GridOptions). |
include_linear_regression |
Logical; fills |
verbose |
Logical; when |
objective |
MaxFit objective: |
inner_parallel |
|
A named list with class PredictOptions or MaxFitOptions.
GridOptions, predict_psr, predict_maxfit
PredictOptions(threshold = 0.5) MaxFitOptions(objective = "kfit")PredictOptions(threshold = 0.5) MaxFitOptions(objective = "kfit")
Print a compact summary of prediction results.
## S3 method for class 'PredictionResults' print(x, ...)## S3 method for class 'PredictionResults' print(x, ...)
x |
A |
... |
Unused. |
x, invisibly.
These call the loaded RBP Math Engine directly. Use ensure_engine() /
engine_available() if you need to check the runtime first.
relevance(X, theta) similarity(X, theta) info_x(X) info_theta(X, theta) relevance_metrics(X, theta)relevance(X, theta) similarity(X, theta) info_x(X) info_theta(X, theta) relevance_metrics(X, theta)
X |
Numeric matrix, N rows by K columns. |
theta |
Circumstances vector, length K (not used by |
For relevance() and similarity(), a numeric vector of length N.
info_x() returns a numeric vector of length K. info_theta() returns a
single numeric. relevance_metrics() returns a named list of metric
vectors/scalars from the engine.
X <- matrix(rnorm(20 * 3), 20, 3) theta <- colMeans(X) if (engine_available()) { relevance(X, theta) similarity(X, theta) info_x(X) info_theta(X, theta) relevance_metrics(X, theta) }X <- matrix(rnorm(20 * 3), 20, 3) theta <- colMeans(X) if (engine_available()) { relevance(X, theta) similarity(X, theta) info_x(X) info_theta(X, theta) relevance_metrics(X, theta) }
censor_unit is percent.Process-wide percentile cut algorithm used when censor_unit is percent.
set_percentile_value_algorithm(algorithm) get_percentile_value_algorithm()set_percentile_value_algorithm(algorithm) get_percentile_value_algorithm()
algorithm |
Integer code or string naming the algorithm (for example
|
set_percentile_value_algorithm() returns NULL invisibly.
get_percentile_value_algorithm() returns the current algorithm code as an
integer.
install_engine().Refuses to delete a directory that does not look like an RBP runtime
(lib/librbp_math_lib.* or lib/rbp_math_lib.dll present).
uninstall_engine(dest = NULL)uninstall_engine(dest = NULL)
dest |
Prefix to remove. Default |
TRUE invisibly if removed.
Package / ABI version and path diagnostics.
package_version_rbpengine() abi_version() engine_path_loaded() library_path()package_version_rbpengine() abi_version() engine_path_loaded() library_path()
package_version_rbpengine() returns the installed package version
as a string. abi_version() returns the loaded engine C ABI version as an
integer (errors if the engine is not loaded). engine_path_loaded()
returns the resolved engine library path, or NA_character_ when none is
loaded. library_path() returns a named list of engine/license diagnostics
including candidate search paths.
engine_available(), ensure_engine(), license_source(), math_lib_version()
package_version_rbpengine() engine_path_loaded()package_version_rbpengine() engine_path_loaded()