function [z,y,z_0,val] = f_forward(W, b, xv, yv)
    nl = size(W,3);
    n = size(b,1);
    z = zeros(n,nl);
    y = zeros(n,nl);
    z(:,nl) = xv;
    y(:,nl) = W(:,:,nl)*z(:,nl) + b(:,nl);
    for k=(nl-1):(-1):1
        z(:,k)= sigma(y(:,k+1));
        y(:,k) = W(:,:,k)*z(:,k) + b(:,k);
    end
    z_0 = sigma(y(:,1));
    val = sum(abs(z_0-yv).^2);
end

function y=sigma(x)
    y = 1./(1+exp(-x));
end