File: bounded.py

package info (click to toggle)
python-bumps 0.7.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,264 kB
  • sloc: python: 22,226; ansic: 4,973; cpp: 4,849; xml: 493; makefile: 163; perl: 108; sh: 101
file content (37 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (2)
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)