I'm trying to construct a class framework for a neural network (ANN) in Matlab by defining a Node class:
function NodeObject = Node(Input, Weights, Activation)
Features.Input = [];
Features.Weights = [];
Features.Activation = [];
Features.Input = Input;
Features.Weights = Weights;
Features.Activation = Activation;
NodeObject = class(Features, 'Node');
Where here the input is an integer (expected number of inputs), Weights is a vector of length Features.Input, and Features.Activation is a string that references an activation function stored in the methods.
What I want to do next is construct a cell array of nodes and define a Network class based on this array:
function Architecture = Network(NodeArray)
ANN.Layers = []; % Number of layers in architecture
ANN.LayerWidths = []; % Vector of length ANN.Layers containing width of each layer
ANN.NodeArray = []; % Original input is cell array with layers in ascending order (input at top, output at bottom) with nodes in each row.
ANN.InputSizes = [];
% Find number of layers
ANN.Layers = length(NodeArray(:,1));
% Find width of each layer
Widths = zeros(ANN.Layers,1);
for i = 1:length(Widths)
Widths(i) = length(NodeArray(:,i));
end
ANN.LayerWidths = Widths;
% Pass NodeArray to Network class
ANN.NodeArray = NodeArray;
% Construct cell of input sizes
InputSizes = [];
for i = 1:ANN.Layers
for j = 1:Widths(i)
InputSizes(i,j) = NodeArray{i,j}.Inputs;
end
end
ANN.InputSizes = InputSizes;
Architecture = class(ANN, 'Network');
The attribute ANN.InputSizes tries to extract the attributes from a Node object, but my code doesn't allow me to do this. How do I amend this problem, or do you recommend a different architecture to this problem all together? Currently my classes Node and Network are contained in two separate directories, but I have a feeling that there is something else I'm not seeing. For reference, I have absolutely no prior experience in OOP, and from what I've gathered it seems Matlab is not the best environment in which to implement these structures. At the moment though I don't have enough experience to implement this type of framework in another language.
classdefformat for defining your classes. - SueverNode2class with theclassdefformat saved in the@Networkdirectory, but theNetworkdefinition didn't recognize it. Part of this problem is in how I'm defining my classes, but part of it too might be how I'm linking my directories. - Mnifldz@Node2. But withclassdefdefinitions, you don't need the@Folderat all. - Suever