I try to code a NN that predicts the cross product of 2 vectors in R^3.
XTrain has 3:2:1000 dimensions and is an array of matrices 3x2 (or basically 2 vectors 3x1). YTrain is a 3:1000 array. Here is my code:
Xtrain = zeros(3,2,1000);
Ytrain = zeros(3,1000);
for c = 1:1000
v1 = -1 + (1+1)*rand(3,1);
v2 = -1 + (1+1)*rand(3,1);
C = cross(v1,v2);
m = [v1, v2];
Xtrain(:,:,c) = m;
Ytrain(:,c) = C;
end
net = feedforwardnet([3 2]);
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'purelin';
net = train(net, Xtrain, Ytrain);
However Matlab gives 'Inputs X is not two-dimensional.' error. What is the best solution here?
In feedforward neural networks inputs are always 1D.
So unroll your 2D input into a 1D array, and just train with that!