| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GenDecay::pdfrand Namespace Reference


Functions

def integrate
def make_cdf
def bisect
def make_user_distribution
def linear

Variables

tuple r = make_user_distribution(linear, lo, hi)

Function Documentation

def GenDecay::pdfrand::integrate (   f,
  lo,
  hi,
  steps = 1000 
)

Definition at line 7 of file pdfrand.py.

00007                                     :
00008     dx = (hi - lo) / steps
00009     lo += dx / 2
00010     return sum(f(i*dx + lo) * dx for i in range(steps))
00011 
def make_cdf(f, lo, hi, steps=1000):

def GenDecay::pdfrand::make_cdf (   f,
  lo,
  hi,
  steps = 1000 
)

Definition at line 12 of file pdfrand.py.

00012                                    :
00013     total_area = integrate(f, lo, hi, steps)
00014     def cdf(x):
00015         assert lo <= x <= hi
00016         return integrate(f, lo, x, steps) / total_area
00017     return cdf
00018 
def bisect(target, f, lo, hi, n=20):

def GenDecay::pdfrand::bisect (   target,
  f,
  lo,
  hi,
  n = 20 
)

Definition at line 19 of file pdfrand.py.

00019                                    :
00020     'Find x between lo and hi where f(x)=target'
00021     for i in range(n):
00022         mid = (hi + lo) / 2.0
00023         if target < f(mid):
00024             hi = mid
00025         else:
00026             lo = mid
00027     return (hi + lo) / 2.0
00028 
def make_user_distribution(f, lo, hi, steps=1000, n=20):

def GenDecay::pdfrand::make_user_distribution (   f,
  lo,
  hi,
  steps = 1000,
  n = 20 
)

Definition at line 29 of file pdfrand.py.

00029                                                        :
00030     cdf = make_cdf(f, lo, hi, steps)
00031     return lambda: bisect(random(), cdf, lo, hi, n)
00032 
if __name__ == '__main__':

def GenDecay::pdfrand::linear (   x  ) 

Definition at line 34 of file pdfrand.py.

00034                  :
00035         return 3 * x - 6
00036     lo, hi = 2, 10
    r = make_user_distribution(linear, lo, hi)


Variable Documentation

tuple GenDecay::pdfrand::r = make_user_distribution(linear, lo, hi) [static]

Definition at line 37 of file pdfrand.py.

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 21:01:10 2011 for GenDecay by doxygen 1.4.7