Ejemplo n.º 1
0
    def __init__(self, alpha=0.1, beta=0.1):
        Function.__init__(self)
        self.uniformRNG = UniformRNG()
        self.betavariateRNG = _BetavariateRNG()

        self.alpha = make_function(alpha)
        self.beta = make_function(beta)
Ejemplo n.º 2
0
    def __init__(self, pairs, periodic=0):
        """
        Return a BPF instance.
        
        pair is the list of pairs (time, value).
        At lease the pairs should be passed, otherwise
        a ValueError exception is raised.
        
        if periodic is true the periodic version of
        the call operator is used.
        if periodic is false the aperiodic version of
        the call operator is used.
        
        >>> a = BPF([(0,1), (100, 20)])
        """

        Function.__init__(self)
        self.pairs = [(float(x), float(y)) for x, y in pairs]

        self._check_pairs()

        if len(self.pairs) < 2:
            raise ValueError('Two few pairs (%d)' % len(self.pairs))

        self.xStart, junk = self.pairs[0]  # x value of first
        self.xEnd, junk = self.pairs[-1]  # x value of last
        self.period = self.xEnd - self.xStart
        self._is_periodic = periodic
Ejemplo n.º 3
0
 def __init__(self, alpha = 0.1, beta = 0.1):
      Function.__init__(self)
      self.uniformRNG = UniformRNG()
      self.betavariateRNG = _BetavariateRNG()
      
      self.alpha = make_function(alpha)
      self.beta = make_function(beta)
Ejemplo n.º 4
0
    def __init__(self, pairs, periodic=0):
        """
        Return a BPF instance.
        
        pair is the list of pairs (time, value).
        At lease the pairs should be passed, otherwise
        a ValueError exception is raised.
        
        if periodic is true the periodic version of
        the call operator is used.
        if periodic is false the aperiodic version of
        the call operator is used.
        
        >>> a = BPF([(0,1), (100, 20)])
        """

        Function.__init__(self)
        self.pairs = [(float(x), float(y)) for x,y in pairs]

        self._check_pairs()
        
        if len(self.pairs) < 2:
            raise ValueError('Two few pairs (%d)' % len(self.pairs))
        
        self.xStart, junk = self.pairs[0] # x value of first
        self.xEnd, junk = self.pairs[-1] # x value of last
        self.period = self.xEnd - self.xStart 
        
        if periodic:
            self.__call__ = self._evaluate_periodic
        else:
            self.__call__ = self._evaluate_aperiodic
Ejemplo n.º 5
0
     def __init__(self, pair0, *pairs):
          Function.__init__(self)
          for pair in pairs:
                if type(pair) is not types.TupleType:
                     raise ValueError, 'pair (object, probability) expected. got %s', repr(pair)

          self.set = []
          for o, p in [pair0] + list(pairs):
                self.set.append(_PossibleChoice(o, make_function(p)))
Ejemplo n.º 6
0
    def __init__(self, pair0, *pairs):
        Function.__init__(self)
        for pair in pairs:
            if type(pair) is not types.TupleType:
                raise ValueError, "pair (object, probability) expected. got %s", repr(pair)

        self.set = []
        for o, p in [pair0] + list(pairs):
            self.set.append(_PossibleChoice(o, make_function(p)))
Ejemplo n.º 7
0
    def __init__(self, pair, *pairs):
        Function.__init__(self)

        pairs = [pair] + list(pairs)

        self.set = []
        for o, p in pairs:
            self.set.append(_PossibleChoice(o, p))

        sum = reduce(lambda x, y: x + y, [possible_choice.probability for possible_choice in self.set])
        self.set = map(_MarkAccumulator(sum), self.set)
Ejemplo n.º 8
0
     def __init__(self, pair, *pairs):
          Function.__init__(self)

          pairs = [pair] + list(pairs)
          
          self.set = []
          for o, p in pairs:
                self.set.append(_PossibleChoice(o, p))

          sum = reduce(lambda x,y: x+y, 
                  [possible_choice.probability for possible_choice in self.set])
          self.set = map(_MarkAccumulator(sum), self.set)
Ejemplo n.º 9
0
    def __init__(self,
                 value_generator,
                 mode='unbound',
                 lower=None,
                 upper=None,
                 sum0=0):
        """
          Return an Accumulator instance.

          If mode is 'unbound' (default value) the accumulation is not limited.
          
          If mode is 'reflect' or 'r' or 'mirror' or 'm', the Accumulator folds values
          inside the [lower, upper] range. lower and upper must be specified and may be
          functions.

          If mode 'wrap' or 'w', the Accumulator performs a wrap around at the
          lower and upper limits. lower and upper must be specified and may be
          functions.

          An Accumulator can be initialized by passing the sum0 argument.
          """
        Function.__init__(self)

        self.generator = make_function(value_generator)
        self.sum = sum0

        if mode in ['unbound', 'u']:
            self.add = self.noBounds
        else:
            if upper is None or lower is None:
                raise ValueError(
                    'cannot create a bound accumulator with undefined bounds')

            self.upper = make_function(upper)
            self.lower = make_function(lower)
            if mode in ['limit', 'l']:
                self.add = self.limitAtBounds
            elif mode in ['reflect', 'r', 'mirror', 'm']:
                self.add = self.reflectAtBounds
            elif mode in ['wrap', 'w']:
                self.add = self.wrapAtBounds
            else:
                raise ValueError(
                    "mode can only be 'unbound', 'limit', 'reflect', 'mirror' or 'wrap' (got %s)"
                    % mode)
Ejemplo n.º 10
0
    def __init__(self, value_generator, mode="unbound", lower=None, upper=None, sum0=0):
        """
          Return an Accumulator instance.

          If mode is 'unbound' (default value) the accumulation is not limited.
          
          If mode is 'reflect' or 'r' or 'mirror' or 'm', the Accumulator folds values
          inside the [lower, upper] range. lower and upper must be specified and may be
          functions.

          If mode 'wrap' or 'w', the Accumulator performs a wrap around at the
          lower and upper limits. lower and upper must be specified and may be
          functions.

          An Accumulator can be initialized by passing the sum0 argument.
          """
        Function.__init__(self)

        self.generator = make_function(value_generator)
        self.sum = sum0

        if mode in ["unbound", "u"]:
            self.add = self.noBounds
        else:
            if upper is None or lower is None:
                raise ValueError, "cannot create a bound accumulator with undefined bounds"

            self.upper = make_function(upper)
            self.lower = make_function(lower)
            if mode in ["limit", "l"]:
                self.add = self.limitAtBounds
            elif mode in ["reflect", "r", "mirror", "m"]:
                self.add = self.reflectAtBounds
            elif mode in ["wrap", "w"]:
                self.add = self.wrapAtBounds
            else:
                raise ValueError, "mode can only be 'unbound', 'limit', 'reflect', 'mirror' or 'wrap' (got %s)" % mode
Ejemplo n.º 11
0
 def __init__(self, mainFunction, lowerLimit, upperLimit, exp=0.0):
     Function.__init__(self)
     self.upperLimit = make_function(upperLimit)
     self.lowerLimit = make_function(lowerLimit)
     self.mainFunction = make_function(mainFunction)
     self.exponent = math.pow(2.0, exp)
Ejemplo n.º 12
0
 def __init__(self, generator, points, strength=1.0, exponent=0.0):
     Function.__init__(self)
     self.generator = make_function(generator)
     self.points = make_function(points)
     self.strength = make_function(strength)
     self.exponent = make_function(exponent)
Ejemplo n.º 13
0
 def __init__(self, generator, delta, strength=1.0, offset=0.0):
     Function.__init__(self)
     self.generator = make_function(generator)
     self.delta = make_function(delta)
     self.strength = make_function(strength)
     self.offset = make_function(offset)
Ejemplo n.º 14
0
 def __init__(self, frequency=1.0, phase0=0.0):
     Function.__init__(self)
     self.frequency = frequency
     self.phase0 = phase0
Ejemplo n.º 15
0
 def __init__(self, lambd=1.0):
     Function.__init__(self)
     self.lambd = make_function(lambd)
     self.expovariateRNG = _ExpovariateRNG()
     self.uniformRNG = UniformRNG()
Ejemplo n.º 16
0
 def __init__(self, mainFunction, lowerLimit, upperLimit, exp = 0.0):
      Function.__init__(self)
      self.upperLimit = make_function(upperLimit)
      self.lowerLimit = make_function(lowerLimit)
      self.mainFunction = make_function(mainFunction)
      self.exponent = math.pow(2.0, exp)
Ejemplo n.º 17
0
 def __init__(self, generator, points, strength = 1.0, exponent = 0.0):
      Function.__init__(self)
      self.generator = make_function(generator)
      self.points = make_function(points)
      self.strength = make_function(strength)
      self.exponent = make_function(exponent)
Ejemplo n.º 18
0
 def __init__(self, generator, delta, strength = 1.0, offset = 0.0):
      Function.__init__(self)
      self.generator = make_function(generator)
      self.delta = make_function(delta)
      self.strength = make_function(strength)
      self.offset = make_function(offset)
Ejemplo n.º 19
0
 def __init__(self, frequency=1.0, phase0=0.0):
     Function.__init__(self)
     self.frequency = frequency
     # this is time per period
     self.T = None  # require when called
     self.phase0 = phase0
Ejemplo n.º 20
0
 def __init__(self, mu = 0.5, sigma = 0.1):
      Function.__init__(self)
      self.mu = make_function(mu)
      self.sigma = make_function(sigma)
      self.gaussRNG = _GaussRNG()
Ejemplo n.º 21
0
 def __init__(self, alpha=0.1, mu=0.5):
     Function.__init__(self)
     self.alpha = make_function(alpha)
     self.mu = make_function(mu)
     self.uniformRNG = UniformRNG()
Ejemplo n.º 22
0
 def __init__(self, mu=0.5, sigma=0.1):
     Function.__init__(self)
     self.mu = make_function(mu)
     self.sigma = make_function(sigma)
     self.gaussRNG = _GaussRNG()
Ejemplo n.º 23
0
 def __init__(self, frequency=1.0, phase0=0.0):
     Function.__init__(self)
     self.frequency = frequency
     self.phase0 = phase0
     self.T = None  # require when called
Ejemplo n.º 24
0
 def __init__(self, lambd = 1.0):
      Function.__init__(self)
      self.lambd = make_function(lambd)
      self.expovariateRNG = _ExpovariateRNG()
      self.uniformRNG = UniformRNG()
Ejemplo n.º 25
0
 def __init__(self, alpha = 0.1, mu = 0.5):
      Function.__init__(self)
      self.alpha = make_function(alpha)
      self.mu = make_function(mu)
      self.uniformRNG = UniformRNG()