def main():
    ## generate data and define inputs
    mu = np.arange(0, 2 * math.pi, 0.1)
    sigma = 0.1
    x_train = np.arange(0, 2 * math.pi, 0.1)
    x_test = np.arange(0.05, 2 * math.pi, 0.1)

    # #! DELTA RULE

    #! LEAST SQUARE
    ## init rbf class
    dim = mu.shape[0]
    rbf_LS = RBF(dim)

    ## Generate data
    sinus, square = rbf_LS.generateData(x_train)
    sinus_test, square_test = rbf_LS.generateData(x_test)

    ## Init and train.
    weights = rbf_LS.initWeights()
    weights, error = rbf_LS.train_DELTA(x_train, square, weights, mu, sigma)

    ## Evaluation
    print(rbf_LS)
    y_test = rbf_LS.evaluation_DELTA(x_test, weights, mu, sigma)
    # y_test=threshold(y_test)
    re = residualError(y_test, square_test)
    plt.figure('Least Square Error')
    plt.plot(x_test, y_test, label='Approximation')
    plt.plot(x_test, square_test, label='True value')
    plt.title('Least Square Error')
    plt.legend()
    plt.show()
def square_delta(x_test, x_train, mu, sigma):
    dim = mu.shape[0]
    rbf = RBF(dim)
    _, square = rbf.generateData(x_train, noise=True)
    _, square_test = rbf.generateData(x_test, noise=True)
    square_test = square_test.reshape((square_test.shape[0], 1))

    ## Init and train.
    weights = rbf.initWeights()
    weights, _, _ = rbf.train_DELTA(x_train, weights, mu, sigma)

    ## Evaluation
    y_test = rbf.evaluation_DELTA(x_test, weights, mu, sigma)
    residual_error = np.sum(abs(y_test - square_test)) / y_test.shape[0]
    return residual_error, y_test, square_test