Lambda¶
-
class
baikal.steps.
Lambda
(compute_func, n_outputs=1, name=None, **kwargs)¶ Bases:
baikal._core.step.Step
Step for arbitrary functions.
- Parameters
compute_func – The function to make the step from. This function a single array-like object (in the case of a single input) or a list of array-like objects (in the case of multiple inputs) If compute_func takes additional arguments you may either pass them as keyword arguments or use a functools.partial object.
n_outputs – Number of outputs of the function.
name – Name of the step (optional). If no name is passed, a name will be automatically generated.
**kwargs – Additional arguments to compute_func.
Examples
def function(Xs): x1, x2 = Xs return 2 * x1, x2 / 2 x = Input() y1, y2 = Lambda(function, n_outputs=2)([x, x]) model = Model(x, [y1, y2]) x_data = np.array([[1.0, 2.0], [3.0, 4.0]]) y1_pred, y2_pred = model.predict(x_data) print(y1_pred) # [[2. 4.] # [6. 8.]] print(y2_pred) # [[0.5 1. ] # [1.5 2. ]]