Ejemplo n.º 1
0
    def __init__(self,
                 dictionary_input_output,
                 function_undefined=None,
                 is_normalised=False):
        self.input_list, self.output_list = convert_dict_to_sorted_lists(
            dictionary_input_output)

        dictionary_bounds_function = {}
        for i in xrange(1, len(self.input_list)):
            x_0, x_1 = self.input_list[i - 1], self.input_list[i]
            y_0, y_1 = self.output_list[i - 1], self.output_list[i]
            dictionary_bounds_function[(x_0, x_1)] = FunctionLinear(x_0=x_0,
                                                                    x_1=x_1,
                                                                    y_0=y_0,
                                                                    y_1=y_1)
        if NEGATIVE_INFINITY not in self.input_list:
            dictionary_bounds_function[(
                NEGATIVE_INFINITY, self.input_list[0])] = function_undefined
        if POSITIVE_INFINITY not in self.input_list:
            dictionary_bounds_function[(
                self.input_list[-1], POSITIVE_INFINITY)] = function_undefined
        FunctionComposite.__init__(self,
                                   dictionary_bounds_function,
                                   function_undefined=function_undefined,
                                   domain=self.input_list,
                                   is_normalised=is_normalised)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def __init__(self, dictionary_beginning, dictionary_ending, bins=50):
        input_list_beginning, output_list_beginning = convert_dict_to_sorted_lists(dictionary_beginning)
        for i in xrange(1, len(input_list_beginning)):
            if not dictionary_beginning[input_list_beginning[i]] > dictionary_beginning[input_list_beginning[i - 1]]:
                raise TypeError("values of 'dictionary_beginning' should be increasing in time")

        input_list_ending, output_list_ending = convert_dict_to_sorted_lists(dictionary_ending)
        for i in xrange(1, len(input_list_ending)):
            if not dictionary_ending[input_list_ending[i]] < dictionary_ending[input_list_ending[i - 1]]:
                raise TypeError("values of 'dictionary_ending' should be decreasing in time")
        dictionary_ending = {}
        for i, time_step in enumerate(input_list_ending):
            dictionary_ending[time_step] = output_list_ending[len(input_list_ending) - i - 1]
        input_list_ending, output_list_ending = convert_dict_to_sorted_lists(dictionary_ending)

        distribution_beginning = ProbabilityDistributionPiecewiseLinear(dictionary_beginning)
        distribution_ending = ProbabilityDistributionPiecewiseLinear(dictionary_ending)

        TemporalEvent.__init__(self, distribution_beginning, distribution_ending, bins=bins)
        self._list = sorted(set(input_list_beginning + input_list_ending))
        self.membership_function = FunctionPiecewiseLinear(self.to_dict(), FUNCTION_ZERO)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def __init__(self, dictionary_input_output, function_undefined=None, is_normalised=False):
        self.input_list, self.output_list = convert_dict_to_sorted_lists(dictionary_input_output)

        dictionary_bounds_function = {}
        for i in xrange(1, len(self.input_list)):
            x_0, x_1 = self.input_list[i - 1], self.input_list[i]
            y_0, y_1 = self.output_list[i - 1], self.output_list[i]
            dictionary_bounds_function[(x_0, x_1)] = FunctionLinear(x_0=x_0, x_1=x_1, y_0=y_0, y_1=y_1)
        if NEGATIVE_INFINITY not in self.input_list:
            dictionary_bounds_function[(NEGATIVE_INFINITY, self.input_list[0])] = function_undefined
        if POSITIVE_INFINITY not in self.input_list:
            dictionary_bounds_function[(self.input_list[-1], POSITIVE_INFINITY)] = function_undefined
        FunctionComposite.__init__(self, dictionary_bounds_function,
                                   function_undefined=function_undefined,
                                   domain=self.input_list,
                                   is_normalised=is_normalised)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)