def compute_x_ks(points, k_function):
    x_ks = []
    t = points[1]
    for point in points:
        x = np.subtract(point, t)
        #print len(k_function(point))
        x_ks.append(np.subtract(x, k_function(point)))
        t = point
    return x_ks
def compute_x_ks(points, k_function):
    x_ks = []
    t = points[1]
    for point in points:
        x=np.subtract(point, t)
        #print len(k_function(point))
        x_ks.append(np.subtract(x, k_function(point)))
        t = point
    return x_ks
def gradient_function(point, k_function, g_function):
    dimension = len(point)
    gradient = np.zeros(dimension)
    k_vector = k_function(point)
    g_matrix = g_function(point)

    # print len(k_function(point))
    #m,n=g_matrix.shape

    for i in range(dimension):
        gradient[i] = k_vector[i]

        for j in range(3):
            gradient[i] += math.sqrt(
                2.0 * 0.0001) * g_matrix[j][i] * np.random.normal(0, 0.001)

    return gradient
def gradient_function(point,k_function,g_function):
    dimension = len(point)
    gradient = np.zeros(dimension)
    k_vector = k_function(point)
    g_matrix = g_function(point)



   # print len(k_function(point))
    #m,n=g_matrix.shape

    for i in range(dimension):
        gradient[i] = k_vector[i]

        for j in range(3):
            gradient[i] += math.sqrt(2.0*0.0001)*g_matrix[j][i]*np.random.normal(0, 0.001)

    return gradient