Sampling¤
NNFE is a data-free method: no ground-truth solution data is required.
Sampler generates control-variable point sets from a prescribed
distribution and provides mini-batch draws for the training loop.
Sampler¤
nnfe.sampling.Sampler
¤
Manages the control-variable point sets used for training and testing.
On construction the full training set (X) and test set (Y) are
generated and stored as NumPy arrays. During training, mini-batches are
drawn from X without replacement via :meth:draw_batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
:class: |
required | |
rng_key
|
Integer seed (currently unused; JAX-based batching is seeded at draw time). |
0
|
Attributes:
| Name | Type | Description |
|---|---|---|
config |
:class: |
|
training_sampler |
Bound method that generates training samples. |
|
testing_sampler |
Bound method that generates test samples. |
|
X |
Full training point set, shape |
|
Y |
Full test point set, shape |
uniform(mins=[0.0], maxes=[1.0], samples=[5], between_training=False)
¤
Generate a uniform Cartesian grid of control-variable samples.
For each dimension, samples equally-spaced points are generated
between mins and maxes using :func:numpy.linspace, then the
full tensor-product grid is assembled via :func:numpy.meshgrid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mins
|
Lower bounds for each dimension. |
[0.0]
|
|
maxes
|
Upper bounds for each dimension. |
[1.0]
|
|
samples
|
Number of points per dimension. |
[5]
|
|
between_training
|
If |
False
|
Returns:
| Type | Description |
|---|---|
|
NumPy array of shape |
|
|
grid points. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If mins, maxes, and samples have different lengths. |
draw_batch(rng_key, batch_size)
¤
Randomly sample a mini-batch from the training set without replacement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng_key
|
JAX PRNG key. A new key is split off internally so the caller's key is advanced. |
required | |
batch_size
|
Number of samples to draw. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple of |
|
|
|
safe_eval(expr)
¤
Return expr as a numeric value, rejecting arbitrary strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
A |
required |
Returns:
| Type | Description |
|---|---|
|
The input unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If expr is not a |