%performregression.m
function [OUTPUTTESTR,MSE,W1]=performregression (INPUTTRAIN,OUTPUTTRAIN,INPUTTEST,OUTPUTTEST,reg,sigma)
    [V,M]=kmeans(INPUTTRAIN,4); 
    [V1,I1]=min(sum((INPUTTRAIN-repmat(M(1,:),size (INPUTTRAIN,1),1)).^2));
    [V2,I2]=min(sum((INPUTTRAIN-repmat(M(2,:),size (INPUTTRAIN,1),1)).^2)); 
    [V3,I3]=min(sum((INPUTTRAIN-repmat(M(3,:),size (INPUTTRAIN,1),1)).^2));
    [V4,I4]=min(sum((INPUTTRAIN-repmat(M(4,:),size (INPUTTRAIN,1),1)).^2)); 
    B1=[]; B2=[]; B3=[]; B4=[]; 
    for i=1:1:size(INPUTTRAIN,1) 
        B1=[B1 gbf(INPUTTRAIN(i,:),M(1,:),sigma)]; 
        B2=[B2 gbf(INPUTTRAIN(i,:),M(2,:),sigma)]; 
        B3=[B3 gbf(INPUTTRAIN(i,:),M(3,:),sigma)]; 
        B4=[B4 gbf(INPUTTRAIN(i,:),M(4,:),sigma)]; 
    end
    %Formulation of matrix 
    MAT=[ones(size(INPUTTRAIN,1),1) B1' B2' B3' B4'];
    MAT1=MAT'*MAT; 
    W1=pinv(MAT1+reg*eye(size(MAT1,1)))*MAT'*OUTPUTTRAIN;
    B1=[]; B2=[]; B3=[]; B4=[]; 
    for i=1:1:size(INPUTTEST,1) 
        B1=[B1 gbf(INPUTTEST(i,:),M(3,:),sigma)];
        B2=[B2 gbf(INPUTTEST(i,:),M(2,:),sigma)];
        B3=[B3 gbf(INPUTTEST(i,:),M(3,:),sigma)]; 
        B4=[B4 gbf(INPUTTEST(i,:),M(4,:),sigma)];
    end
    MAT=[ones(size(INPUTTEST,1),1) B1' B2' B3' B4'];
    OUTPUTTESTR=MAT*W1;
    MSE=sum((OUTPUTTESTR-OUTPUTTEST).^2)/length (OUTPUTTEST);
    
