1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# Boundary check
# ==============
#
# Check probability at boundaries.
#
# In this case we define the probability density function (PDF) directly
# in an n-dimensional uniform box.
#
# Ideally, the correlation plots and variable distributions will be uniform.
from bumps.names import *
# Adjust scale from 1e-150 to 1e+150 and you will see that DREAM is equally
# adept at filling the box.
scale = 1
# Uniform cost function.
def box(x):
return 0 if np.all(np.abs(x)<=scale) else np.inf
def diamond(x):
return 0 if np.sum(np.abs(x))<=scale else np.inf
# Wrap it in a PDF object which turns an arbitrary probability density into
# a fitting function. Give it a valid initial value, and set the bounds to
# a unit cube with one corner at the origin.
M = PDF(lambda a,b: box([a,b]))
#M = PDF(lambda a,b: diamond([a,b]))
M.a.range(-2*scale,2*scale)
M.b.range(-2*scale,2*scale)
# Make the PDF a fit problem that bumps can process.
problem = FitProblem(M)
|