~ubuntu-branches/ubuntu/raring/python-scipy/raring-proposed

« back to all changes in this revision

Viewing changes to Lib/sandbox/models/family/varfuncs.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-07 14:12:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070107141212-mm0ebkh5b37hcpzn
* Remove build dependency on python-numpy-dev.
* python-scipy: Depend on python-numpy instead of python-numpy-dev.
* Package builds on other archs than i386. Closes: #402783.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import numpy as N
 
2
 
 
3
class VarianceFunction:
 
4
    """
 
5
    Variance function that relates the variance of a random variable
 
6
    to its mean. Defaults to 1.
 
7
 
 
8
    """
 
9
 
 
10
    def __call__(self, mu):
 
11
        return N.ones(mu.shape, N.float64)
 
12
 
 
13
constant = VarianceFunction()
 
14
 
 
15
class Power:
 
16
 
 
17
    """
 
18
    Variance function:
 
19
 
 
20
    V(mu) = fabs(mu)**power
 
21
    """
 
22
 
 
23
    def __init__(self, power=1.):
 
24
        self.power = power
 
25
 
 
26
    def __call__(self, mu):
 
27
        return N.power(N.fabs(mu), self.power)
 
28
 
 
29
class Binomial:
 
30
 
 
31
    """
 
32
    Binomial variance function
 
33
 
 
34
    p = mu / n; V(mu) = p * (1 - p) * n
 
35
    """
 
36
 
 
37
    tol = 1.0e-10
 
38
 
 
39
    def __init__(self, n=1):
 
40
        self.n = n
 
41
 
 
42
    def clean(self, p):
 
43
        return N.clip(p, Binomial.tol, 1 - Binomial.tol)
 
44
 
 
45
    def __call__(self, mu):
 
46
        p = self.clean(mu / self.n)
 
47
        return p * (1 - p) * self.n
 
48
 
 
49
mu = Power()
 
50
mu_squared = Power(power=2)
 
51
mu_cubed = Power(power=3)
 
52
binary = Binomial()
 
53