My function takes in a single input and provides a single output, but of the array type. Class properties are defined properly earlier and this as been tested to work (e.g. net.Num_Layers) Sizes is an array denoting number of neurons in each layer (e.g. net.Sizes = [3 4 2]) When trying to test individual method, a Network object is created in command line.
>>net = Network(sizes) net = Network with properties: Sizes: [3 4 2] Num_Layers: 3 Weights: [4×3×4 double] Biases: [4×3 double]>> a = [1 2 3]';>> net.feedforward(a)Error using Network/feedforwardToo many input arguments.
Here a snippet of my feed-forward method for the Network class:
function [a] = feedforward(a) %return output of network if column vector "a" is input.
for i=2:net.Num_Layers w = squeeze(net.Weights(1:net.Sizes(i),i,1:net.Sizes(i-1))); b =net.Biases(1:net.Sizes(i),i); a = w*a-b; end end
And here is my constructor method for reference if its relevant:
function net = Network(sizes)% The list ``sizes`` contains the number of neurons in the
% respective layers of the network. For example, if the list was
% [2, 3, 1] then it would be a three-layer network, with the first
% layer containing 2 neurons, the second layer 3 neurons, and the
% third layer 1 neuron. The biases and weights for the network are
% initialized randomly, using a Gaussian distribution with mean 0,
% and variance 1. Note that the first layer is assumed to be an
% input layer, and by convention we won't set any biases for those
% neurons, since biases are only ever used in computing the outputs
% from later layers.
if nargin == 0 net.Sizes = 0; end net.Num_Layers = length(sizes); net.Sizes = sizes; %Intialize and pad with zeros
net.Biases=zeros(max(sizes),net.Num_Layers); net.Weights=zeros(max(sizes),net.Num_Layers,max(sizes)); for i=2:net.Num_Layers net.Biases(1:sizes(i),i) = randn(sizes(i),1); end %layers are stored along columns i
%connecting from previous layer along rows j
%connecting to current layer along pages k
for i=2:(net.Num_Layers) net.Weights(1:sizes(i),i,1:sizes(i-1)) = ... randn(sizes(i),1,sizes(i-1)); end end
Best Answer