#include <iostream>

// Parameters of the line (y=ax+b)
#define     a       0.6
#define     b       -2

// Size fo training set
#define     N       1000

// Learning rate
#define     ETA     0.03

// Generate random double
double rand_double(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

int main(void)
{
    // Create training set
    double X[N],Y_[N];
    for (int i=0;i$lt;N;i++)
    {
        X[i]=rand_double(-10,10);
        Y_[i]=a*X[i]+b;
    }


    // Training
    double w1=0,w2=0;
    for (int i=0;i<N;i++)
    {
        // Forward
        double Y=w1*X[i]+w2;
        // Update weights (backward)
        w1=w1+ETA*(Y_[i]-Y)*X[i];
        w2=w2+ETA*(Y_[i]-Y);
    }

    std::cout << "::: Results :::" << std::endl;

    // Display a and b
    std::cout << std::endl;
    std::cout << "** Model **" << std::endl;
    std::cout << "a=" << a << std::endl;
    std::cout << "b=" << b << std::endl;

    // Display weights (w1 and w2)
    std::cout << std::endl;
    std::cout << "** Network weights **" << std::endl;
    std::cout << "w1=" << w1 << std::endl;
    std::cout << "w2=" << w2 << std::endl;


    return 0;
}

/* Expected output :
::: Results :::

** Model **
a=0.6
b=-2

** Network weights **
w1=0.6
w2=-2
*/