Пример #1
0
    def solve(self, pos):
        self.pos = pos

        ret1 = OvR.separate(self.matx, self.label, pos, self.m, self.n)

        mat, vec = Smote.genNew(ret1[0], ret1[1], self.n)
        #		mat, vec = BorderlineSmote.genNew(ret1[0], ret1[1], self.n)

        beta = Descent.solve(mat, vec)
        '''
		ensembleN = 5
		beta = np.zeros((self.n))
		for i in range(ensembleN):
			mat, vec = EasyEnsemble.genNew(ret1[0], ret1[1], self.n)
			beta = beta + Descent.solve(mat, vec)
		beta = beta / ensembleN
		'''
        print('beta', beta)

        return beta
Пример #2
0
for i in range(3, 10):

    # read from file

    with open('../data/Data/0' + str(i) + '/watch/raw_4_0_unsync.txt') as f:
        x = f.readlines()

    with open('../data/Data/10/watch/raw_1_0_unsync.txt') as f:
        x = f.readlines()

    data = []
    for e in x:
        data.append(map(float, e[:-1].split(' ')[1:-1]))

    #print len(data), len(data[0]), data[0]

    # --- get a gesture chunk ---

    d_obj = Descent()
    g_obj = WatchGesture()

    swipe_threshold = int(d_obj.median(data[0])) * 0.80
    touch_threshold = int(d_obj.median(data[0])) * 0.10

    #swipe_threshold, touch_threshold = d_obj.auto_thresh(data)

    y = g_obj.gd(data, swipe_threshold, 1)
    if len(y) > 3:
        print '~~~~\nSwipe Detected, Swipe gesture direction\n'
        print len(y), y
Пример #3
0
class Gesture(object):
    def __init__(self):
        self.m = 0
        self.y = []
        self.obj = Descent()

    def clearobj(self):
        self.m = 0
        self.y = []

    def gd(self, data, threshold, control=5):
        i = 0
        temp = -1
        y = []

        while i < len(data) - 1:
            temp = self.obj.gradient_descent(data[i], threshold)
            while temp == -1 and i < len(data) - 1:
                i += 1
                temp = self.obj.gradient_descent(data[i], threshold)

            w = []
            temp = self.obj.gradient_descent(data[i], threshold)
            while temp != -1 and i < len(data) - 1:
                w.append(temp)
                i += 1
                temp = self.obj.gradient_descent(data[i], threshold)

            # now w has one chunk
            cnt = 0
            for j in range(1, len(w)):
                if w[j] > w[j - 1]:
                    cnt += 1
                elif w[j] < w[j - 1]:
                    cnt -= 1
            #print i, cnt
            if cnt > control:
                y.append(2)
            elif cnt < -control:
                y.append(1)
        return y

    def gd_double_touch(self, data, threshold, control=0):
        i = 0
        temp1 = -1
        temp2 = -1
        y = []

        last_i = -1

        while i < len(data) - 1:
            temp1 = self.obj.gradient_descent(data[i], threshold)
            temp2 = self.obj.gradient_descent(data[i][::-1], threshold)
            while temp1 == -1 and i < len(data) - 1:
                i += 1
                temp1 = self.obj.gradient_descent(data[i], threshold)
                temp2 = self.obj.gradient_descent(data[i][::-1], threshold)

            w1 = []
            w2 = []
            temp1 = self.obj.gradient_descent(data[i], threshold)
            temp2 = self.obj.gradient_descent(data[i][::-1], threshold)
            while temp1 != -1 and i < len(data) - 1:
                w1.append(temp1)
                w2.append(15 - temp2)
                i += 1
                temp1 = self.obj.gradient_descent(data[i], threshold)
                temp2 = self.obj.gradient_descent(data[i][::-1], threshold)

            # now w has one chunk
            print len(w1), len(w2), w1, w2

            if len(w1) > 2:
                if w1 == w2:
                    if i - last_i < 20:
                        y.pop()
                        y.append(
                            'd_' +
                            str(max(k
                                    for k, v in Counter(w1).items() if v > 1)))
                    else:
                        y.append(max(w1))
                else:
                    if y and i - last_i < 20:
                        y.pop()
                    y.append(
                        'm_' +
                        str(max(k for k, v in Counter(w1).items() if v > 1)) +
                        '_' +
                        str(max(k for k, v in Counter(w2).items() if v > 1)))

            last_i = i
        return y
Пример #4
0
 def __init__(self):
     self.m = 0
     self.y = []
     self.obj = Descent()
Пример #5
0
class WatchGesture(object):
    def __init__(self):
        self.m = 0
        self.y = []
        self.obj = Descent()

    def clearobj(self):
        self.m = 0
        self.y = []

    def findLongestConseqSubseq(self, arr):

        # Time Complexity O(n) - Linear

        s = set([])
        ans = 0
        sp = -1

        # Hash all the array elements
        for ele in arr:
            s.add(ele)

        # check each possible sequence from the start
        # then update optimal length
        for i in range(len(arr)):

            # if current element is the starting
            # element of a sequence
            if (arr[i] - 1) not in s:

                # Then check for next elements in the
                # sequence
                j = arr[i]
                while (j in s):
                    j += 1

                # update  optimal length if this length
                # is more
                if j - arr[i] > ans:
                    ans = j - arr[i]
                    sp = arr[i]
                #ans=max(ans, j-arr[i])
        return ans, sp

    def gd(self, data, threshold, control=5):
        i = 0
        temp = -1
        y = []

        #print len(data), len(data[0]), data[0]

        tdata = []
        for e in data:
            tdata.append([e[:6], e[6:11], e[11:17], e[17:]])

        while i < len(data) - 1:
            temp = self.obj.gradient_descent(data[i], threshold)
            while temp == -1 and i < len(data) - 1:
                i += 1
                temp = self.obj.gradient_descent(data[i], threshold)

            w = []
            temp = self.obj.gradient_descent(data[i], threshold)
            while temp != -1 and i < len(data) - 1:
                w.append(temp)
                i += 1
                temp = self.obj.gradient_descent(data[i], threshold)

            # now w has one chunk
            #print len(w), self.findLongestConseqSubseq(w)

            cnt = 0
            for j in range(1, len(w)):
                if w[j] > w[j - 1]:
                    cnt += 1
                elif w[j] < w[j - 1]:
                    cnt -= 1

            if len(w) > 3:
                a, b = self.findLongestConseqSubseq(w)
                if b + a / 2 in range(0, 6) or b + a / 2 in range(11, 17):
                    if cnt > control:
                        y.append(2)
                    elif cnt < -control:
                        y.append(1)
                    #y.append('1/2')
                elif b + a / 2 in range(6, 11) or b + a / 2 in range(17, 22):
                    if cnt > control:
                        y.append(4)
                    elif cnt < -control:
                        y.append(3)
        return y