Exemple #1
0
def temporal_relation_between(temporal_event_1, temporal_event_2):
    temporal_event_1 = TemporalEventTrapezium(1, 10)
    temporal_event_2 = TemporalEventTrapezium(11, 16)

    sum_times = sorted([
        UnixTime(time).to_datetime()
        for time in set(temporal_event_1.to_list() +
                        temporal_event_2.to_list())
    ])
    sum_certainties = []
    for time_step in sum_times:
        sum_certainties.append(
            temporal_event_1.membership_function(time_step) +
            temporal_event_2.membership_function(time_step))

    result = {}

    formulas = {
        'p': beforeFormula,
        'm': meetsFormula,
        'o': overlapsFormula,
        'F': finished_byFormula,
        'D': containsFormula,
        's': startsFormula,
        'e': equalsFormula,
        'S': started_byFormula,
        'd': duringFormula,
        'f': finishesFormula,
        'O': overlapped_byFormula,
        'M': met_byFormula,
        'P': afterFormula
    }

    dist1, dist2 = temporal_event_1.to_dict(), temporal_event_2.to_dict()
    for name in formulas:
        degree = formulas[name](dist1, dist2)
        if degree > 0:
            result[name] = degree

    print result
    temporal_event_1.plot()
    plt = temporal_event_2.plot()
    plt.plot(sum_times, sum_certainties)
    plt.show()

    return result
Exemple #2
0
    def normalised(self):
        area = self.integral(NEGATIVE_INFINITY, POSITIVE_INFINITY)
        if equals(area, 0):
            area = self.integral(NEGATIVE_INFINITY, POSITIVE_INFINITY)
        dictionary_input_output = {}
        output_list = [y / area for y in self.output_list]
        for i in xrange(len(self.input_list)):
            dictionary_input_output[self.input_list[i]] = output_list[i]
        result = FunctionPiecewiseLinear(
            dictionary_input_output,
            function_undefined=self.function_undefined)
        result.is_normalised = True
        return result


if __name__ == '__main__':
    from spatiotemporal.temporal_events import TemporalEventTrapezium
    e = TemporalEventTrapezium(1, 10, 3, 8)
    print e
    mf = e.membership_function()
    print 'degree in [1 : 3]:', e.degree_in_interval(1, 3)
    print 'degree in [3 : 4]:', e.degree_in_interval(3, 4)
    print 'degree in [8 : 9]:', e.degree_in_interval(8, 9)
    print 'degree in [2 : 9]:', e.degree_in_interval(2, 9)
    print 'degree in [1 : 10]:', e.degree_in_interval()
    print 'degree in [11 : 17]:', e.degree_in_interval(11, 17)

    #a = FunctionLinear(None, None, 3, 0, -1, 1.0/9)
    #print (a(-0.25) + a(0.25))/4
    #print a(0.25) * 2.75 / 2
def temporal_relation_between(temporal_event_1, temporal_event_2):
    temporal_event_1 = TemporalEventTrapezium(1, 10)
    temporal_event_2 = TemporalEventTrapezium(11, 16)

    sum_times = sorted(
        [UnixTime(time).to_datetime() for time in set(temporal_event_1.to_list() + temporal_event_2.to_list())]
    )
    sum_certainties = []
    for time_step in sum_times:
        sum_certainties.append(temporal_event_1.membership_function(time_step) +
                               temporal_event_2.membership_function(time_step))

    result = {}

    formulas = {
        'p': beforeFormula,
        'm': meetsFormula,
        'o': overlapsFormula,
        'F': finished_byFormula,
        'D': containsFormula,
        's': startsFormula,
        'e': equalsFormula,
        'S': started_byFormula,
        'd': duringFormula,
        'f': finishesFormula,
        'O': overlapped_byFormula,
        'M': met_byFormula,
        'P': afterFormula
    }

    dist1, dist2 = temporal_event_1.to_dict(), temporal_event_2.to_dict()
    for name in formulas:
        degree = formulas[name](dist1, dist2)
        if degree > 0:
            result[name] = degree

    print result
    temporal_event_1.plot()
    plt = temporal_event_2.plot()
    plt.plot(sum_times, sum_certainties)
    plt.show()

    return result
Exemple #4
0
        assert len(self.input_list) == len(self.output_list) >= 2
        bounds_function_dictionary = {}
        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]
            bounds_function_dictionary[(x_0, x_1)] = FunctionLinear(x_0=x_0, x_1=x_1, y_0=y_0, y_1=y_1)
        bounds_function_dictionary[(MINUS_INFINITY, self.input_list[0])] = self.function_undefined
        bounds_function_dictionary[(self.input_list[-1], PLUS_INFINITY)] = self.function_undefined
        FunctionComposite.__init__(self, bounds_function_dictionary)

    def __getitem__(self, index):
        return self.output_list.__getitem__(index)

    def __len__(self):
        return len(self.output_list)

    def __iter__(self):
        return iter(self.output_list)

if __name__ == '__main__':
    from spatiotemporal.temporal_events import TemporalEventTrapezium
    e = TemporalEventTrapezium(1, 10, 3, 8)
    print e
    mf = e.membership_function()
    print 'degree in [1 : 3]:', e.degree_in_interval(1, 3)
    print 'degree in [3 : 4]:', e.degree_in_interval(3, 4)
    print 'degree in [8 : 9]:', e.degree_in_interval(8, 9)
    print 'degree in [2 : 9]:', e.degree_in_interval(2, 9)
    print 'degree in [1 : 10]:', e.degree_in_interval()
    print 'degree in [11 : 17]:', e.degree_in_interval(11, 17)