| Title: | Backend-Neutral Explainable Geometry State and Operators |
|---|---|
| Description: | Provides the platform layer for explanation geometry in R. The package standardizes generic explanation tables into a normalized backend state object, computes embeddings, diagnostics, and multiscale level-of-detail summaries, and serializes backend-neutral state for reproducible workflows. It also exposes selected long-table and regular-grid views for downstream use-case packages. Rendering and viewport orchestration are delegated to downstream frontends such as 'ggWebGL'. |
| Authors: | Frederic Bertrand [cre, aut] (ORCID: <https://orcid.org/0000-0002-0837-8281>) |
| Maintainer: | Frederic Bertrand <[email protected]> |
| License: | GPL-3 |
| Version: | 0.7.0 |
| Built: | 2026-05-08 19:17:39 UTC |
| Source: | https://github.com/cran/XGeoRTR |
xgeo_state
Coerce inputs to xgeo_state
as_xgeo_state(x, ...)as_xgeo_state(x, ...)
x |
An object to coerce. |
... |
Passed to method-specific implementations. |
An xgeo_state object.
as_xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75) ) )as_xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75) ) )
Build density-grid LOD summaries for a state
build_xgeo_lod( state, embedding = NULL, levels = c(16L, 32L, 64L), color_by = c("count", "mean_value"), name = NULL, auto_threshold = 200L )build_xgeo_lod( state, embedding = NULL, levels = c(16L, 32L, 64L), color_by = c("count", "mean_value"), name = NULL, auto_threshold = 200L )
state |
An |
embedding |
Optional embedding name. Defaults to the active embedding. |
levels |
Integer vector of grid resolutions. |
color_by |
Statistic stored in each density grid. |
name |
Optional LOD bundle name. |
auto_threshold |
Point count threshold used by |
The updated xgeo_state.
state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) state <- build_xgeo_lod(state, levels = c(4L, 8L), auto_threshold = 2L) names(state$lod$items)state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) state <- build_xgeo_lod(state, levels = c(4L, 8L), auto_threshold = 2L) names(state$lod$items)
Compute embedding diagnostics for a state
compute_xgeo_diagnostics( state, embedding = NULL, source = c("explanations", "point_meta", "points"), k = 10L, name = NULL )compute_xgeo_diagnostics( state, embedding = NULL, source = c("explanations", "point_meta", "points"), k = 10L, name = NULL )
state |
An |
embedding |
Optional embedding name. Defaults to the active embedding. |
source |
Reference source space used for neighbour comparisons. |
k |
Number of neighbours. |
name |
Optional diagnostic bundle name. |
The updated xgeo_state.
state <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) state <- compute_xgeo_diagnostics( state, embedding = "pca_explanations", source = "explanations", k = 1 ) names(state$attributes$diagnostics$items)state <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) state <- compute_xgeo_diagnostics( state, embedding = "pca_explanations", source = "explanations", k = 1 ) names(state$attributes$diagnostics$items)
Compute and attach a platform embedding
compute_xgeo_embedding( state, source = c("explanations", "point_meta", "points"), method = c("pca", "umap"), dims = 2L, name = NULL, ... )compute_xgeo_embedding( state, source = c("explanations", "point_meta", "points"), method = c("pca", "umap"), dims = 2L, name = NULL, ... )
state |
An |
source |
Source matrix used to build the embedding. One of
|
method |
Embedding backend. |
dims |
Number of output dimensions. |
name |
Optional embedding name. Defaults to |
... |
Passed to backend-specific implementations. |
The updated xgeo_state.
state <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) names(state$attributes$embeddings$items)state <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) names(state$attributes$embeddings$items)
Read a backend state from JSON
read_xgeo_state(path)read_xgeo_state(path)
path |
Path to a JSON state file. |
An xgeo_state object.
state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) path <- tempfile(fileext = ".json") write_xgeo_state(state, path) restored <- read_xgeo_state(path) class(restored)state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) path <- tempfile(fileext = ".json") write_xgeo_state(state, path) restored <- read_xgeo_state(path) class(restored)
Set the active embedding on a state
set_active_embedding(state, name)set_active_embedding(state, name)
state |
An |
name |
Name of an embedding stored in |
The updated xgeo_state.
state <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) state <- set_active_embedding(state, "pca_explanations") state$attributes$embeddings$activestate <- as_xgeo_state( data.frame( point_id = rep(paste0("p", 1:4), each = 2), feature = rep(c("f1", "f2"), times = 4), x = c(0, 0, 1, 1, 0, 0, 1, 1), y = c(0, 0, 0, 0, 1, 1, 1, 1), value = c(0.2, 0.7, 0.4, 0.1, 0.8, 0.6, 0.5, 0.3) ), point_id_col = "point_id", feature_col = "feature" ) state <- compute_xgeo_embedding(state, method = "pca", source = "explanations", dims = 2) state <- set_active_embedding(state, "pca_explanations") state$attributes$embeddings$active
Set the active level-of-detail state on a state
set_xgeo_lod(state, name = NULL, level = NULL)set_xgeo_lod(state, name = NULL, level = NULL)
state |
An |
name |
Optional LOD bundle name stored in |
level |
Optional level inside the selected LOD bundle. |
The updated xgeo_state.
state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) state <- build_xgeo_lod(state, levels = c(4L, 8L), auto_threshold = 2L) state <- set_xgeo_lod(state, name = "density_grid_spatial", level = "4") state$lod$activestate <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) state <- build_xgeo_lod(state, levels = c(4L, 8L), auto_threshold = 2L) state <- set_xgeo_lod(state, name = "density_grid_spatial", level = "4") state$lod$active
Set explicit point and feature selection on a state
set_xgeo_selection(state, point_ids = NULL, features = NULL)set_xgeo_selection(state, point_ids = NULL, features = NULL)
state |
An |
point_ids |
Optional character vector of selected point ids. |
features |
Optional character vector of selected feature ids. |
The updated xgeo_state.
state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2", "p2"), feature = c("f1", "f2", "f1", "f2"), x = c(0, 0, 1, 1), y = c(0, 0, 1, 1), value = c(1, -0.25, 0.75, 2) ), point_id_col = "point_id", feature_col = "feature" ) state <- set_xgeo_selection(state, point_ids = "p1", features = "f2") xgeo_selection(state)state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2", "p2"), feature = c("f1", "f2", "f1", "f2"), x = c(0, 0, 1, 1), y = c(0, 0, 1, 1), value = c(1, -0.25, 0.75, 2) ), point_id_col = "point_id", feature_col = "feature" ) state <- set_xgeo_selection(state, point_ids = "p1", features = "f2") xgeo_selection(state)
xgeo_state objectValidate an xgeo_state object
validate_xgeo_state(x)validate_xgeo_state(x)
x |
An object to validate. |
x, invisibly, when validation succeeds.
state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) validate_xgeo_state(state)state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) validate_xgeo_state(state)
Write a backend state to JSON
write_xgeo_state(state, path, pretty = TRUE)write_xgeo_state(state, path, pretty = TRUE)
state |
An |
path |
Output file path. |
pretty |
Whether to pretty-print the JSON. |
The normalized output path, invisibly.
state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) path <- tempfile(fileext = ".json") write_xgeo_state(state, path) file.exists(path)state <- xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) path <- tempfile(fileext = ".json") write_xgeo_state(state, path) file.exists(path)
xgeo_state
Get attributes from an xgeo_state
xgeo_attributes(state)xgeo_attributes(state)
state |
An |
The attributes field.
state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) names(xgeo_attributes(state))state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) names(xgeo_attributes(state))
xgeo_explanation_table() exposes the selected explanation records together
with point coordinates and metadata. It is renderer-agnostic and contains no
use-case-specific presentation semantics.
xgeo_explanation_table(state, selected = TRUE)xgeo_explanation_table(state, selected = TRUE)
state |
An |
selected |
Whether to apply the state's point and feature selection. |
A data frame containing point_id, feature, value, x, y,
z, and any point-, feature-, prediction-, or uncertainty-level metadata.
state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75), cluster = c("A", "A", "B") ), point_id_col = "point_id", feature_col = "feature" ) xgeo_explanation_table(state)state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75), cluster = c("A", "A", "B") ), point_id_col = "point_id", feature_col = "feature" ) xgeo_explanation_table(state)
xgeo_state
Get geometry from an xgeo_state
xgeo_geometry(state)xgeo_geometry(state)
state |
An |
The geometry field.
state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) xgeo_geometry(state)$pointsstate <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) xgeo_geometry(state)$points
xgeo_state
Get indices from an xgeo_state
xgeo_indices(state)xgeo_indices(state)
state |
An |
The indices field.
state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) xgeo_indices(state)state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) xgeo_indices(state)
xgeo_state
Get metadata from an xgeo_state
xgeo_metadata(state)xgeo_metadata(state)
state |
An |
The metadata field.
state <- xgeo_state( matrix(c(1, 2, 3, 4), nrow = 2), metadata = list(source = "demo-state") ) xgeo_metadata(state)state <- xgeo_state( matrix(c(1, 2, 3, 4), nrow = 2), metadata = list(source = "demo-state") ) xgeo_metadata(state)
xgeo_point_values() exposes a selected, renderer-neutral point table with
coordinates, aggregated explanation values, and point-level metadata.
xgeo_point_values(state, aggregate = sum, selected = TRUE)xgeo_point_values(state, aggregate = sum, selected = TRUE)
state |
An |
aggregate |
Aggregation function applied across selected features per
point. Defaults to |
selected |
Whether to apply the state's point and feature selection. |
A data frame containing point_id, x, y, z, value, and any
point-, prediction-, or uncertainty-level metadata.
state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2", "p2"), feature = c("f1", "f2", "f1", "f2"), x = c(0, 0, 1, 1), y = c(0, 0, 1, 1), value = c(1, -0.25, 0.75, 2), cluster = c("A", "A", "B", "B") ), point_id_col = "point_id", feature_col = "feature" ) state <- set_xgeo_selection(state, features = "f1") xgeo_point_values(state)state <- as_xgeo_state( data.frame( point_id = c("p1", "p1", "p2", "p2"), feature = c("f1", "f2", "f1", "f2"), x = c(0, 0, 1, 1), y = c(0, 0, 1, 1), value = c(1, -0.25, 0.75, 2), cluster = c("A", "A", "B", "B") ), point_id_col = "point_id", feature_col = "feature" ) state <- set_xgeo_selection(state, features = "f1") xgeo_point_values(state)
xgeo_regular_grid() validates a complete 2D regular grid and returns the
grid vectors and value matrix without creating a renderer-specific object.
xgeo_regular_grid(data, x = "x", y = "y", value = "value")xgeo_regular_grid(data, x = "x", y = "y", value = "value")
data |
A data frame containing x, y, and value columns. |
x |
Name of the x-coordinate column. |
y |
Name of the y-coordinate column. |
value |
Name of the value column. |
A list with x, y, and z, where z is a value matrix indexed by
the returned x and y coordinates.
xgeo_regular_grid( data.frame( x_coord = c(0, 1, 0, 1), y_coord = c(0, 0, 1, 1), score = c(1, 2, 3, 4) ), x = "x_coord", y = "y_coord", value = "score" )xgeo_regular_grid( data.frame( x_coord = c(0, 1, 0, 1), y_coord = c(0, 0, 1, 1), score = c(1, 2, 3, 4) ), x = "x_coord", y = "y_coord", value = "score" )
xgeo_state
Get selection from an xgeo_state
xgeo_selection(state)xgeo_selection(state)
state |
An |
The selection field.
state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) state <- set_xgeo_selection(state, point_ids = state$indices$point_ids[[1]]) xgeo_selection(state)state <- xgeo_state(matrix(c(1, 2, 3, 4), nrow = 2)) state <- set_xgeo_selection(state, point_ids = state$indices$point_ids[[1]]) xgeo_selection(state)
xgeo_state
Create an xgeo_state
xgeo_state( x, embeddings = NULL, diagnostics = NULL, lod = NULL, selection = NULL, metadata = list() )xgeo_state( x, embeddings = NULL, diagnostics = NULL, lod = NULL, selection = NULL, metadata = list() )
x |
A matrix, data frame, or object coercible to backend geometry state. |
embeddings |
Optional embedding state. |
diagnostics |
Optional diagnostic state. |
lod |
Optional level-of-detail state. |
selection |
Optional explicit selection state. |
metadata |
Optional state metadata. |
An xgeo_state object.
# Matrix input is converted into a backend regular grid state. xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) # Long-tabular input preserves point ids and feature ids. xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75) ) )# Matrix input is converted into a backend regular grid state. xgeo_state(matrix(c(1, -1, 2, 0), nrow = 2)) # Long-tabular input preserves point ids and feature ids. xgeo_state( data.frame( point_id = c("p1", "p1", "p2"), feature = c("f1", "f2", "f1"), x = c(0, 0, 1), y = c(0, 0, 1), value = c(1, -0.5, 0.75) ) )