dataset.py¶
Collection of codes for generating some training data sets.
-
class
dataset.
diffOp1
(op_type='uxx', op_params=None, gen_mode='exp1', gen_params={'alpha1': 0.1}, num_samples=10000, nchannels=1, nx=15, flag_verbose=0, **extra_params)¶ Generates samples of the form \((u^{[i]},f^{[i]})\) where \(f^{[i]} = L[u^{[i]}]\), where \(i\) denotes the index of the sample.
Stores data samples in the form \((u,f)\).
The samples of u are represented as a tensor of size [nsamples,nchannels,nx] and sample of f as a tensor of size [nsamples,nchannels,nx].
Note
For now, please use nx that is odd. In this initial implementation, we use a method based on conjugated flips with formula for the odd case which is slightly simpler than other case.
-
__getitem__
(index)¶
-
__init__
(op_type='uxx', op_params=None, gen_mode='exp1', gen_params={'alpha1': 0.1}, num_samples=10000, nchannels=1, nx=15, flag_verbose=0, **extra_params)¶ Setup for data generation.
- Parameters
op_type (str) – The differential operator to sample.
op_params (dict) – The operator parameters.
gen_mode (str) – The mode for the data generator.
gen_params (dict) – The parameters for the given generator.
num_samples (int) – The number of samples to generate.
nchannels (int) – The number of channels.
nx (int) – The number of input sample points.
flag_verbose (int) – Level of reporting during calculations.
extra_params (dict) – Extra parameters for the sampler.
- For extra_params we have:
noise_factor (float): The amount of noise to add to samples. scale_factor (float): A factor to scale magnitude of the samples. flagComputeL (bool): If the fourier symbol of operator should be computed.
- For generator modes we have:
- gen_mode == ‘exp1’:
alpha1 (float): The decay rate.
Note
For now, please use only nx that is odd. In this initial implementation, we use a method based on conjugated flips with formula for the odd case which is slightly simpler than other case.
-
__len__
()¶
-
__module__
= 'dataset'¶
-
computeActionL
(u, L_hat)¶ Computes the action of operator L used for data generation.
-
computeCoeffActionL
(u_hat, L_hat)¶ Computes the action of operator L used for data generation in Fourier space.
-
computeLSymbol_ux
()¶ Compute associated Fourier symbols for use under DFT for the operator L[u].
-
computeLSymbol_uxx
()¶ Compute associated Fourier symbols for use under DFT for the operator L[u].
-
flipForFFT
(u_k_part)¶ We flip as \(f_k = f_{N-k}\). Notice that only \(0,\ldots,N-1\) entries stored. This is useful for constructing real-valued function representations from random coefficients. Real-valued function requires \(conj(f_k) = f_{N-k}\). We can use this flip to construct from random coefficients the term \(u_k = f_k + conj(flip(f_k))\), then above constraint is satisfied.
- Parameters
a (Tensor) – 1d array to flip.
- Returns
The flipped tensors symmetric under conjucation.
- Return type
Tensor
-
getComplex
(a, b)¶
-
getRealImag
(c)¶
-
to
(device)¶
-
-
class
dataset.
diffOp2
(op_type='\Delta{u}', op_params=None, gen_mode='exp1', gen_params={'alpha1': 0.1}, num_samples=10000, nchannels=1, nx=15, ny=15, flag_verbose=0, **extra_params)¶ Generates samples of the form \((u^{[i]},f^{[i]})\) where \(f^{[i]} = L[u^{[i]}]\), where \(i\) denotes the index of the sample.
Stores data samples in the form \((u,f)\).
The samples of u are represented as a tensor of size [nsamples,nchannels,nx] and sample of f as a tensor of size [nsamples,nchannels,nx].
Note
For now, please use nx that is odd. In this initial implementation, we use a method based on conjugated flips with formula for the odd case which is slightly simpler than other case.
-
__getitem__
(index)¶
-
__init__
(op_type='\\Delta{u}', op_params=None, gen_mode='exp1', gen_params={'alpha1': 0.1}, num_samples=10000, nchannels=1, nx=15, ny=15, flag_verbose=0, **extra_params)¶ Setup for data generation.
- Parameters
op_type (str) – The differential operator to sample.
op_params (dict) – The operator parameters.
gen_mode (str) – The mode for the data generator.
gen_params (dict) – The parameters for the given generator.
num_samples (int) – The number of samples to generate.
nchannels (int) – The number of channels.
nx (int) – The number of input sample points in x-direction.
ny (int) – The number of input sample points in y- direction.
flag_verbose (int) – Level of reporting during calculations.
extra_params (dict) – Extra parameters for the sampler.
- For extra_params we have:
noise_factor (float): The amount of noise to add to samples. scale_factor (float): A factor to scale magnitude of the samples. flagComputeL (bool): If the fourier symbol of operator should be computed.
- For generator modes we have:
- gen_mode == ‘exp1’:
alpha1 (float): The decay rate.
Note
For now, please use only nx that is odd. In this initial implementation, we use a method based on conjugated flips with formula for the odd case which is slightly simpler than other case.
-
__len__
()¶
-
__module__
= 'dataset'¶
-
computeActionL
(u, L_hat)¶ Computes the action of operator L used for data generation.
-
computeCoeffActionL
(u_hat, L_hat)¶ Computes the action of operator L used for data generation in Fourier space.
-
computeLSymbol_grad_u
()¶ Compute associated Fourier symbols for use under DFT for the operator L[u].
-
computeLSymbol_laplacian_u
()¶ Compute associated Fourier symbols for use under DFT for the operator L[u].
-
flipForFFT
(u_k_part)¶ We flip as \(f_k = f_{N-k}\). Notice that only \(0,\ldots,N-1\) entries stored. This is useful for constructing real-valued function representations from random coefficients. Real-valued function requires \(conj(f_k) = f_{N-k}\). We can use this flip to construct from random coefficients the term \(u_k = f_k + conj(flip(f_k))\), then above constraint is satisfied.
- Parameters
a (Tensor) – 1d array to flip.
- Returns
The flipped tensors symmetric under conjucation.
- Return type
Tensor
-
getComplex
(a, b)¶
-
getRealImag
(c)¶
-
to
(device)¶
-