function net = decode_jyu_mlp(mrepr)
% Read the network structure just like we do in our optimization
% codes. Create a "simple MLP" like those we have used in earlier
% industrial projects.
%
% First number is the version. As of now, we know of two types:
%
% "Version 0" is always two-layer 2-n-m MLP with in-logsig-purelin
% activations. Used in some early try-outs.
%
% "Version 1" is variable size, and can contain logsig, tansig or
% purelin activations. This is the format used in my 2016
% dissertation.
%

mlpvers = mrepr(1);

assert((mlpvers == 0) || (mlpvers == 1), ...
       'MLP Individual encoding type not recognized: %d', mlpvers);

if (mlpvers == 0)
  nlayers = mrepr(2);
  assert((nlayers == 3), ...
       'This works only for 2-n-m MLPs. (%d layers attempted.)', nlayers);

  nneur = mrepr(3:5);

  if (nneur(1) ~= 2)
    ermsg = sprintf(['Version 0 only supports 2-n-m MLPs.' ...
		     ' Seems that you tried %d-%d-%d.'], nneur(1), ...
		    nneur(2), nneur(3));
    error(ermsg);
  end
  
  
  % Make our structure the same as in the c++ code for optimization
  net = simple_mlp_create(nneur);
  net.alpha=2; net.q=2; % (not used here)
  net.activ{1}  = @simple_mlp_logsigfwd;
  net.activD{1} = @simple_mlp_logsigderiv;

  % then get weights:
  nxreal = numel(net.W{1}) + numel(net.W{2});
  w = mrepr(6:6+nxreal-1);
  
  net.W = simple_mlp_vec2cell(w, nneur, 'row');
elseif (mlpvers == 1)
  nlayers = mrepr(2);
  for ilay=1:nlayers
    nneur(ilay) = mrepr(2+ilay);
  end
  net = simple_mlp_create(nneur);
  net.alpha=2; net.q=2; % (not used here)
  for ilay=1:nlayers-1 % Index base is different here! (we have
                       % "layer 0" stored as the input.)
    actenum = mrepr(2+nlayers+1+ilay); % +1 skips the "always 0" input layer
    net.actenum(ilay)=actenum; % Store the C++ enum int here.
    if (actenum==0)
      error('The "Unset" enumeration used on layer %d',ilay);
    elseif (actenum==1)
        net.activ{ilay}  = @simple_mlp_plinfwd;
	net.activD{ilay} = @simple_mlp_plinderiv;
    elseif (actenum==2)
        net.activ{ilay}  = @simple_mlp_tanhfwd;
	net.activD{ilay} = @simple_mlp_tanhderiv;
    elseif (actenum==3)
        net.activ{ilay}  = @simple_mlp_logsigfwd;
	net.activD{ilay} = @simple_mlp_logsigderiv;
    else
      error('Unknown enumeration for activation function: %d', ...
      actenum);
    end
  end

  rdbase = 2+2*nlayers+1;
  for ilay=1:nlayers
    w = mrepr(rdbase:end);
    net.W = simple_mlp_vec2cell(w, nneur, 'row');
  end
end
