Neural Network with custom performance function
8 次查看(过去 30 天)
显示 更早的评论
Although this question was asked before, but I didn't find a single statesfying answer! The question is:
Given a nueral network, regardless of its type, the desire is to train the neural network using an error function that, presumabely, positive definite or semi positive definite. Meaning, the function does have minima. The error function in the Deep learning toolbox always takes the neural network outputs and some targets. This is understood as the gradient calculation should start from the output of the netowrk. However, once the backprobagation starts, taking the derivative of performance function, say it is MSE, the result is simply the error. This means, you can easitly replace it with any error function you want regardless if it's calculated from the network outputs or not. The Main objective of this question is to have the ability to replace the calculation of the Error with calculation of ANY constrain function that we would like to minimize during training of the neural network.
A typical example is tunning the gains of a PID controller. The gains are the outputs of the Neural Network. The tunning uses the error calculated from the desired and current system outputs. So, I can't use the standard toolbox performance functions as they require using the outputs of the Neural network to get the error! In this example, there is no Target PID gains and the training is similar to what we do in adaptive control, i.e use the system error to tune the gains.
How do we supply an error function to the MSE peformance function that is NOT calculated from the Neural Netowrk Outputs/Targets?
Thanks.
0 个评论
回答(1 个)
Yash
2024-1-10
Hi EngM,
In the Deep Learning Toolbox, if the built-in performance metrics like Mean Squared Error (MSE) do not meet your specific needs, you have the option to create a custom performance metric. This involves defining a MATLAB function that accepts the network's predictions, the true targets, and other parameters, which then computes the error according to your custom criteria.
This custom function can then be integrated into the training process of the neural network, allowing you to optimize the network's weights based on your defined error metric. By doing so, you can tailor the learning process to focus on minimizing the error based on your custom performance function.
Here's an example of how you can define a custom performance function:
function error = myMetric(outputs, targets, additionalInputs)
% Calculate the error based on the desired constraint function and return the error value
error = yourCustomConstraintFunction(outputs, targets, additionalInputs);
end
Once you have defined your custom performance function, you can use it in the training process by specifying it as the performance function when creating the neural network:
net = feedforwardnet(hiddenSizes);
net.performFcn = 'myMetric';
By supplying your own error function, you can train the neural network to minimize any constraint or error metric that you define, even if it is not directly calculated from the network outputs or targets.
Hope this helps
另请参阅
类别
在 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!