Exemplo n.º 1
0
    def update(self, *args, **kargs):
        self.prev = []
        self.residual_start = float("inf")
        self.max = float("inf")

        out = []
        input_list = args[0]
        ans = []


        #i = 1
        i = len(input_list) - 1
        begin = self.begin
        end = self.end

        domain_end = float('inf')
        if input_list:
            domain_end = input_list[len(input_list)-1][0]

        while i >= 0:
            # if i < len(input_list):
            if i > 0:
                b = (input_list[i - 1][0] - end, input_list[i][0] - begin, input_list[i - 1][1])
            else:
                b = (input_list[i][0] - end, input_list[i][0] - begin, input_list[i][1])

            if not out:
                out.insert(0, b)
            else:
                a = out[0]
                while (a[2] > b[2]) and (b[1] > a[1]):
                    out.pop(0)
                    a = out[0]
                if not intersect.intersects(a[0], a[1], b[0], b[1]):
                    out.insert(0, b)
                else:
                    if a[2] <= b[2]:
                        out.insert(0, (b[0], a[0], b[2]))
                    else:
                        out.pop(0)
                        if (a[1] > b[1]):
                            out.insert(0, (b[1], a[1], a[2]))
                        out.insert(0, (b[0], b[1], b[2]))

            i = i - 1

        for i, b in enumerate(out):
            if b[0] <= 0 and b[1] > 0:
                ans.append([0, b[2]])
            elif b[0] > 0:
                ans.append([b[0], b[2]])

            if i == len(out) - 1:
                ans.append([b[1], b[2]])

        return ans
    def update(self, *args, **kargs):
        out = []
        input_list = args[0]
        ans = []

        i = 1
        begin = self.begin
        end = self.end

        while i < len(input_list):
            b = (input_list[i - 1][0] + begin, input_list[i][0] + end,
                 input_list[i - 1][1])
            last = (input_list[i][0] + end, input_list[i][0] + end,
                    input_list[i][1])
            if not out:
                out.append(b)
            else:
                a = out[len(out) - 1]
                while (a[2] < b[2]) and (b[0] < a[0]):
                    del (out[len(out) - 1])
                    a = out[len(out) - 1]
                if not intersect.intersects(a[0], a[1], b[0], b[1]):
                    out.append(b)
                else:
                    if a[2] >= b[2]:
                        out.append((a[1], b[1], b[2]))
                    else:
                        del (out[len(out) - 1])
                        out.append((a[0], b[0], a[2]))
                        out.append((b[0], b[1], b[2]))
            if i == len(input_list) - 1:
                out.append(last)

            i = i + 1

        prev = float("nan")

        for i, b in enumerate(out):
            if b[2] != prev or i == len(out) - 1:
                ans.append([b[0], b[2]])
            prev = b[2]

        return ans
    def update(self, *args, **kargs):
        out = []
        input_list = args[0]
        ans = []
        self.prev = []
        self.residual_start = float("inf")
        self.max = float("inf")

        i = 1
        begin = self.begin
        end = self.end

        domain_end = float('inf')
        if input_list:
            domain_end = input_list[len(input_list) - 1][0]

        while i <= len(input_list):
            if i == 1 and begin > 0:
                out.append((0, input_list[0][0] + begin, float('inf')))

            if i < len(input_list):
                b = (input_list[i - 1][0] + begin, input_list[i][0] + end,
                     input_list[i - 1][1])
            else:
                b = (input_list[i - 1][0] + begin, input_list[i - 1][0] + end,
                     input_list[i - 1][1])

            if not out:
                out.append(b)
            else:
                a = out[len(out) - 1]
                while (a[2] > b[2]) and (b[0] < a[0]):
                    del (out[len(out) - 1])
                    a = out[len(out) - 1]
                if not intersect.intersects(a[0], a[1], b[0], b[1]):
                    out.append(b)
                else:
                    if a[2] <= b[2]:
                        out.append((a[1], b[1], b[2]))
                    else:
                        del (out[len(out) - 1])
                        if b[0] > a[0]:
                            out.append((a[0], b[0], a[2]))
                        out.append((b[0], b[1], b[2]))

            i = i + 1

        prev = float("nan")

        for i, b in enumerate(out):
            if b[2] != prev or i == len(out) - 1:
                ans.append([b[0], b[2]])

            if b[0] <= domain_end < b[1]:
                if b[0] < domain_end:
                    ans.append([domain_end, b[2]])
                break

            if i == len(out) - 1 and b[1] > b[0]:
                ans.append([b[1], b[2]])

            prev = b[2]

        return ans
Exemplo n.º 4
0
    def update(self, *args, **kargs):
        # get inputs
        input_list = args[0]
        ans = []
        out = self.prev
        self.prev = []

        begin = self.begin
        end = self.end

        if input_list:
            # update when the residuals start in this iteration
            self.residual_start = input_list[len(input_list) - 1][0] + begin
            if out:
                # update the last previous sample with current knowledge
                last_prev = out[len(out) - 1]
                first_now = input_list[0]
                del (out[len(out) - 1])
                out.append((last_prev[0], first_now[0] + end, last_prev[2]))

        i = 1
        while len(input_list) >= i:
            if i == len(input_list):
                b = (input_list[i - 1][0] + begin, input_list[i - 1][0] + end,
                     input_list[i - 1][1])
            else:
                b = (input_list[i - 1][0] + begin, input_list[i][0] + end,
                     input_list[i - 1][1])

            if not out:
                out.append(b)
            else:
                a = out[len(out) - 1]
                while (a[2] < b[2]) and (b[0] < a[0]):
                    del (out[len(out) - 1])
                    a = out[len(out) - 1]
                if not intersect.intersects(a[0], a[1], b[0], b[1]):
                    out.append(b)
                else:
                    if a[2] >= b[2]:
                        out.append((a[1], b[1], b[2]))
                    else:
                        del (out[len(out) - 1])
                        out.append((a[0], b[0], a[2]))
                        out.append((b[0], b[1], b[2]))
            i = i + 1

        prev = float("nan")

        for i, b in enumerate(out):
            if b[1] <= self.residual_start:
                if b[2] != prev or i == len(out) - 1:
                    ans.append([b[0], b[2]])
            elif b[0] < self.residual_start < b[1]:
                if b[2] != prev or i == len(out) - 1:
                    ans.append([b[0], b[2]])
                self.prev.append((self.residual_start, b[1], b[2]))
            else:
                self.prev.append(b)

            prev = b[2]

        return ans