% This is the second part of the script that calculates the error for the
% data set d-100.csv
% To work with matlab, the class value for the file d-100.csv has been
% changed to NS = -1 and S = 1 using Excell. Please use the file d-100.csv 
% uploaded with it here to get the value

clc; clear all; close all;

% Import the data and initiate the learning rate, number of epochs, and 
% error matrix of zeros. 
alpha = 0.1:0.1:1;      % learning rate
epochs = [100, 500];    % number of epochs
error = zeros( length(alpha), length(epochs));

% Use function "impdata" to import csv data file and to convert it to a
% matrix form without header row
nameofdata = 'd-100.csv';
[values] = impdata(nameofdata);

% Define min and max value and the bias value for the weight vector and 
% Call the function  int_weight to initiate weights 
minV = 1; maxV = 100; bias_weight = 1;
[weights] = int_weight(minV,maxV,bias_weight);
numberofRows = size(values, 1);
values = [ones(numberofRows, 1) values]; % add a bias term to the data matrix

% The last column is the class values, we don't need to include it for
% weight update
numberofColumns = size(values, 2) - 1; 

% Call the "cal_error" function to calculate the error after 100 and 500
% epochs
[ error2 ] = cal_error(alpha, epochs, numberofRows, numberofColumns, weights, values, error)