Custom Noise CBX#
This notebook showcases, how to use a custom noise function.
[ ]:
from cbx.dynamics import CBO
import numpy as np
Define the custom noise function#
In this case we select that the noise should be zero
[ ]:
def custom_noise(dyn):
return np.zeros(dyn.drift.shape)
Define a loss function and test the method#
[ ]:
def f(x):
return np.linalg.norm(x, axis=-1)
x0 = np.random.normal(0,1,(4,7,26))
dyn_cn = CBO(f, x=x0, noise=custom_noise, max_it=10, verbosity = 0)
x_cn = dyn_cn.optimize()
Using this noise is equivalent to specifying sigma=0
with standard CBO. So let’s test, if this is the case:
[ ]:
dyn = CBO(f, x=x0, sigma=0, max_it=10, verbosity = 0)
x = dyn.optimize()
print('L-infinty Error between the custom noise solution and standard CBO with sigma=0: ' + str(np.abs(x-x_cn).max()))