Xarray Integration¶
Integration utilities for Xarray data structures.
This module provides tools to bridge JAX tensors with xarray, allowing symbolic labeling of neural outputs and trained logical weights.
- jlnn.utils.xarray_utils.extract_weights_to_xarray(weights: Array, input_labels: List[str], gate_name: str) DataArray[source]¶
Extracts trained logic weights into a labeled xarray DataArray.
In LNN, weights w >= 1.0 represent the importance of an antecedent. This function creates a structured view of these weights, mapping each value to its symbolic predicate name.
- Parameters:
weights – JAX array of weights from a logical gate.
input_labels – Symbolic names of the inputs (e.g., [‘A’, ‘B’]).
gate_name – Name of the gate these weights belong to.
- Returns:
Labeled weights with ‘input’ dimension.
- Return type:
xr.DataArray
- jlnn.utils.xarray_utils.model_to_xarray(gate_outputs: Dict[str, Array], sample_labels: List[str]) Dataset[source]¶
Converts logical model outputs into a labeled xarray Dataset.
By mapping raw (batch, 2) tensors to a Dataset with ‘sample’ and ‘bound’ dimensions, we enable powerful scientific indexing and visualization of truth intervals.
- Parameters:
gate_outputs – Mapping of gate names to their [L, U] output tensors.
sample_labels – Names for the samples in the batch (e.g., individual IDs).
- Returns:
Multi-dimensional dataset containing truth intervals.
- Return type:
xr.Dataset
This module allows exporting model outputs to the xarray.Dataset format. This brings advantages such as:
* Labelled dimensions: Access to data via predicate names instead of numerical indices.
* Advanced indexing: Easy filtering of samples that exhibit high uncertainty.
* Serialization: Easy saving of experimental results in NetCDF format.