Beispiel #1
0
 def test_convert_is_date(self):
     current_date = date.today()
     current_date_converted = utility.convert(current_date)
     self.assertIsNotNone(current_date_converted)
     self.assertEquals(
         current_date_converted,
         str(current_date.year) + '-' + str(current_date.month).zfill(2) +
         '-' + str(current_date.day).zfill(2))
def convert_params_to_correct_types(params):
    converted_params = {}

    for key, val in params.items():
        new_val = utility.convert(val)

        if type(
                new_val
        ) == str:  # If param is a comma separated string, convert it to a list of the elements
            elements = new_val.split(",")
            if len(elements) > 1:
                new_val = [utility.convert(x) for x in elements]

                if new_val[
                        -1] == '':  # One-element string (nothing after the comma)
                    new_val = new_val[:-1]

        converted_params[key] = new_val

    return converted_params
Beispiel #3
0
def main():
    ncolors = [256, 128, 64, 32, 16, 8, 4]  #number of clusters
    bw = [1, 2, 5, 10, 15, 40]  #bandwidth values
    img = Image()
    img.read_img(
        '/Users/davidclevenger/PycharmProjects/Pattern-Recognition/flowers120.ppm'
    )
    orig = img.pix

    #k_means
    print 'kmeans'
    for i in ncolors:
        tmp = convert(kmeans(i, orig))
        img.pix = tmp
        performance(i, orig, tmp)
        img.write_img(
            '/Users/davidclevenger/PycharmProjects/Pattern-Recognition/kmeans'
            + str(i) + '.ppm')

    #winner_take_all
    print 'winner_take_all'
    for i in ncolors:
        tmp = convert(winner_take_all(i, 0.1, orig))
        img.pix = tmp
        performance(i, orig, tmp)
        img.write_img(
            '/Users/davidclevenger/PycharmProjects/Pattern-Recognition/wta' +
            str(i) + '.ppm')

    #mean_shift
    print 'mean_shift'
    for i in bw:
        tmp = convert(meanshift(i, orig))
        img.pix = tmp
        performance(i, orig, tmp)
        img.write_img(
            '/Users/davidclevenger/PycharmProjects/Pattern-Recognition/ms' +
            str(i) + '.ppm')

    return 0
Beispiel #4
0
def p_type(p):
    '''type : BOOL
            | CHAR
            | BYTE
            | SHORT
            | INT
            | LONG
            | DOUBLE
            | FLOAT
            | ID '''
    if not isType(p[1]):
        raise SyntaxError
    p[0] = convert(p[1])
Beispiel #5
0
 def confusion_matrix(self, y_pred, y_real):
     for i in range(len(y_pred)):
         y_pred[i] = ut.convert(y_pred[i])
     n = y_real.shape[1]
     m = np.array(n * [n * [0]])
     for i in range(len(y_real)):
         if (y_real.values[i][0] == 1):
             m[0] += y_pred[i]
         elif (y_real.values[i][1] == 1):
             m[1] += y_pred[i]
         else:
             m[2] += y_pred[i]
     ut.plt_confusion_matrix(m)
     return m
Beispiel #6
0
    def _sample(self, size, training, random_state):
        s = None
        temp = None
        if training:
            temp = self.train_df.drop(pd.DataFrame())
        else:
            temp = self.test_df.drop(pd.DataFrame())

        while len(temp) > 0:
            if len(temp) < size:
                s = temp.sample(len(temp), random_state=random_state)
                temp = temp.drop(s.index)

                s = utility.convert(s)

                yield utility.reform(s)
            else:
                s = temp.sample(size, random_state=random_state)
                temp = temp.drop(s.index)

                s = utility.convert(s)

                yield utility.reform(s)
Beispiel #7
0
 def test_convert_is_none(self):
     non_date = "I am not a date."
     self.assertIsNone(utility.convert(non_date))
Beispiel #8
0
def p_acs(p):
    ''' acs : PRIVATE
            | PUBLIC
            | PROTECTED
            | '''
    addToFile(text=convert(p[1]) + " ")