TP simulation¶
Prediction, Realizations, transition-probability cokriging and T-PROGS simulation. See the guide.
Prediction
¶
Category probabilities at every cell.
Attributes:
| Name | Type | Description |
|---|---|---|
probabilities |
ndarray
|
|
most_likely |
ndarray
|
int64 most probable category (lowest code on ties), -1 outside the mask. |
entropy |
ndarray
|
Shannon entropy over |
corrected |
float
|
Fraction of cells whose probabilities were clipped to [0, 1] and renormalised. |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> pred = tg.tp_cokriging(model, grid, xyz, codes)
>>> pred.probabilities.shape, pred.entropy.shape
((864, 3), (864,))
>>> pred.most_likely[cells], hard
(array([0, 2, 1]), array([0, 2, 1]))
>>> float(pred.corrected) >= 0.0
True
>>> tg.Prediction.from_json(pred.to_json()).to_json() == pred.to_json()
True
probabilities
property
¶
probabilities: NDArray[float64]
(n_cells, k) category probabilities, rows summing to 1; NaN outside the mask.
most_likely
property
¶
most_likely: NDArray[int64]
int64 most probable category (lowest code on ties), -1 outside the mask.
corrected
property
¶
corrected: float
Fraction of cells whose probabilities were clipped to [0, 1] and renormalised.
to_json
¶
to_json() -> str
Realizations
¶
Categorical grid realizations.
Attributes:
| Name | Type | Description |
|---|---|---|
realizations |
ndarray
|
int64 |
proportions |
ndarray
|
|
probabilities |
ndarray
|
|
most_likely |
ndarray
|
Of |
entropy |
ndarray
|
Of |
corrected |
ndarray
|
|
objective |
list of numpy.ndarray
|
Quenching objective after each sweep, per realization (empty for MCRF). |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> real = tg.mcrf_simulate(model, grid, xyz, codes, n=3, seed=1)
>>> real.realizations.shape, real.proportions.shape, real.probabilities.shape
((3, 864), (3, 3), (864, 3))
>>> bool(np.all(real.realizations[:, cells] == hard))
True
>>> real.most_likely.shape, real.entropy.shape, real.corrected, real.objective
((864,), (864,), array([0., 0., 0.]), [])
>>> tg.Realizations.from_json(real.to_json()).to_json() == real.to_json()
True
realizations
property
¶
realizations: NDArray[int64]
int64 (n, n_cells), cells x fastest, -1 outside the mask.
proportions
property
¶
proportions: NDArray[float64]
(n, k) category proportions of each realization over active cells.
probabilities
property
¶
probabilities: NDArray[float64]
(n_cells, k) frequency of each category over the realizations.
most_likely
property
¶
most_likely: NDArray[int64]
int64 most frequent category per cell (lowest code on ties), -1 outside the mask.
corrected
property
¶
corrected: NDArray[float64]
(n,) fraction of cells clipped during sequential simulation (zeros for MCRF).
objective
property
¶
objective: list[NDArray[float64]]
Quenching objective after each sweep, per realization (empty for MCRF).
to_json
¶
to_json() -> str
tp_cokriging
builtin
¶
tp_cokriging(
model: TransitionModel,
grid: Grid | object,
coords: ArrayLike | str | object,
codes: ArrayLike | str | None = None,
*,
mask: ArrayLike | None = None,
max_data: int = 12,
closeness_limit: float = 0.01,
max_per_octant: int = 0,
svd_cutoff: float = 1e-08,
memory: int | None = None,
data: Mapping[str, ArrayLike] | object | None = None,
) -> Prediction
Transition-probability cokriging (T-PROGS): category probabilities at every cell from the hard data, without simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TransitionModel
|
|
required |
grid
|
Grid
|
|
required |
coords
|
array_like
|
|
required |
codes
|
array_like or str
|
Hard data categories. |
None
|
mask
|
array_like
|
Active cells. |
None
|
max_data
|
int
|
Nearest data per cell, even. |
12
|
closeness_limit
|
float
|
Offsets whose closeness falls below it are not searched. |
0.01
|
max_per_octant
|
int
|
0 for no cap. |
0
|
svd_cutoff
|
float
|
Relative singular value cutoff of the cokriging solve. |
1e-08
|
memory
|
int
|
Byte budget; the available memory by default. |
None
|
data
|
mapping
|
|
None
|
Returns:
| Type | Description |
|---|---|
Prediction
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When the coordinates are not |
ConvergenceError
|
When a cokriging system cannot be solved. |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> pred = tg.tp_cokriging(model, grid, xyz, codes, max_data=8)
>>> bool(np.allclose(pred.probabilities.sum(axis=1), 1.0))
True
tprogs_simulate
builtin
¶
tprogs_simulate(
model: TransitionModel,
grid: Grid | object,
coords: ArrayLike | str | object,
codes: ArrayLike | str | None = None,
*,
n: int = 1,
seed: int = 0,
mask: ArrayLike | None = None,
max_data: int = 12,
closeness_limit: float = 0.01,
max_per_octant: int = 0,
svd_cutoff: float = 1e-08,
quench: bool = True,
quench_iterations: int = 3,
quench_limit: float = 0.4,
quench_tol: float = 0.001,
proportion_weight: float = 1.0,
memory: int | None = None,
data: Mapping[str, ArrayLike] | object | None = None,
) -> Realizations
T-PROGS simulation: sequential indicator simulation with transition-probability cokriging, then zero-temperature quenching towards the model transiograms. Hard cells never change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TransitionModel
|
As in |
required |
grid
|
TransitionModel
|
As in |
required |
coords
|
TransitionModel
|
As in |
required |
codes
|
TransitionModel
|
As in |
required |
mask
|
TransitionModel
|
As in |
required |
max_data
|
TransitionModel
|
As in |
required |
closeness_limit
|
TransitionModel
|
As in |
required |
max_per_octant
|
TransitionModel
|
As in |
required |
svd_cutoff
|
TransitionModel
|
As in |
required |
n
|
int
|
Number of realizations. |
1
|
seed
|
int
|
|
0
|
quench
|
bool
|
|
True
|
quench_iterations
|
int
|
Largest number of quenching sweeps. |
3
|
quench_limit
|
float
|
Closeness above which a lag enters the quenching objective. |
0.4
|
quench_tol
|
float
|
Relative objective gain that stops quenching. |
0.001
|
proportion_weight
|
float
|
Weight of the proportion term in the objective. |
1.0
|
memory
|
int
|
|
None
|
data
|
mapping
|
|
None
|
Returns:
| Type | Description |
|---|---|
Realizations
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When the coordinates are not |
ConvergenceError
|
When a cokriging system cannot be solved. |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> real = tg.tprogs_simulate(model, grid, xyz, codes, n=2, seed=1, quench_iterations=1)
>>> real.realizations.shape, len(real.objective)
((2, 864), 2)
>>> bool(np.all(real.realizations[:, cells] == hard))
True