Esempio n. 1
0
def thetas(data, size, lambda_c, labels):
    l_in = line_len(data)
    theta1 = initialize_weights(l_in, size)
    theta2 = initialize_weights(size, 2)

    cost = lambda p: cost_function(get_x(data), get_y(data), lambda_c, p, l_in, size, labels)
    init_p = np.concatenate((make1d(theta1), make1d(theta2)), axis=1)
    params = fmin(cost, init_p.reshape((len(init_p), 1)))

    return reshape(params, l_in, size, labels)
Esempio n. 2
0
def thetas(data, size, lambda_c, labels):
    l_in = line_len(data)
    theta1 = initialize_weights(l_in, size)
    theta2 = initialize_weights(size, 2)

    cost = lambda p: cost_function(get_x(data), get_y(data), lambda_c, p, l_in, size, labels)
    init_p = np.concatenate((make1d(theta1), make1d(theta2)), axis=1)
    params = fmin(cost, init_p.reshape((len(init_p), 1)))

    return reshape(params, l_in, size, labels)
Esempio n. 3
0
def scale(data):
    m = line_len(data)
    x_min, x_max = numpy.array([1e10] * m), zeros(m)

    for (x, _) in data:
        for i in range(m):
            x_min[i] = min(x_min[i], x[i])
            x_max[i] = max(x_max[i], x[i])

    for (x, _) in data:
        for i in range(m):
            x[i] = (x[i] - x_min[i]) / (x_max[i] - x_min[i]) if x_max[i] != x_min[i] else 1

    return data
Esempio n. 4
0
def optimize_size_lambda(data, labels, size_max=20, base=2.0, degree_max=10, coefficient=100):
    result, error = (line_len(data), 0), 2.0

    for size in range(1, size_max):
        for degree in range(1, degree_max):
            lambda_c = (base ** degree) / coefficient

            average_error = cross_validate(data, size, lambda_c, labels)
            print("%d %f %f\n" % (size, lambda_c, average_error))

            if average_error < error:
                error = average_error
                result = (size, lambda_c)

    return result
Esempio n. 5
0
def optimize_size_lambda(data, labels, size_max=20, base=2.0, degree_max=10, coefficient=100):
    result, error = (line_len(data), 0), 2.0

    for size in range(1, size_max):
        for degree in range(1, degree_max):
            lambda_c = (base ** degree) / coefficient

            average_error = cross_validate(data, size, lambda_c, labels)
            print('%d %f %f\n' % (size, lambda_c, average_error))

            if average_error < error:
                error = average_error
                result = (size, lambda_c)

    return result
Esempio n. 6
0
def scale(data):
    m = line_len(data)
    x_min, x_max = numpy.array([1e10] * m), zeros(m)

    for (x, _) in data:
        for i in range(m):
            x_min[i] = min(x_min[i], x[i])
            x_max[i] = max(x_max[i], x[i])

    for (x, _) in data:
        for i in range(m):
            x[i] = (x[i] - x_min[i]) / (
                x_max[i] - x_min[i]) if x_max[i] != x_min[i] else 1

    return data