コード例 #1
0
ファイル: vulnerability_model.py プロジェクト: dynaryu/eqrm
 def __init__(self, 
              func_id,
              mean_loss_ratio, 
              coefficient_of_variation,
              distribution,
              var_method=2):
     self.function_id = func_id
     self.mean_loss_ratio = asarray(mean_loss_ratio)
     self.coefficient_of_variation = asarray(coefficient_of_variation)
     
     # Support lognormal and normal only initially 
     # (this could be covered in xsd validation)
     if distribution == 'N':
         self.distribution = Distribution_Normal(var_method=var_method)
     elif distribution == 'LN':
         self.distribution = Distribution_Log_Normal(var_method=var_method)
     else:
         raise NotImplementedError(
             '%s: %s is not a supported probabilistic distribution' % (func_id,
                                                                       distribution))
コード例 #2
0
    def __init__(self,
                 func_id,
                 mean_loss_ratio,
                 coefficient_of_variation,
                 distribution,
                 var_method=2):
        self.function_id = func_id
        self.mean_loss_ratio = asarray(mean_loss_ratio)
        self.coefficient_of_variation = asarray(coefficient_of_variation)

        # Support lognormal and normal only initially
        # (this could be covered in xsd validation)
        if distribution == 'N':
            self.distribution = Distribution_Normal(var_method=var_method)
        elif distribution == 'LN':
            self.distribution = Distribution_Log_Normal(var_method=var_method)
        else:
            raise NotImplementedError(
                '%s: %s is not a supported probabilistic distribution' %
                (func_id, distribution))
コード例 #3
0
ファイル: vulnerability_model.py プロジェクト: dynaryu/eqrm
class Vulnerability_Function(object):
    """
    A vulnerability function defined by a specified set of points on a curve.

    Methods:
    - calc_mean - return mean loss and sigma based on the given set of points
    - sample - return a sample based on the specified probabilistic distribution
    
    Constructor input:
    - func_id - identifier for this function
    - mean_loss_ratio - array of ratio points
    - coefficient_of_variation - array of uncertainty points (shape must match 
      shape of mean_loss_ratio)
    - distribution - either normal ('N') or lognormal ('LN')
    - var_method - variability method to be used in sampling (see sample doc)
    """
    
    def __init__(self, 
                 func_id,
                 mean_loss_ratio, 
                 coefficient_of_variation,
                 distribution,
                 var_method=2):
        self.function_id = func_id
        self.mean_loss_ratio = asarray(mean_loss_ratio)
        self.coefficient_of_variation = asarray(coefficient_of_variation)
        
        # Support lognormal and normal only initially 
        # (this could be covered in xsd validation)
        if distribution == 'N':
            self.distribution = Distribution_Normal(var_method=var_method)
        elif distribution == 'LN':
            self.distribution = Distribution_Log_Normal(var_method=var_method)
        else:
            raise NotImplementedError(
                '%s: %s is not a supported probabilistic distribution' % (func_id,
                                                                          distribution))
    
    def calc_mean(self, intensity, intensity_measure_level):
        """
        Calculate mean loss ratio and sigma based on the specified points on 
        the curve:
                        |
                        |                                +
                        |                           +
        Mean loss ratio |                     +
                        |               +
                        |            +
                        |          +
                        |         +
                        |        +
                        |       +
                        |    +
                        | +
                        +-----------------------------------
                               Intensity measure level
        
        For a given intensity, mean loss and sigma is determined by linearly
        interpolating the points on the curve.
        
        Note that sigma is calculated as cv * mean loss as cv = mean loss/sigma
        """
        mean_loss = interp(intensity, 
                           intensity_measure_level, 
                           self.mean_loss_ratio)
        cv = interp(intensity, 
                    intensity_measure_level, 
                    self.coefficient_of_variation)
        # cv = sigma / mean
        sigma = cv * mean_loss
        
        return (mean_loss, sigma)
    
    def sample(self, mean, sigma):
        """
        Take a sample based on the given mean and sigma. The distribution used
        is either normal or lognormal, and based on the specified variability
        method:
        
        None -> no sampling (mean loss is the deterministic figure)
        2 -> random sampling
        3 -> mean + 2 * sigma
        4 -> mean + sigma
        5 -> mean - sigma
        6 -> mean - 2 * sigma
        """
        
        # No period axis, so we want variability in the last axis
        var_in_last_axis = True
        return self.distribution.sample_for_eqrm(mean, sigma, var_in_last_axis)
コード例 #4
0
class Vulnerability_Function(object):
    """
    A vulnerability function defined by a specified set of points on a curve.

    Methods:
    - calc_mean - return mean loss and sigma based on the given set of points
    - sample - return a sample based on the specified probabilistic distribution
    
    Constructor input:
    - func_id - identifier for this function
    - mean_loss_ratio - array of ratio points
    - coefficient_of_variation - array of uncertainty points (shape must match 
      shape of mean_loss_ratio)
    - distribution - either normal ('N') or lognormal ('LN')
    - var_method - variability method to be used in sampling (see sample doc)
    """
    def __init__(self,
                 func_id,
                 mean_loss_ratio,
                 coefficient_of_variation,
                 distribution,
                 var_method=2):
        self.function_id = func_id
        self.mean_loss_ratio = asarray(mean_loss_ratio)
        self.coefficient_of_variation = asarray(coefficient_of_variation)

        # Support lognormal and normal only initially
        # (this could be covered in xsd validation)
        if distribution == 'N':
            self.distribution = Distribution_Normal(var_method=var_method)
        elif distribution == 'LN':
            self.distribution = Distribution_Log_Normal(var_method=var_method)
        else:
            raise NotImplementedError(
                '%s: %s is not a supported probabilistic distribution' %
                (func_id, distribution))

    def calc_mean(self, intensity, intensity_measure_level):
        """
        Calculate mean loss ratio and sigma based on the specified points on 
        the curve:
                        |
                        |                                +
                        |                           +
        Mean loss ratio |                     +
                        |               +
                        |            +
                        |          +
                        |         +
                        |        +
                        |       +
                        |    +
                        | +
                        +-----------------------------------
                               Intensity measure level
        
        For a given intensity, mean loss and sigma is determined by linearly
        interpolating the points on the curve.
        
        Note that sigma is calculated as cv * mean loss as cv = mean loss/sigma
        """
        mean_loss = interp(intensity, intensity_measure_level,
                           self.mean_loss_ratio)
        cv = interp(intensity, intensity_measure_level,
                    self.coefficient_of_variation)
        # cv = sigma / mean
        sigma = cv * mean_loss

        return (mean_loss, sigma)

    def sample(self, mean, sigma):
        """
        Take a sample based on the given mean and sigma. The distribution used
        is either normal or lognormal, and based on the specified variability
        method:
        
        None -> no sampling (mean loss is the deterministic figure)
        2 -> random sampling
        3 -> mean + 2 * sigma
        4 -> mean + sigma
        5 -> mean - sigma
        6 -> mean - 2 * sigma
        """

        # No period axis, so we want variability in the last axis
        var_in_last_axis = True
        return self.distribution.sample_for_eqrm(mean, sigma, var_in_last_axis)