How to use different dimensions for neural network?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to write a neural network that calculates the cross product of 2 vectors in
which elements are between -1 and 1.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1043545/image.png)
So as Xtrain it gets an array with 3x2 matrices or basically 2 vectors
and as Ytrain it's an array of
vectors. So dimensions are 3,2,1000 and 3,1000. Here is my code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1043545/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1043545/image.png)
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. I wonder what is the best solution here? One of my ideas is to convert Xtrain into an array of cells, so the cell would consist of 2 vectors but as far as I understand it's an antipattern.
0 commentaires
Réponse acceptée
Sam Chak
le 23 Juin 2022
Documentation says that Network inputs must be specified as an InputSize-by-BatchSize matrix. Is this approach acceptable?
Xtrain = zeros(6,5);
Ytrain = zeros(3,5);
for c = 1:5
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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Define Shallow Neural Network Architectures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!