Beispiel #1
0
    def __init__(self, distribution_beginning, distribution_ending,
                 bins=50, relation_formula=None):
        if not isinstance(distribution_beginning, rv_frozen):
            raise TypeError("'distribution_beginning' should be a scipy frozen distribution")
        if not isinstance(distribution_ending, rv_frozen):
            raise TypeError("'distribution_ending' should be a scipy frozen distribution")
        self._distribution_beginning = distribution_beginning
        self._distribution_ending = distribution_ending

        a, beginning = calculate_bounds_of_probability_distribution(distribution_beginning)
        ending, b = calculate_bounds_of_probability_distribution(distribution_ending)

        self._beginning = UnixTime(beginning)
        self._ending = UnixTime(ending)
        self.membership_function = MembershipFunction(self)
        bins_beginning = bins / 2
        bins_ending = bins - bins_beginning
        self.interval_beginning = TimeInterval(a, beginning, bins_beginning)
        self.interval_ending = TimeInterval(ending, b, bins_ending)
        list.__init__(self, self.interval_beginning + self.interval_ending)
        TimeInterval.__init__(self, a, b, bins)
        if relation_formula is None:
            relation_formula = RelationFormulaGeometricMean()
        elif not isinstance(relation_formula, BaseRelationFormula):
            raise TypeError("'relation_formula' should be of type 'BaseRelationFormula'")
        relation_formula.bounds[distribution_beginning] = self.a, self.beginning
        relation_formula.bounds[distribution_ending] = self.ending, self.b
        self._formula_creator = FormulaCreator(relation_formula)
    def __init__(self, dictionary_input_output):
        cdf_input_list, cdf_output_list = convert_dict_to_sorted_lists(dictionary_input_output)
        list.__init__(self, cdf_input_list)
        TimeInterval.__init__(self, self[0], self[-1], 2)
        self.cdf = FunctionPiecewiseLinear(dictionary_input_output, function_undefined=FUNCTION_ZERO)
        self.cdf.dictionary_bounds_function[(self.b, POSITIVE_INFINITY)] = FUNCTION_ONE
        pdf_output_list = []
        dictionary_bounds_function = {}
        for bounds in sorted(self.cdf.dictionary_bounds_function):
            a, b = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY] or b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            pdf_y_intercept = fabs(self.cdf.derivative((a + b) / 2.0))
            pdf_output_list.append(pdf_y_intercept)
            dictionary_bounds_function[bounds] = FunctionHorizontalLinear(pdf_y_intercept)

        self.pdf = FunctionComposite(dictionary_bounds_function, function_undefined=FUNCTION_ZERO, domain=self,
                                     is_normalised=True)

        self.roulette_wheel = []

        self._mean = 0
        for bounds in sorted(self.pdf.dictionary_bounds_function):
            (a, b) = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY] and b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            cdf = self.cdf.dictionary_bounds_function[bounds]
            pdf = self.pdf.dictionary_bounds_function[bounds]
            share = cdf(b)
            self.roulette_wheel.append((a, b, share))

            self._mean += (a + b) / 2.0 * pdf(a) * (b - a)
Beispiel #3
0
    def __init__(self,
                 distribution_beginning,
                 distribution_ending,
                 bins=50,
                 distribution_integral_limit=DISTRIBUTION_INTEGRAL_LIMIT):
        if not isinstance(distribution_beginning, rv_frozen):
            raise TypeError(
                "'distribution_beginning' should be a scipy frozen distribution"
            )
        if not isinstance(distribution_ending, rv_frozen):
            raise TypeError(
                "'distribution_ending' should be a scipy frozen distribution")
        if not 0 < distribution_integral_limit <= 1:
            raise TypeError(
                "'distribution_integral_limit' should be within (0, 1]")
        self._distribution_beginning = distribution_beginning
        self._distribution_ending = distribution_ending

        a, beginning = calculate_bounds_of_probability_distribution(
            distribution_beginning, distribution_integral_limit)
        ending, b = calculate_bounds_of_probability_distribution(
            distribution_ending, distribution_integral_limit)

        self._beginning = UnixTime(beginning)
        self._ending = UnixTime(ending)
        self.membership_function = MembershipFunction(self)
        bins_beginning = bins / 2
        bins_ending = bins - bins_beginning
        self.interval_beginning = TimeInterval(a, beginning, bins_beginning)
        self.interval_ending = TimeInterval(ending, b, bins_ending)
        list.__init__(self, self.interval_beginning + self.interval_ending)
        TimeInterval.__init__(self, a, b, bins)
    def __init__(self, dictionary_input_output):
        cdf_input_list, cdf_output_list = convert_dict_to_sorted_lists(
            dictionary_input_output)
        list.__init__(self, cdf_input_list)
        TimeInterval.__init__(self, self[0], self[-1], 2)
        self.cdf = FunctionPiecewiseLinear(dictionary_input_output,
                                           function_undefined=FUNCTION_ZERO)
        self.cdf.dictionary_bounds_function[(self.b,
                                             POSITIVE_INFINITY)] = FUNCTION_ONE
        pdf_output_list = []
        dictionary_bounds_function = {}
        for bounds in sorted(self.cdf.dictionary_bounds_function):
            a, b = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY
                     ] or b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            pdf_y_intercept = fabs(self.cdf.derivative((a + b) / 2.0))
            pdf_output_list.append(pdf_y_intercept)
            dictionary_bounds_function[bounds] = FunctionHorizontalLinear(
                pdf_y_intercept)
            #dictionary_bounds_function[bounds] = FunctionLinear(
            #    x_0=a, y_0=pdf_y_intercept - pdf_y_intercept / 2.0,
            #    x_1=b, y_1=pdf_y_intercept + pdf_y_intercept / 2.0)

        self.pdf = FunctionComposite(dictionary_bounds_function,
                                     function_undefined=FUNCTION_ZERO,
                                     domain=self,
                                     is_normalised=True)

        self.roulette_wheel = []
        #center_of_mass_lower_bound = 0
        #center_of_mass_set = False

        self._mean = 0
        for bounds in sorted(self.pdf.dictionary_bounds_function):
            (a, b) = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY
                     ] and b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            cdf = self.cdf.dictionary_bounds_function[bounds]
            pdf = self.pdf.dictionary_bounds_function[bounds]
            share = cdf(b)
            self.roulette_wheel.append((a, b, share))

            #if not center_of_mass_set and share > 0.5:
            #    self._center_of_mass = UnixTime(self._calculate_center_of_mass(center_of_mass_lower_bound, b))
            #    center_of_mass_set = True
            #center_of_mass_lower_bound = b

            self._mean += (a + b) / 2.0 * pdf(a) * (b - a)
    def __init__(self, dictionary_input_output):
        cdf_input_list, cdf_output_list = convert_dict_to_sorted_lists(dictionary_input_output)
        list.__init__(self, cdf_input_list)
        TimeInterval.__init__(self, self[0], self[-1], 2)
        self.cdf = FunctionPiecewiseLinear(dictionary_input_output, function_undefined=FUNCTION_ZERO)
        self.cdf.dictionary_bounds_function[(self.b, POSITIVE_INFINITY)] = FUNCTION_ONE
        pdf_output_list = []
        dictionary_bounds_function = {}
        for bounds in sorted(self.cdf.dictionary_bounds_function):
            a, b = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY] or b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            pdf_y_intercept = fabs(self.cdf.derivative((a + b) / 2.0))
            pdf_output_list.append(pdf_y_intercept)
            dictionary_bounds_function[bounds] = FunctionHorizontalLinear(pdf_y_intercept)
            #dictionary_bounds_function[bounds] = FunctionLinear(
            #    x_0=a, y_0=pdf_y_intercept - pdf_y_intercept / 2.0,
            #    x_1=b, y_1=pdf_y_intercept + pdf_y_intercept / 2.0)

        self.pdf = FunctionComposite(dictionary_bounds_function, function_undefined=FUNCTION_ZERO, domain=self,
                                     is_normalised=True)

        self.roulette_wheel = []
        #center_of_mass_lower_bound = 0
        #center_of_mass_set = False

        self._mean = 0
        for bounds in sorted(self.pdf.dictionary_bounds_function):
            (a, b) = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY] and b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            cdf = self.cdf.dictionary_bounds_function[bounds]
            pdf = self.pdf.dictionary_bounds_function[bounds]
            share = cdf(b)
            self.roulette_wheel.append((a, b, share))

            #if not center_of_mass_set and share > 0.5:
            #    self._center_of_mass = UnixTime(self._calculate_center_of_mass(center_of_mass_lower_bound, b))
            #    center_of_mass_set = True
            #center_of_mass_lower_bound = b

            self._mean += (a + b) / 2.0 * pdf(a) * (b - a)
    def __init__(self, dictionary_input_output):
        cdf_input_list, cdf_output_list = convert_dict_to_sorted_lists(
            dictionary_input_output)
        list.__init__(self, cdf_input_list)
        TimeInterval.__init__(self, self[0], self[-1], 2)
        self.cdf = FunctionPiecewiseLinear(dictionary_input_output,
                                           function_undefined=FUNCTION_ZERO)
        self.cdf.dictionary_bounds_function[(self.b,
                                             POSITIVE_INFINITY)] = FUNCTION_ONE
        pdf_output_list = []
        dictionary_bounds_function = {}
        for bounds in sorted(self.cdf.dictionary_bounds_function):
            a, b = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY
                     ] or b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            pdf_y_intercept = fabs(self.cdf.derivative((a + b) / 2.0))
            pdf_output_list.append(pdf_y_intercept)
            dictionary_bounds_function[bounds] = FunctionHorizontalLinear(
                pdf_y_intercept)

        self.pdf = FunctionComposite(dictionary_bounds_function,
                                     function_undefined=FUNCTION_ZERO,
                                     domain=self,
                                     is_normalised=True)

        self.roulette_wheel = []

        self._mean = 0
        for bounds in sorted(self.pdf.dictionary_bounds_function):
            (a, b) = bounds
            if a in [NEGATIVE_INFINITY, POSITIVE_INFINITY
                     ] and b in [NEGATIVE_INFINITY, POSITIVE_INFINITY]:
                continue
            cdf = self.cdf.dictionary_bounds_function[bounds]
            pdf = self.pdf.dictionary_bounds_function[bounds]
            share = cdf(b)
            self.roulette_wheel.append((a, b, share))

            self._mean += (a + b) / 2.0 * pdf(a) * (b - a)
Beispiel #7
0
    def __init__(self, distribution_beginning, distribution_ending,
                 bins=50, distribution_integral_limit=DISTRIBUTION_INTEGRAL_LIMIT):
        if not isinstance(distribution_beginning, rv_frozen):
            raise TypeError("'distribution_beginning' should be a scipy frozen distribution")
        if not isinstance(distribution_ending, rv_frozen):
            raise TypeError("'distribution_ending' should be a scipy frozen distribution")
        if not 0 < distribution_integral_limit <= 1:
            raise TypeError("'distribution_integral_limit' should be within (0, 1]")
        self._distribution_beginning = distribution_beginning
        self._distribution_ending = distribution_ending

        a, beginning = calculate_bounds_of_probability_distribution(distribution_beginning, distribution_integral_limit)
        ending, b = calculate_bounds_of_probability_distribution(distribution_ending, distribution_integral_limit)

        self._beginning = UnixTime(beginning)
        self._ending = UnixTime(ending)
        self.membership_function = MembershipFunction(self)
        bins_beginning = bins / 2
        bins_ending = bins - bins_beginning
        self.interval_beginning = TimeInterval(a, beginning, bins_beginning)
        self.interval_ending = TimeInterval(ending, b, bins_ending)
        list.__init__(self, self.interval_beginning + self.interval_ending)
        TimeInterval.__init__(self, a, b, bins)
Beispiel #8
0
 def __init__(self, a, b):
     TimeInterval.__init__(self, a, b, 1)
Beispiel #9
0
 def __init__(self, a, b):
     TimeInterval.__init__(self, a, b, 1)