def convert_rail_to_trapezium_event(railway_system, rail_key):
    a = railway_system[rail_key][0].a
    beginning = railway_system[rail_key][0].b
    ending = railway_system[rail_key][1].a
    b = railway_system[rail_key][1].b

    return TemporalEventTrapezium(a, b, beginning, ending)
示例#2
0
    def animate(self, t):
        interval = self.interval
        B = TemporalEventTrapezium(interval[t], interval[t] + self.event_b_length_total,
                                   interval[t] + self.event_b_length_beginning,
                                   interval[t] + self.event_b_length_middle)
        plt.figure()
        B.plot().show()
        a_b = (self.event_a * B).to_list()
        b_c = (B * self.event_c).to_list()
        self.line_b.set_data(B, B.membership_function)
        artists = []
        for rect, h in zip(self.rects_a_b, a_b):
            rect.set_height(h)
            artists.append(rect)

        for rect, h in zip(self.rects_b_c, b_c):
            rect.set_height(h)
            artists.append(rect)

        artists.append(self.line_a)
        artists.append(self.line_b)
        artists.append(self.line_c)
        return artists
示例#3
0
    def animate(self, t):
        interval = self.interval
        B = TemporalEventTrapezium(interval[t],
                                   interval[t] + self.event_b_length_total,
                                   interval[t] + self.event_b_length_beginning,
                                   interval[t] + self.event_b_length_middle)
        plt.figure()
        B.plot().show()
        a_b = (self.event_a * B).to_list()
        b_c = (B * self.event_c).to_list()
        self.line_b.set_data(B, B.membership_function)
        artists = []
        for rect, h in zip(self.rects_a_b, a_b):
            rect.set_height(h)
            artists.append(rect)

        for rect, h in zip(self.rects_b_c, b_c):
            rect.set_height(h)
            artists.append(rect)

        artists.append(self.line_a)
        artists.append(self.line_b)
        artists.append(self.line_c)
        return artists
示例#4
0
        artists = []
        for rect, h in zip(self.rects_a_b, a_b):
            rect.set_height(h)
            artists.append(rect)

        for rect, h in zip(self.rects_b_c, b_c):
            rect.set_height(h)
            artists.append(rect)

        artists.append(self.line_a)
        artists.append(self.line_b)
        artists.append(self.line_c)
        return artists

    def show(self):
        fr = len(self.interval) - 1
        anim = animation.FuncAnimation(self.fig,
                                       self.animate,
                                       init_func=self.init,
                                       frames=fr,
                                       interval=fr,
                                       blit=True)
        self.plt.show()


if __name__ == '__main__':
    anim = Animation(TemporalEventTrapezium(4, 8, 5, 7),
                     TemporalEventTrapezium(0, 10, 6, 9),
                     TemporalEventTrapezium(0.5, 11, 1, 3))
    # anim.show()
示例#5
0
文件: demo.py 项目: AdolphLua/opencog
__author__ = 'sebastian'

from spatiotemporal.temporal_events.trapezium import TemporalEventTrapezium
from spatiotemporal.temporal_events.relation_formulas import FormulaCreator
from spatiotemporal.temporal_events.composition.non_linear_least_squares import DecompositionFitter

import matplotlib.pyplot as plt


all_relations = "pmoFDseSdfOMP"

a = TemporalEventTrapezium(1, 12, 4, 8)
b = TemporalEventTrapezium(9, 17, 13, 15)

# compute relations between events
temporal_relations = a * b
print("Relations: {0}".format(temporal_relations.to_list()))
# print degree for every relation
for relation in all_relations:
    print(relation, temporal_relations[relation])

# plot events
a.plot(show_distributions=True).ylim(ymin=-0.1, ymax=1.1)
b.plot(show_distributions=True).figure()
plt.show()

# from the 13 relations, learns parameters for all combinations of the
# before, same, and after relationships between the beginning and
# ending distributions of the two intervals
formula = FormulaCreator(DecompositionFitter(temporal_relations))
# from these relationships, computes the 13 relations again
if __name__ == '__main__':
    from spatiotemporal.temporal_events.trapezium import generate_random_events
    from spatiotemporal.temporal_events.util import compute_railway_strength
    import numpy
    from spatiotemporal.temporal_events import RelationFormulaConvolution

    search_tree = DepthFirstSearchComposition()
    formula = RelationFormulaConvolution()
    # A, B, C = generate_random_events(3)
    # for event in [A, B, C]:
    #     p = ''
    #     for point in [event.a, event.b, event.beginning, event.ending]:
    #         p += str((point - A.a) / (A.beginning - A.a)) + ', '
    #     print p

    A = TemporalEventTrapezium(0, 30, 10, 20)
    B = TemporalEventTrapezium(1, 9, 2, 8)
    C = TemporalEventTrapezium(0, 30, 10, 20)

    actual_solution = (A * C).to_vector()
    print 'Actual\n', actual_solution

    goal = []
    events = {'A': A, 'B': B, 'C': C}
    for a_key, b_key in [('A', 'B'), ('B', 'C')]:
        a, b = events[a_key], events[b_key]
        for portion_index_a in [0, 1]:
            for portion_index_b in [0, 1]:
                relation = formula.compare(a[portion_index_a], b[portion_index_b])
                goal.append(relation)
                search_tree.add_relation(a_key, portion_index_a, b_key, portion_index_b, relation)
示例#7
0
__author__ = 'sebastian'

from spatiotemporal.temporal_events.trapezium import TemporalEventTrapezium
from spatiotemporal.temporal_events.relation_formulas import FormulaCreator
from spatiotemporal.temporal_events.composition.non_linear_least_squares import DecompositionFitter

import matplotlib.pyplot as plt

all_relations = "pmoFDseSdfOMP"

a = TemporalEventTrapezium(1, 12, 4, 8)
b = TemporalEventTrapezium(9, 17, 13, 15)

# compute relations between events
temporal_relations = a * b
print("Relations: {0}".format(temporal_relations.to_list()))
# print degree for every relation
for relation in all_relations:
    print(relation, temporal_relations[relation])

# plot events
a.plot(show_distributions=True).ylim(ymin=-0.1, ymax=1.1)
b.plot(show_distributions=True).figure()
plt.show()

# from the 13 relations, learns parameters for all combinations of the
# before, same, and after relationships between the beginning and
# ending distributions of the two intervals
formula = FormulaCreator(DecompositionFitter(temporal_relations))
# from these relationships, computes the 13 relations again
relations_estimate = formula.calculate_relations()


    from spatiotemporal.temporal_events.trapezium import TemporalEventTrapezium
    # f = CombinationFormulaGeometricMeanTrapezium()
    # rf = RelationFormulaGeometricMean()
    # a, b_beg, b_end = uniform(5, 2), uniform(1, 3), uniform(8, 4)
    # [a_h], b_end_h = f.unpack(rf.compare(a, b_beg), rf.compare(a, b_end))
    #
    # print a_h.args, b_end_h.args
    # print rf.compare(a, b_beg), rf.compare(a, b_end)
    # print rf.compare(a_h, uniform_reference), rf.compare(a_h, b_end_h)
    #
    # quit()

    A = TemporalEventTrapezium(2, 7, 5, 6)
    B = TemporalEventTrapezium(1, 6, 3, 4)
    C = TemporalEventTrapezium(0, 9, 7, 8)

    f = CombinationFormulaGeometricMeanTrapezium()
    rf = RelationFormulaGeometricMean()
    # print rf.compare(f.unpack((1, 0, 0))[0], uniform(0, 1))

    A_, B_beg, B_end, C_ = A.distribution_beginning, B.distribution_beginning, B.distribution_ending, C.distribution_beginning
    # A, B, C = C.distribution_beginning, B.distribution_beginning, A.distribution_beginning
    print f.combine(rf.compare(A_, B_beg),
                    rf.compare(A_, B_end),
                    rf.compare(B_beg, C_),
                    rf.compare(B_end, C_))
    print rf.compare(A_, C_)