Exemple #1
0
def get_lookup_table(stylization_model):
    # TODO: Need to create function
    table_r = np.zeros((256, 256), dtype=np.uint8)
    table_g = np.zeros((256, 256), dtype=np.uint8)
    table_b = np.zeros((256, 256), dtype=np.uint8)
    for i in range(256):
        for j in range(256):
            xm = np.zeros(1, np.float)
            xm[0] = i / 255
            xm = PolynomialFeatures(degree=POLY_DEGREE,
                                    include_bias=False).fit_transform(
                                        xm.reshape(-1, 1))

            xs = np.zeros(1, np.float)
            xs[0] = j / 255
            xs = PolynomialFeatures(degree=POLY_DEGREE,
                                    include_bias=False).fit_transform(
                                        xs.reshape(-1, 1))

            tmp = np.append(xm, xs)
            x = np.append(np.ones(1), tmp)

            table_r[i][j] = np.clip(np.dot(stylization_model[0].coef_, x), 0,
                                    1) * 255
            table_g[i][j] = np.clip(np.dot(stylization_model[1].coef_, x), 0,
                                    1) * 255
            table_b[i][j] = np.clip(np.dot(stylization_model[2].coef_, x), 0,
                                    1) * 255
            # ======================================================================

    print('done')
    return table_r, table_g, table_b
def fit_trend(ser, n):
    """
    Takes a series and fits an n-th order polynomial to the series.
    Returns the predictions.
    """
    #Generate ordinal values to represent timestamps for use in regression
    # Create train_X and train_y
#     train_X, train_y = np.asarray(ser.index.map(dt.datetime.toordinal)), np.asarray(ser) # xi's and yi's
    train_X, train_y = np.asarray([i+1 for i in range(len(ser.index))]), np.asarray(ser)

    # Fit a polynomial regression model - code given to you

    train_X = PolynomialFeatures(n).fit_transform(train_X.reshape(-1, 1))

    lin_reg = LinearRegression().fit(train_X, train_y.reshape(-1))

    # Make predictions to create the trend curve
    # YOUR CODE HERE
    y_pred = np.asarray(lin_reg.predict(train_X))

    trend_curve = y_pred

    return trend_curve