LambdaFunction¶
- class probnum.LambdaFunction(fn, input_shape, output_shape=())¶
Bases:
probnum.FunctionDefine a
Functionfrom a givencallable.Creates a
Functionfrom a givencallableand in- and output shapes. This provides a convenient interface to define aFunction.- Parameters
Examples
>>> import numpy as np >>> from probnum import LambdaFunction >>> fn = LambdaFunction(fn=lambda x: 2 * x + 1, input_shape=(2,), output_shape=(2,)) >>> fn(np.array([[1, 2], [4, 5]])) array([[ 3, 5], [ 9, 11]])
See also
FunctionCallable with a fixed in- and output shape.
Attributes Summary
Syntactic sugar for
len(input_shape).Shape of the function's input.
Syntactic sugar for
len(output_shape).Shape of the function's output.
Methods Summary
__call__(x)Evaluate the function at a given input.
Attributes Documentation
- input_shape¶
Shape of the function’s input.
For a scalar-input function, this is an empty tuple.
- output_shape¶
Shape of the function’s output.
For scalar-valued function, this is an empty tuple.
Methods Documentation
- __call__(x)¶
Evaluate the function at a given input.
The function is vectorized over the batch shape of the input.
- Parameters
x (
Union[_SupportsArray[dtype],_NestedSequence[_SupportsArray[dtype]],bool,int,float,complex,str,bytes,_NestedSequence[Union[bool,int,float,complex,str,bytes]]]) – shape=batch_shape +input_shape– (Batch of) input(s) at which to evaluate the function.- Returns
shape=
batch_shape +output_shape– Function evaluated at the given (batch of) input(s).- Return type
fx
- Raises
ValueError – If the shape of
xdoes not matchinput_shapealong its last dimensions.