GRF2D#

class pinnx.fnspace.GRF2D(kernel='RBF', length_scale=1, N=100, interp='splinef2d')[source]#

Gaussian random field in [0, 1]x[0, 1].

The random sampling algorithm is based on Cholesky decomposition of the covariance matrix.

Parameters:
  • kernel (str) – The kernel function. “RBF” (radial-basis function) or “AE” (absolute exponential).

  • length_scale (float) – The length scale of the kernel.

  • N (int) – The size of the covariance matrix.

  • interp (str) – The interpolation to interpolate the random function. “linear” or “splinef2d”.

Example

space = pinnx.fnspace.GRF2D(length_scale=0.1)
features = space.random(3)
x = np.linspace(0, 1, num=500)
y = np.linspace(0, 1, num=500)
xv, yv = np.meshgrid(x, y)
sensors = np.vstack((np.ravel(xv), np.ravel(yv))).T
u = space.eval_batch(features, sensors)
for ui in u:
    plt.figure()
    plt.imshow(np.reshape(ui, (len(y), len(x))))
    plt.colorbar()
plt.show()
eval_batch(features, xs)[source]#

Evaluate a list of functions at a list of points.

Parameters:
  • features – A NumPy array of shape (n_functions, n_features). A list of the feature vectors of the functions to be evaluated.

  • xs – A NumPy array of shape (n_points, dim). A list of points to be evaluated.

Returns:

A NumPy array of shape (n_functions, n_points). The values of different functions at different points.

eval_one(feature, x)[source]#

Evaluate the function at one point.

Parameters:
  • feature – The feature vector of the function to be evaluated.

  • x – The point to be evaluated.

Returns:

The function value at x.

Return type:

float

random(size)[source]#

Generate feature vectors of random functions.

Parameters:

size (int) – The number of random functions to generate.

Returns:

A NumPy array of shape (size, n_features).