%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% wnet.m       Define the wnet - only need to call once by main %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% wnet is defined as anet + cnet
% It now works for both anet and cnet with only 1 hidden layers
% It can be modified for more layers and other activiation functions
% More comments in the program
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp('Define wnet = anet + cnet'); disp(' ')

wnet = network; 

% wnet inputs are x(t) to anet and x(t) to cnet in standard set up
wnet.numInputs = 2*nia; wnet.numLayers = 2+2;
wnet.biasConnect = ones(wnet.numLayers,1);

wnet.inputConnect(1,1:nia) = 1; 	% anet inputs
wnet.inputConnect(3,nia+1:2*nia) = 1;	% cnet inputs

wnet.layerConnect(2,1) = 1; 
wnet.layerConnect(3,2) = 1;
wnet.layerConnect(4,3) = 1; 
%wnet.layerConnect(5,4) = 1; 	% If you have more layers
wnet.outputConnect = [0 1 0 1];
wnet.targetConnect = [zeros(1,wnet.numLayers-1) 1];

wnet.layers{1}.size = nh1a;
wnet.layers{1}.transferFcn = 'tansig';
wnet.layers{2}.size = noa;
wnet.layers{2}.transferFcn = 'tansig';    % should match the anet output layer.

wnet.layers{3}.size = nh1c;
wnet.layers{3}.transferFcn = 'tansig';
%wnet.layers{4}.size = nh2c;		  % You might use more layers for cnet
%wnet.layers{4}.transferFcn = 'tansig';
wnet.layers{4}.size = noc;
wnet.layers{4}.transferFcn = 'purelin';	  % should match the cnet output layer.

wnet.initFcn           = 'initlay'; 
wnet.trainFcn          = anet.trainFcn;
wnet.performFcn        = anet.performFcn;
wnet.trainParam.lr     = anet.trainParam.lr;
wnet.trainParam.goal   = anet.trainParam.goal;
wnet.trainParam.show   = anet.trainParam.show;
wnet.trainParam.epochs = anet.trainParam.epochs;

