How to use different dimensions for neural network?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Sam Chak
il 23 Giu 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Define Shallow Neural Network Architectures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!