2.26.5.23. pycsamt.agents.ensemble_agent#

pycsamt.agents.ensemble_agent#

EnsembleAgent — Ensemble 1-D inversion with uncertainty quantification.

Wraps EnsembleInverter:

  • Trains N independent EMInverter1D models on a shared synthetic dataset using different random seeds.

  • Predicts mean resistivity and uncertainty (std / confidence intervals) for every observed station.

  • Optionally calibrates the intervals using a held-out conformal set.

  • Reports empirical coverage (fraction of true values inside the interval) as a reliability metric.

The outputs feed directly into the ReportAgent and are used as a rigorous uncertainty-aware alternative to single-model AI inversion.

Requires PyTorch or TensorFlow.

Classes

EnsembleAgent(*[, api_key, model, ...])

Ensemble 1-D MT inversion with uncertainty bands.

class pycsamt.agents.ensemble_agent.EnsembleAgent(*, api_key=None, model=None, llm_provider='claude', n_estimators=5, arch='resnet', n_layers=5, n_train_samples=2000, epochs=30, calibrate=True)[source]

Bases: BaseAgent

Ensemble 1-D MT inversion with uncertainty bands.

Parameters:
  • api_key (str)

  • model (str)

  • llm_provider (str)

  • n_estimators (int) – Number of independent models in the ensemble (default 5).

  • arch (str) – Network architecture for each estimator (default "resnet").

  • n_layers (int) – Number of model layers (default 5).

  • n_train_samples (int) – Synthetic training samples per estimator (default 2 000).

  • epochs (int) – Training epochs per estimator (default 30).

  • calibrate (bool) – Apply conformal calibration using 20 % of training data (default True).

  • keys (Output data)

  • ----------

  • path (sites /)

  • output_dir (str, optional)

  • keys

  • ----------------

  • EnsembleInverter (ensemble)

  • {station (pred_hi dict)

  • {station

  • {station

  • {station

  • coverage (coverage float — empirical 90 % interval)

  • float (rms_global)

  • dict (figure_paths)

  • dict

Examples

>>> agent = EnsembleAgent(n_estimators=3, epochs=20)
>>> result = agent.execute(
...     {"path": "/data/L22PLT", "output_dir": "/out/ens"}
... )
>>> result["coverage"]  # should be ≈ 0.90 after calibration
0.88
SYSTEM_PROMPT: str = 'You are an expert in Bayesian and ensemble methods for geophysical inversion.\nGiven an ensemble inversion result with uncertainty quantification, write 4-5\nsentences that:\n1. Describe the ensemble configuration (N models, architecture, training data).\n2. State the prediction quality (mean RMS, uncertainty magnitude).\n3. Assess the calibration: are the confidence intervals reliable?\n4. Identify depth ranges or stations where uncertainty is largest.\n5. Recommend whether the uncertainty is small enough for geological interpretation.\nReply in plain scientific English.\n'

Override in subclasses to give the LLM its domain expertise.

execute(input_data)[source]

Run this agent on input_data and return an AgentResult.

Subclasses must implement this method. The contract:

  • Reset self._last_cost = 0.0 at the top.

  • Record wall-clock time with t0 = time.time().

  • Return AgentResult(elapsed_seconds=time.time()-t0, cost_estimate_usd=self._last_cost, ...).

Parameters:

input_data (dict[str, Any])

Return type:

AgentResult