Consensus Based Sampling#
[ ]:
%load_ext autoreload
%autoreload 2
from cbx.dynamics import CBS
from cbx.objectives import Quadratic
from cbx.plotting import PlotDynamicHistory
f = Quadratic()
dyn = CBS(f, d=5, M=3, max_it=1000, track_args={'names':['x']}, alpha=0.5)
dyn.run()
[ ]:
import matplotlib.pyplot as plt
from IPython import display
fig, ax = plt.subplots(1,)
pl = PlotDynamicHistory(dyn, ax=ax,objective_args={'x_min':-3, 'x_max':3},)
for i in range(0, pl.max_it,1):
pl.plot_at_ind(i)
pl.decorate_at_ind(i)
display.display(fig)
display.clear_output(wait=True)
plt.pause(0.1)