sciai.common.Sampler

View Source On Gitee
class sciai.common.Sampler(dim, coords, func, name=None)[source]

Common data sampler.

Parameters
  • dim (int) – Data dimension.

  • coords (Union[array, list]) – Lower bound coordinate and upper bound coordinate, e.g., [[0.0, 0.0], [0.0, 1.0]].

  • func (Callable) – Exact solution function.

  • name (str) – Sampler name. Default: None.

Supported Platforms:

GPU CPU Ascend

Examples

>>> import numpy as np
>>> from sciai.common import Sampler
>>> def u(x_):
>>>     t = x_[:, 0:1]
>>>     x = x_[:, 1:2]
>>>     return np.exp(-t) * np.sin(500 * np.pi * x)
>>> ics_coords = np.array([[0.0, 0.0], [0.0, 1.0]])
>>> ics_sampler = Sampler(2, ics_coords, u, name='Initial Condition 1')
>>> x_batch, y_batch = ics_sampler.sample(10)
>>> print(x_batch.shape, y_batch.shape)
(10, 2), (10, 1)
fetch_minibatch(n, mu_x, sigma_x)[source]

Fetch a minibatch of the sampler.

Parameters
  • n (int) – Number of sample points per minibatch.

  • mu_x (int) – Mean of the sample points.

  • sigma_x (int) – Standard deviation of the sample points.

Returns

tuple[Tensor], A minibatch of normalized sample points from the sampler.

normalization_constants(n)[source]

Normalization mean and standard deviation.

Parameters

n (int) – Number of sample points for mean and standard deviation calculation.

Returns

tuple[Tensor], Mean and standard deviation of sampled points.

sample(n)[source]

Sample points in given field.

Parameters

n (int) – Number of sample points.

Returns

tuple[Tensor], x and y of n sample points.