anypinn.core.samplers
Collocation point sampling strategies for PINN training.
AdaptiveSampler
Residual-weighted adaptive collocation sampler.
Draws an oversample of candidate points, scores them using a
ResidualScorer, and retains the top-scoring subset. A configurable
exploration_ratio ensures a fraction of purely random points to prevent
mode collapse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scorer
|
ResidualScorer
|
Callable returning per-point residual scores |
required |
oversample_factor
|
int
|
Multiplier on |
4
|
exploration_ratio
|
float
|
Fraction of the budget reserved for random points. |
0.2
|
seed
|
int | None
|
Optional seed for reproducible sampling. |
None
|
Source code in src/anypinn/core/samplers.py
__init__(scorer: ResidualScorer, oversample_factor: int = 4, exploration_ratio: float = 0.2, seed: int | None = None) -> None
Source code in src/anypinn/core/samplers.py
sample(n: int, domain: Domain) -> Tensor
Source code in src/anypinn/core/samplers.py
CollocationSampler
Bases: Protocol
Protocol for collocation point samplers.
Implementations must return a tensor of shape (n, domain.ndim) with all
points inside the domain bounds.
Source code in src/anypinn/core/samplers.py
sample(n: int, domain: Domain) -> Tensor
Source code in src/anypinn/core/samplers.py
LatinHypercubeSampler
Latin Hypercube sampler (pure-PyTorch, no SciPy dependency).
Stratifies each dimension into n equal intervals and places one sample
per interval, then shuffles columns independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed for reproducible sampling. |
None
|
Source code in src/anypinn/core/samplers.py
__init__(seed: int | None = None) -> None
sample(n: int, domain: Domain) -> Tensor
Source code in src/anypinn/core/samplers.py
LogUniform1DSampler
Log-uniform sampler for 1-D domains (reproduces SIR collocation behavior).
Samples uniformly in log1p space and maps back via expm1, producing
a distribution that is denser near the lower bound — useful for epidemic
models where early dynamics are most informative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed for reproducible sampling. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the domain is not 1-D or |
Source code in src/anypinn/core/samplers.py
__init__(seed: int | None = None) -> None
sample(n: int, domain: Domain) -> Tensor
Source code in src/anypinn/core/samplers.py
RandomSampler
Uniform random sampler inside domain bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed for reproducible sampling. |
None
|
Source code in src/anypinn/core/samplers.py
__init__(seed: int | None = None) -> None
sample(n: int, domain: Domain) -> Tensor
ResidualScorer
Bases: Protocol
Protocol for scoring candidate collocation points by PDE residual magnitude.
Source code in src/anypinn/core/samplers.py
residual_score(x: Tensor) -> Tensor
Return per-point non-negative residual score of shape (n,).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Candidate collocation points |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scores |
Source code in src/anypinn/core/samplers.py
UniformSampler
Cartesian grid sampler that distributes points evenly across the domain.
For d-dimensional domains, places ceil(n^(1/d)) points per axis then
takes the first n points of the resulting grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed (unused — grid is deterministic). |
None
|
Source code in src/anypinn/core/samplers.py
__init__(seed: int | None = None) -> None
sample(n: int, domain: Domain) -> Tensor
Source code in src/anypinn/core/samplers.py
build_sampler(strategy: CollocationStrategies, seed: int | None = None, scorer: ResidualScorer | None = None) -> CollocationSampler
Construct a collocation sampler from a strategy name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
CollocationStrategies
|
One of the |
required |
seed
|
int | None
|
Optional seed for reproducible sampling. |
None
|
scorer
|
ResidualScorer | None
|
Required when |
None
|
Returns:
| Type | Description |
|---|---|
CollocationSampler
|
A sampler instance satisfying the |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |