torchphysics.problem.domains.functionsets package
Function sets can be used to sample functions, e.g. in DeepONet.
Submodules
torchphysics.problem.domains.functionsets.functionset module
- class torchphysics.problem.domains.functionsets.functionset.CustomFunctionSet(function_space, parameter_sampler, custom_fn)[source]
Bases:
FunctionSet
FunctionSet for an arbitrary function.
- Parameters:
function_space (torchphysics.spaces.FunctionSpace) – The space of which this set of functions belongs to. The inputs and outputs of this FunctionSet are defined by the corresponding values inside the function space.
parameter_sampler (torchphysics.samplers.PointSampler) –
A sampler that provides additional parameters that can be used to create different kinds of functions. E.g. our FunctionSet consists of Functions like k*x, x is the input variable and k is given through the sampler.
During each training iteration will call the parameter_sampler to sample new parameters. For each parameter a function will be created and the input batch of functions will be of the same length as the sampled parameters.
custom_fn (callable) – A function that describes the FunctionSet. The input of the functions can include the variables of the function_space.input_space and the parameters from the parameter_sampler.
- class torchphysics.problem.domains.functionsets.functionset.FunctionSet(function_space, parameter_sampler)[source]
Bases:
object
A set of functions that can supply samples from a function space.
- Parameters:
function_space (torchphysics.spaces.FunctionSpace) – The space of which this set of functions belongs to. The inputs and outputs of this FunctionSet are defined by the corresponding values inside the function space.
parameter_sampler (torchphysics.samplers.PointSampler) –
A sampler that provides additional parameters that can be used to create different kinds of functions. E.g. our FunctionSet consists of Functions like k*x, x is the input variable and k is given through the sampler.
During each training iteration will call the parameter_sampler to sample new parameters. For each parameter a function will be created and the input batch of functions will be of the same length as the sampled parameters.
- __add__(other)[source]
Combines two function sets.
Notes
When parameters are sampled, will sample them from both sets. Creates a batch of functions consisting of the batch of each set. (Length of the batches will be added)
- create_function_batch(points)[source]
Evaluates the underlying function object to create a batch of discrete function samples.
- Parameters:
points (torchphysics.spaces.Points) – The input points, where we want to evaluate a set of functions.
- Returns:
The batch of discrete function samples. The underlying tensor is of the shape: [len(self), len(points), self.function_space.output_space.dim]
- Return type:
torchphysics.spaces.Points
- sample_params(device='cpu')[source]
Samples parameters of the function space.
- Parameters:
device (str, optional) – The device, where the parameters should be created. Default is ‘cpu’.
Notes
We save the sampled parameters internally, so that we can use them multiple times. Since given a parameter we still have a continuous representation of the underlying function types. When the functions should be evaluated at some input points, we just have to create the meshgrid of parameters and points.
- class torchphysics.problem.domains.functionsets.functionset.FunctionSetCollection(function_sets)[source]
Bases:
FunctionSet
Collection of multiple FunctionSets. Used for the additions of different FunctionSets.
- __add__(other)[source]
Combines two function sets.
Notes
When parameters are sampled, will sample them from both sets. Creates a batch of functions consisting of the batch of each set. (Length of the batches will be added)
- create_function_batch(points)[source]
Evaluates the underlying function object to create a batch of discrete function samples.
- Parameters:
points (torchphysics.spaces.Points) – The input points, where we want to evaluate a set of functions.
- Returns:
The batch of discrete function samples. The underlying tensor is of the shape: [len(self), len(points), self.function_space.output_space.dim]
- Return type:
torchphysics.spaces.Points
- sample_params(device='cpu')[source]
Samples parameters of the function space.
- Parameters:
device (str, optional) – The device, where the parameters should be created. Default is ‘cpu’.
Notes
We save the sampled parameters internally, so that we can use them multiple times. Since given a parameter we still have a continuous representation of the underlying function types. When the functions should be evaluated at some input points, we just have to create the meshgrid of parameters and points.