Exemplo n.º 1
0
class LogNormalCDF(Base):
    """
    The log normal CDF response model for components.
    """

    median = _Element('float', 'Median of the log normal CDF.',
                      _Element.NO_DEFAULT, [lambda x: float(x) > 0.])

    beta = _Element('float', 'Log standard deviation of the log normal CDF',
                    _Element.NO_DEFAULT, [lambda x: float(x) > 0.])

    lower_limit = _Element(
        'float',
        'lower limit of function if part of piecewise function',
        None,
        [lambda x: float(x) > 0.])

    upper_limit = _Element(
        'float',
        'upper limit of function  if part of piecewise function',
        None,
        [lambda x: float(x) > 0.])

    def __call__(self, hazard_intensity):
        """
        In scipy lognormal CDF is implemented thus:
            scipy.stats.lognorm.cdf(x, s, loc=0, scale=1)
        where,
            s = sigma   # or beta or standard deviation
            scale = exp(mean) = median
            loc is used to shift the distribution and commonly not used
        """
        return stats.lognorm.cdf(hazard_intensity,
                                 self.beta, loc=0, scale=self.median)
Exemplo n.º 2
0
class StepFunc(Base):
    """
    A response model that does not have a cumulative distribution
    function, rather a series of steps for damage.
    """
    xys = _Element('XYPairs', 'A list of X, Y pairs.', list,
        [lambda xy: [(float(x), float(y)) for x, y in xy]])

    lower_limit = _Element(
        'float',
        'lower limit of function if part of piecewise function',
        None,
        [lambda x: float(x) > 0.])

    upper_limit = _Element(
        'float',
        'upper limit of function  if part of piecewise function',
        None,
        [lambda x: float(x) > 0.])

    def __call__(self, hazard_intensity):
        """
        Note that intervals are closed on the right.
        """
        for x, y in self.xys:
            if hazard_intensity < x:
                return y
        raise ValueError('value is greater than all xs!')
Exemplo n.º 3
0
class Level0Recovery(Base):
    """
    Standard recovery for no damage.
    """
    recovery_mean = 0.00001
    recovery_std = 0.00001

    lower_limit = _Element('float', 'lower limit of function if part of piecewise function',
                           None, [lambda x: float(x) > 0.])
    upper_limit = _Element('float', 'upper limit of function  if part of piecewise function',
                           None, [lambda x: float(x) > 0.])

    def __call__(self, hazard_level):
        return 0.0
Exemplo n.º 4
0
class ConstantFunction(Base):
    """
    A function for defining a constant amplitude for a given range
    """
    amplitude = _Element('float', 'Constant amplitude of function',
                    _Element.NO_DEFAULT, [lambda x: float(x) >= 0.])

    lower_limit = _Element('float', 'lower limit of function if part of piecewise function',
                           None, [lambda x: float(x) > 0.])
    upper_limit = _Element('float', 'upper limit of function  if part of piecewise function',
                           None, [lambda x: float(x) > 0.])

    def __call__(self, hazard_intensity):
        return self.amplitude
Exemplo n.º 5
0
class NormalCDF(ResponseModel):
    mean = _Element('float', 'Mean of the normal or Gaussian CDF',
                    _Element.NO_DEFAULT, [lambda x: float(x) >= 0.])

    stddev = _Element('float', 'Standard deviation of the normal CDF',
                      _Element.NO_DEFAULT, [lambda x: float(x) > 0.])

    def __call__(self, value):
        """
        In scipy normal CDF is implemented thus:
            scipy.stats.norm.cdf(x, loc=0, scale=1)
        where,
        loc = Mean
        scale = Standard Deviation i.e. square root of Variance
        """
        return stats.norm.cdf(value, loc=self.mean, scale=self.stddev)
Exemplo n.º 6
0
class Level0Response(Base):
    """
    Standard response for no damage.
    """
    mode = 1
    damage_ratio = 0.0
    functionality = 1.0
    beta = 0.0
    median = 1.0

    lower_limit = _Element('float', 'lower limit of function if part of piecewise function',
                           None, [lambda x: float(x) > 0.])
    upper_limit = _Element('float', 'upper limit of function  if part of piecewise function',
                           None, [lambda x: float(x) > 0.])

    def __call__(self, hazard_level):
        return 0.0
Exemplo n.º 7
0
class NormalCDF(Base):
    """
    The normal CDF response model for components
    """
    # -----------------------------------------------
    norm_mean = _Element(
        'float',
        'Mean of the normal or Gaussian CDF',
        _Element.NO_DEFAULT,
        [lambda x: float(x) >= 0.])
    norm_stddev = _Element(
        'float',
        'Standard deviation of the normal CDF',
        _Element.NO_DEFAULT,
        [lambda x: float(x) > 0.])
    # -----------------------------------------------
    lower_limit = _Element(
        'float',
        'lower limit of function if part of piecewise function',
        -np.inf,
        [lambda x: float(x) > 0.])
    upper_limit = _Element(
        'float',
        'upper limit of function  if part of piecewise function',
        np.inf,
        [lambda x: float(x) > 0.])
    # -----------------------------------------------

    def __call__(self, data_point, inverse=False):
        """
        In scipy normal CDF is implemented thus:
            scipy.stats.norm.cdf(x, loc=0, scale=1)
        where,
        loc = Mean
        scale = Standard Deviation i.e. square root of Variance
        """
        if not inverse:
            return stats.norm.cdf(data_point,
                                  loc=self.norm_mean,
                                  scale=self.norm_stddev)
        elif inverse:
            return stats.norm.ppf(data_point,
                                  loc=self.norm_mean,
                                  scale=self.norm_stddev)
Exemplo n.º 8
0
class LogNormalCDF(ResponseModel):
    median = _Element('float', 'Median of the log normal CDF.',
                      _Element.NO_DEFAULT, [lambda x: float(x) > 0.])

    beta = _Element('float', 'Log standard deviation of the log normal CDF',
                    _Element.NO_DEFAULT, [lambda x: float(x) > 0.])

    def __call__(self, hazard_level):
        """
        In scipy lognormal CDF is implemented thus:
            scipy.stats.lognorm.cdf(x, s, loc=0, scale=1)
        where,
            s = sigma   # or beta or standard deviation
            scale = exp(mean) = median
            loc is used to shift the distribution and commonly not used
        """
        return stats.lognorm.cdf(hazard_level.hazard_intensity,
                                 self.beta,
                                 loc=0,
                                 scale=self.median)
Exemplo n.º 9
0
class StepFunc(ResponseModel):
    xys = _Element('XYPairs', 'A list of X, Y pairs.', list,
                   [lambda xy: [(float(x), float(y)) for x, y in xy]])

    def __call__(self, value):
        """
        Note that intervals are closed on the right.
        """

        for x, y in self.xys:
            if value < x:
                return y

        raise ValueError('value is greater than all xs!')