Skip to content

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:~nnfe.nnfe_config.SamplerConfig instance.

required
rng_key

Integer seed (currently unused; JAX-based batching is seeded at draw time).

0

Attributes:

Name Type Description
config

:class:~nnfe.nnfe_config.SamplerConfig used to build this sampler.

training_sampler

Bound method that generates training samples.

testing_sampler

Bound method that generates test samples.

X

Full training point set, shape (N_train, n_ctrl_vars).

Y

Full test point set, shape (N_test, n_ctrl_vars).

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 True, shift the grid so points fall between training points (half-step offset), reducing the sample count by one per dimension.

False

Returns:

Type Description

NumPy array of shape (prod(samples), n_dims) containing all

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 (updated_rng_key, batch) where batch has shape

(batch_size, n_ctrl_vars).

safe_eval(expr) ¤

Return expr as a numeric value, rejecting arbitrary strings.

Parameters:

Name Type Description Default
expr

A float or int value.

required

Returns:

Type Description

The input unchanged.

Raises:

Type Description
ValueError

If expr is not a float or int.