Implement the following perceptron learning algorithm using C++. Test your algorithm with AND and OR operations. Calculate the rate value.
Learning Algorithm steps:
1. Initialize weights and threshold.
Set wi(t), (1 ≤ i ≤ m) to be the weight i at time t, and θ to be the threshold value in the output node.
Set wi to small random values, thus initializing the weights and threshold.
2. Present input and desired output.
Present input xo and x1, x2, ..., X and desired output d(t).
3. Calculate the actual output.
y(t) = θ[wo(t) xo(t) + w1(t) x1(t) + w2(t) x2(t) + ... + Wm(t) Xxr(t)].
4. Adapt weights.
wi(t+1) = w(t) + [d(t) - y(t)] x(t), for.
Steps 3 and 4 are repeated until the iteration error is less than a user-specified error threshold or a predetermined number of iterations have been completed.
η is the learning rate.
d(t) is the desired output.
y(t) is the actual output.
Error = d(t) - y(t).
η is between 0 and 1.