How to define my own performance function using fitnet besides copying the source code like mse.m?
10 views (last 30 days)
Show older comments
Saeed Khaleghi Rahimian
on 28 Feb 2023
Edited: Amanjit Dulai
on 4 Dec 2023
I tried to copy the mse.m function in the curret directory and other functions in +mse folder like apply.m but it did not work. Is there any other method to simply define a new performance fucntion using fitnet?
0 Comments
Accepted Answer
Amanjit Dulai
on 4 Dec 2023
Edited: Amanjit Dulai
on 4 Dec 2023
See this answer for a step by step guide on how to create a custom performance function:
0 Comments
More Answers (1)
Shubham
on 8 Mar 2023
Hi Saeed,
Yes, there is another way to define a new performance function in MATLAB's fitnet function. You can use the performFcn property of the fitnet object to specify the name of your custom performance function.
Here's an example:
% Define your custom performance function
function perf = myperf(y, t)
% Calculate the mean squared error
perf = mean((t-y).^2);
end
% Create a new fitnet object with 10 hidden neurons
net = fitnet(10);
% Set the performFcn property to your custom performance function
net.performFcn = 'myperf';
% Train the network with your custom performance function
net = train(net, inputs, targets);
In this example, we define a custom performance function called myperf that calculates the mean squared error between the network's output y and the target values t. We then create a fitnet object with 10 hidden neurons, and set its performFcn property to myperf. Finally, we train the network using the train function, which will use your custom performance function to evaluate the network's performance during training.
Note that your custom performance function should have the same input arguments as the built-in performance functions in MATLAB's Neural Network Toolbox, which are y (the network's output) and t (the target values). Your function should return a scalar value that represents the network's performance.
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!