<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
This module defines the computations used in the
probabilistic scenario. For more information, take a look at the
scientific model at <http://to_be_defined>.
"""

class Curve(object):
    """This class defines a curve (discrete function)
    
    used in the risk domain.
    """
    
    def __init__(self, values):
        self.values = values
    
    @property
    def domain(self):
        return self.values.keys()
    
    def get_for(self, x_value):
        """Returns the y value (codomain) for the given x value (domain)."""
        
        return self.values[x_value]
    
    def __eq__(self, other):
        return self.values == other.values

EMPTY_CURVE = Curve({})

def compute_loss_curve(loss_ratio_curve, asset):
    """Computes the loss curve for the given loss ratio curve."""
    
    # invalid asset
    if not asset: return EMPTY_CURVE
    
    loss_curve_values = {}
    
    for loss_ratio in loss_ratio_curve.domain:
        loss_curve_values[loss_ratio * asset] = \
                loss_ratio_curve.get_for(loss_ratio)
    
    return Curve(loss_curve_values)<commit_msg>Refactored Curve class<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
This module defines the computations used in the
probabilistic scenario. For more information, take a look at the
scientific model at <http://to_be_defined>.
"""

class Curve(object):
    """This class defines a curve (discrete function)
    
    used in the risk domain.
    """
    
    def __init__(self, values):
        self.values = values
    
    def __eq__(self, other):
        return self.values == other.values

EMPTY_CURVE = Curve({})

def compute_loss_curve(loss_ratio_curve, asset):
    """Computes the loss curve for the given loss ratio curve."""
    
    # invalid asset
    if not asset: return EMPTY_CURVE
    
    loss_curve_values = {}
    for loss_ratio, probability_occurrence \
            in loss_ratio_curve.values.iteritems(): \
            loss_curve_values[loss_ratio * asset] = probability_occurrence
    
    return Curve(loss_curve_values)
{'fraction_non_alphanumeric': 0.09289099526066351, 'fraction_numerical': 0.0009478672985781991, 'mean_word_length': 2.859232175502742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3732510', 'n_tokens_mistral': 650, 'n_tokens_neox': 626, 'n_words': 189}