class TemporalEventPiecewiseLinear(TimeIntervalListBased, BaseTemporalEvent): def __init__(self, input_list, output_list): TimeIntervalListBased.__init__(self, input_list) self.output_list = output_list self.membership_function = MembershipFunctionPiecewiseLinear( self, output_list) self.membership_function_single_point = self.membership_function def degree_in_interval(self, a=None, b=None, interval=None): interval = self._interval_from_self_if_none(a, b, interval) return self.membership_function_single_point.integrate( interval.a, interval.b) / (interval.b - interval.a) def to_list(self): result = [] for i, time_step in enumerate(self): if i == len(self) - 1 and self.output_list[len(self) - 1] == 0: result.append(UnixTime(time_step - EPSILON)) result.append(time_step) if i == 0 and self.output_list[0] == 0: result.append(UnixTime(time_step + EPSILON)) return result @TimeIntervalListBased.a.setter def a(self, value): TimeIntervalListBased.a.fset(value) self.membership_function.invalidate() @TimeIntervalListBased.b.setter def b(self, value): TimeIntervalListBased.b.fset(value) self.membership_function.invalidate() def __repr__(self): pairs = [ '{0}: {1}'.format(self[i], self.output_list[i]) for i in xrange(len(self)) ] return '{0}({1})'.format(self.__class__.__name__, ', '.join(pairs)) # Every time that self as list changes, or output_list # changes, membership_function should be invalidated # Here, only the two main methods that change the list content have been overridden # One can add more later if needed... def append(self, x): TimeIntervalListBased.append(self, x) self.membership_function.invalidate() def __setitem__(self, index, value): TimeIntervalListBased.__setitem__(self, index, value) self.membership_function.invalidate()
class TemporalEventPiecewiseLinear(TimeIntervalListBased, BaseTemporalEvent): def __init__(self, input_list, output_list): TimeIntervalListBased.__init__(self, input_list) self.output_list = output_list self.membership_function = MembershipFunctionPiecewiseLinear(self, output_list) self.membership_function_single_point = self.membership_function def degree_in_interval(self, a=None, b=None, interval=None): interval = self._interval_from_self_if_none(a, b, interval) return self.membership_function_single_point.integrate(interval.a, interval.b) / (interval.b - interval.a) def to_list(self): result = [] for i, time_step in enumerate(self): if i == len(self) - 1 and self.output_list[len(self) - 1] == 0: result.append(UnixTime(time_step - EPSILON)) result.append(time_step) if i == 0 and self.output_list[0] == 0: result.append(UnixTime(time_step + EPSILON)) return result @TimeIntervalListBased.a.setter def a(self, value): TimeIntervalListBased.a.fset(value) self.membership_function.invalidate() @TimeIntervalListBased.b.setter def b(self, value): TimeIntervalListBased.b.fset(value) self.membership_function.invalidate() def __repr__(self): pairs = ['{0}: {1}'.format(self[i], self.output_list[i]) for i in xrange(len(self))] return '{0}({1})'.format(self.__class__.__name__, ', '.join(pairs)) # Every time that self as list changes, or output_list # changes, membership_function should be invalidated # Here, only the two main methods that change the list content have been overridden # One can add more later if needed... def append(self, x): TimeIntervalListBased.append(self, x) self.membership_function.invalidate() def __setitem__(self, index, value): TimeIntervalListBased.__setitem__(self, index, value) self.membership_function.invalidate()
def __init__(self, input_list, output_list): TimeIntervalListBased.__init__(self, input_list) self.output_list = output_list self.membership_function = MembershipFunctionPiecewiseLinear( self, output_list) self.membership_function_single_point = self.membership_function
def __init__(self, input_list, output_list): TimeIntervalListBased.__init__(self, input_list) self.output_list = output_list self.membership_function = MembershipFunctionPiecewiseLinear(self, output_list) self.membership_function_single_point = self.membership_function