Train a Feedforward NN with Error Weights for the performance function
8 ビュー (過去 30 日間)
古いコメントを表示
Hello, my name is Jansen Acosta and I am currently trying to develop a Feedforward NN to predict 6 different responses.
At this time I am using the Mean squared error performance function - mse. However, for the function mse(net,targets,outputs,errorWeights,...parameters...), the default error weight is {1}, which weights the importance of all targets equally. Is there any way to set different errorWeights values for my Feedforward NN training process? My code looks like this:
nnsize = [10 6] ; nn_Hls = length(nnsize) ; % Hidden Layers
nnTrainFun = 'traingdx' ; % TRAINING
NN = feedforwardnet(nnsize, nnTrainFun) ; % 8 -10,6- 6
nnActFunc = 'tansig' ; % ACTIVATION
for h=1:nn_Hls ; NN.layers{h}.transferFcn = nnActFunc ; end % | HIDDEN Layers
NN.layers{end}.transferFcn = 'purelin'; % Linear transfer function | OUTPUT Layer
NN.performFcn = 'mse' ; % Mean Squared Error performance metric <-------- HELP NEEDED
NN.performParam.normalization = 'standard' ; % OUTPUTS ERROR
NN.performParam.regularization = 0.2 ; %
Thanks in advance
1 件のコメント
Juan Miguel Serrano Rodríguez
2024 年 3 月 14 日
編集済み: Juan Miguel Serrano Rodríguez
2024 年 3 月 14 日
I tried the other given answer and it was a waste of time since it was a made up response from chatGPT, errorWeights is not a parameter of the train function.
trainedNet = train(net,X,T,Xi,Ai,EW)
The problem I am facing is that I am not able to set Xi and Ai to its defaults so I can just speficy Ew. This is my (unsuccesful) attempt:
inputs_net = rand(10,5); % 5 inputs
outputs_net = rand(10,2); % 2 outputs
errorWeights = {1; 0.5}; % Half the weight for the second output as in https://www.mathworks.com/help/deeplearning/ref/network.perform.html
net = feedforwardnet();
net = configure(net, inputs_net', outputs_net')
% train(net, inputs_net', outputs_net', zeros, zeros, errorWeights)
train(net, inputs_net', outputs_net', zeros(net.numInputs, net.numInputDelays), zeros(net.numLayers, net.numLayerDelays), errorWeights)
回答 (1 件)
Mrutyunjaya Hiremath
2023 年 7 月 25 日
- Yes, you can set different error weights for your Feedforward Neural Network training process. The error weight values can be specified for each target separately to weigh their importance differently. To achieve this, you need to adjust the "errorWeights" parameter when training the network.
- In MATLAB's Neural Network Toolbox, you can use the "train" function to train the network and set the error weights. The train function allows you to pass additional training parameters, including the error weights.
- Here's how you can modify your code to set different error weights for the targets:
nnsize = [10 6]; % Hidden Layers
nnTrainFun = 'traingdx'; % TRAINING
NN = feedforwardnet(nnsize, nnTrainFun); % 8 -10,6- 6
nnActFunc = 'tansig'; % ACTIVATION
for h = 1:numel(nn.layers)
NN.layers{h}.transferFcn = nnActFunc;
end % | HIDDEN Layers
NN.layers{end}.transferFcn = 'purelin'; % Linear transfer function | OUTPUT Layer
NN.performFcn = 'mse'; % Mean Squared Error performance metric
% Set different error weights for each target
errorWeights = [w1, w2, w3, w4, w5, w6]; % Replace w1, w2, ..., w6 with your desired weights
NN.performParam.normalization = 'standard'; % OUTPUTS ERROR
NN.performParam.regularization = 0.2;
% Set the error weights for the network
NN.divideFcn = 'divideind'; % Use individual errors (per sample) for validation and test
NN.divideParam.trainInd = your_train_indices; % Replace with indices of your training data
NN.divideParam.valInd = your_validation_indices; % Replace with indices of your validation data
NN.divideParam.testInd = your_test_indices; % Replace with indices of your test data
NN.performParam.normalization = 'standard';
% Train the network with specified error weights
[NN, tr] = train(NN, inputs, targets, 'useGPU', 'yes', 'errorWeights', errorWeights);
% You can then use the trained network 'NN' for prediction or evaluation.
- In the code above, you need to replace w1, w2, ..., w6 with the desired error weight values for each target. Additionally, replace "your_train_indices", "your_validation_indices", and "your_test_indices" with the appropriate indices for your training, validation, and test datasets, respectively.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Sequence and Numeric Feature Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!