pycsamt.agents.ai_inversion#
pycsamt.agents.ai_inversion#
AIInversionAgent — End-to-end AI 1-D MT inversion.
Workflow#
Generate synthetic training data —
generate_dataset()builds aForwardDatasetof (response, model) pairs covering a realistic resistivity range.Train —
EMInverter1Dis fitted on the synthetic data using the selected network architecture.Predict — the trained inverter predicts a layered resistivity model for every station in the observed dataset.
Evaluate — per-station RMS between observed and re-computed forward response validates the prediction quality.
Visualise — convergence curve + predicted model sections.
Requires PyTorch or TensorFlow (lazy import — no hard dependency at import time). When neither is available the agent returns a clear error message with an installation hint.
Classes
|
Train an AI inverter on synthetic data then predict on observed sites. |
- class pycsamt.agents.ai_inversion.AIInversionAgent(*, api_key=None, model=None, llm_provider='claude', arch='resnet', n_layers=5, n_train_samples=2000, epochs=30, freqs=None, pretrained=None)[source]#
Bases:
BaseAgentTrain an AI inverter on synthetic data then predict on observed sites.
- Parameters:
api_key (str)
model (str)
llm_provider (str)
arch (optional overrides) – Neural network architecture.
n_layers (int) – Number of model layers the inverter will predict (default 5).
n_train_samples (optional overrides) – Number of synthetic training samples (default 2 000).
epochs (optional overrides) – Training epochs (default 30). Increase for better models.
freqs (array-like or None) – Frequencies used for both training synthesis and observed data interpolation. Default: 40 log-spaced 10⁻⁴–10³ Hz.
pretrained (str or None) – Path to a pre-trained model checkpoint. When set, skips training.
keys (Output data)
----------
path (sites /)
output_dir (str, optional)
arch
epochs
n_train_samples
keys
----------------
:param
inverterEMInverter1D: :parampredictionsdict {station: :typepredictionsdict {station: ndarray of log₁₀ ρ values} :parambest_modeldict with “resistivity” and “thickness” for first station: :paramrms_per_stationdict {station: :typerms_per_stationdict {station: float} :paramrms_globalfloat: :paramtrain_historydict (loss curves): :paramfiguresdict: :paramfigure_pathsdict:Examples
>>> agent = AIInversionAgent(arch="resnet", n_layers=5, epochs=30) >>> result = agent.execute({ ... "path": "/data/L22PLT", ... "output_dir": "/out/ai_inv", ... }) >>> result["rms_global"] 0.24
- SYSTEM_PROMPT: str = 'You are an expert in AI-based MT inversion and deep learning for geophysics.\nGiven an AI inversion result, write 4–5 sentences that:\n1. Describe the neural network architecture used and training convergence.\n2. State the prediction quality (RMS, layer count, depth range).\n3. Identify stations where the AI prediction is most / least reliable.\n4. Compare AI results with classical Bostick depth estimates if available.\n5. Recommend next steps (fine-tuning, ensemble, switch to 2-D inversion).\nReply in plain scientific English.\n'#
Override in subclasses to give the LLM its domain expertise.
- classmethod from_pretrained(model_name, *, api_key=None, model=None, llm_provider='claude', cache_dir=None, force_download=False)[source]#
Return an
AIInversionAgentpre-loaded with a zoo checkpoint.- Parameters:
- Return type:
Examples
>>> agent = AIInversionAgent.from_pretrained("mt1d-resnet-5layer-v1") >>> result = agent.execute({"path": "/data/L22PLT"})
- 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.0at the top.Record wall-clock time with
t0 = time.time().Return
AgentResult(elapsed_seconds=time.time()-t0, cost_estimate_usd=self._last_cost, ...).
- Parameters:
- Return type: