The PDE is given by
where and .
The domain is defined as
The terminal condition is
where
File name: 2D_Black-Scholes-Barenblatt_r0.05_sigma0.4.hdf5
File hierarchy:
/ |-- tensor |-- x-coordinate |-- y-coordinate |-- t-coordinate
Datasets information:
According to the paper, the equation admits the explicit solution: . We generate data directly based on the explicit solution. The python script is below:
import torch
import h5py
# 2D
Nt = 101
Nx = 128
Ny = 128
spatial_dim = 2
num_samples = 1000
# create coordinates
T, X, Y = torch.meshgrid(torch.linspace(0, 1, Nt), torch.linspace(0, 1, Nx), torch.linspace(0, 1, Ny), indexing="ij")
coords = torch.stack([T, X, Y], dim=spatial_dim+1)
# print(coords[0,0,:,:], coords[0,:,0,:], coords[:,0,0,:])
coords = torch.reshape(coords, [-1, spatial_dim+1])
# random coefficient c
C = torch.rand(num_samples)
dataset_path = "2D_Black-Scholes-Barenblatt_r0.05_sigma0.4.hdf5"
with h5py.File(dataset_path, 'w') as f:
f.create_dataset("x-coordinate", data=torch.linspace(0, 1, Nx))
f.create_dataset("y-coordinate", data=torch.linspace(0, 1, Ny))
f.create_dataset("t-coordinate", data=torch.linspace(0, 1, Nt))
tensor = f.create_dataset("tensor", (num_samples, Nt, Nx, Ny), dtype='f')
tensor.attrs["c"] = C
for i in range(num_samples):
U = C[i] * torch.exp((r + sigma**2) * (1 - coords[:,0])) * torch.linalg.vector_norm(coords[:,1:], ord=2, dim=1)**2
U = torch.reshape(U, [Nt, Nx, Ny, -1])
tensor[i] = U.squeeze(-1)