clear all
% load search data plus CDC data
M_raw = xlsread('../InfluenzaWeeklyCounts_scaled_plus_more_terms2.xls');

% Assign variables
week_number=M_raw(:,1);
date=M_raw(:,2)
CDC=M_raw(:,3);

% This is the prediction from Google Flu Trends 
gft=M_raw(:,28);

% Z-transform search data. The last 23 (from (:,4:26)) columns are UpToDate search values. 
Mean_M=mean(M_raw(:,4:26));
Stand_dev=std(M_raw(:,4:26));

for k=4:26
    M(:,k)=(M_raw(:,k)-Mean_M(k-3))./Stand_dev(k-3);
end

%Training period equals to first "training" months
training=26;
end_period=109;

% Method 3. Use lasso to obtain a multi-variate fit to data
% Initialize array to store values of predicition + training
lasso_gdt=zeros(1,end_period);

for i=training:(end_period-2)
    %Fit data
    b= cvglmnet(M(1:i,4:terms), CDC(1:i));
    if i==training
        % Set time series to include the training set
        lasso_gdt(1:i+1)=cvglmnetPredict(b, M(1:i+1,4:terms),'lambda_min');
    end
    %Predict for next week
    lasso_gdt(i+2)=cvglmnetPredict(b, M(i+2,4:terms),'lambda_min');
    coeff(i-training+1, :)=cvglmnetCoef(b, 'lambda_min');
    
end