Пример #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)
Пример #2
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)
Пример #3
0
class LogNormalCDF(Base):
    """
    The lognormal 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.])

    location = _Element('float', 'Location parameter of the log normal CDF',
                        0.0, [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, data_point):
        """
        SciPy implementation of LogNormal CDF:
            scipy.stats.lognorm.cdf(x, s, loc=0, scale=1)
        where,
            s = sigma   # or beta or standard deviation (shape parameter)
            scale = exp(mean) = median
            loc is used to shift the distribution and commonly not used
        """
        return stats.lognorm.cdf(data_point,
                                 self.beta,
                                 loc=self.location,
                                 scale=self.median)
Пример #4
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
Пример #5
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
Пример #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
Пример #7
0
class RayleighCDF(Base):
    """
    The Rayliegh CDF response model for components.
    """
    scale = _Element('float',
                     'Scale parameter for Rayleigh CDF.',
                     _Element.NO_DEFAULT,
                     validators=[lambda x: float(x) > 0.])

    loc = _Element('float',
                   'Location parameter for Rayleigh CDF.',
                   default=0,
                   validators=[lambda x: float(x) >= 0.])

    def __call__(self, x):
        """
        SciPy implementation of Rayleigh CDF:
        loc = shift parameter
        scale = scaling parameter
        """
        return stats.rayleigh.cdf(x, loc=self.loc, scale=self.scale)
Пример #8
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!')