%% EXAMPLE: Adaptive training % % In this example, we look at how online learning can be very beneficial. % Here, we construct a toy signal that changes in time. Our goal: Using % the past 5 values, predict the 6th value. That is, build a linear % mapping so that: f(x_1, ..., x_5)=x_6 and f(x_2, ..., x_6)=x_7, etc. % % % First, build the time vectors: time1 = 0:0.05:4; % from 0 to 4 seconds time2 = 4.05:0.024:6; % from 4 to 6 seconds time = [time1 time2]; % from 0 to 6 seconds %% The data T = [sin(time1*4*pi) sin(time2*8*pi)]; lr = 0.2; % The domain will be vectors in R^5 found by lagging the vector T: X=lag(T,4,1); %X is 5 x 159. That is, T(1:5) is the first column of X, % and is used to predict T(6). X(:,159)=[]; %Last column not used. % Construct the desired targets: Targets=T(6:158+5); %Online training. In this case, track the error point-by-point: [W,B,err]=wid_hoff1(X',Targets',0.01,120); %The error is an array, 80 x 158 (80=number of epochs, 158=number of % points) plot(mean(err)) %Plot the predicted values and the actual values: Yout=W*X+B; tt=time(6:158+5); figure plot(tt,Targets-Yout)