In NIFTy, users can add hand-crafted point-wise nonlinearities that are then available for `Field`, `MultiField`, `Linearization` and `Operator`. This guide illustrates how this is done.
Suppose that we would like to use the point-wise function f(x) = x*exp(x) in an operator chain. This function is called "myptw" in the following. We introduce this function to NIFTy by implementing two functions.
First, one that takes a `numpy.ndarray` as an input, applies the point-wise mapping and returns the result as a `numpy.ndarray` of the same shape. Second, a function that takes a `numpy.ndarray` as an input and returns two `numpy.ndarray`s: the application of the nonlinearity (same as before) and the derivative.
%% Cell type:code id:modern-spouse tags:
``` python
deffunc(x):
returnx*np.exp(x)
deffunc_and_derv(x):
expx=np.exp(x)
returnx*expx,(1+x)*expx
```
%% Cell type:markdown id:shared-deficit tags:
These two functions are then added to the NIFTy-internal dictionary that contains all implemented point-wise nonlinearities.
Please remember to always check that the gradient has been implemented correctly by comparint it to an approximation to the gradient by finite differences.