필터 지우기
필터 지우기

Custom Performance Function for shallow Neural Networks using +MSE package

조회 수: 3 (최근 30일)
Vivek Ranade
Vivek Ranade 2024년 2월 23일
댓글: Vivek Ranade 2024년 2월 26일
I am trying to build a Custom Performance Function for shallow Neural Networks using +MSE package as mentioned in https://uk.mathworks.com/matlabcentral/answers/461848-custom-performance-function-for-shallow-neural-networks-using-mse-package.
While modifying apply.m for constructing expression of desired performance, I need to use input and layer weights for the network. Direct reference to net.IW and net.LW variables gives error. It will be great if anyone can suggest some way to access these variables in this function.

답변 (1개)

Namnendra
Namnendra 2024년 2월 26일
Hi Vivek,
In MATLAB, when creating a custom performance function for neural networks, you typically need to access various properties of the network, such as input weights (`net.IW`) and layer weights (`net.LW`). However, these properties should be passed to the performance function in a specific manner, as direct access within the function might not be possible due to the function's scope and the way MATLAB handles objects and namespaces.
The custom performance function should be designed to accept the network object and any additional information it requires as input arguments. For example, when you define your custom performance function, you might structure it like this:
function perf = myCustomPerformance(net, data, varargin)
% Extract the necessary information from the network
inputWeights = net.IW;
layerWeights = net.LW;
% ...Rest of your performance calculation code...
end
However, if you're modifying the `apply.m` function within the `+MSE` package or any other package, you need to ensure that the network object `net` and the necessary properties are available within the scope of the `apply.m` function. The `apply.m` function should be part of a class definition, and the network object should be passed to it correctly.
Here's an example of how you might set up the `apply.m` function to accept the network object and then use its properties:
function perf = apply(net, targets, outputs, ~, ~)
% Here, 'net' is the network object, 'targets' are the target outputs,
% and 'outputs' are the actual outputs of the network.
% Access the input weights and layer weights
inputWeights = net.IW{1};
layerWeights = net.LW{2,1}; % This is just an example; use the correct indices for your network
% Now you can use 'inputWeights' and 'layerWeights' to calculate your custom performance
% ...Rest of your performance calculation code...
end
Please note that the indices for `net.IW` and `net.LW` should correspond to the specific input-to-layer or layer-to-layer connections you want to access. For example, `net.IW{1,1}` would access the weights from the first input to the first layer, and `net.LW{2,1}` would access the weights from the first layer to the second layer.
If you're still encountering errors, please ensure that:
1. The network object `net` is being passed correctly into the performance function.
2. The indices used to access `net.IW` and `net.LW` are valid for your network's architecture.
3. Any modifications you make to the `apply.m` function are consistent with the expected input and output arguments for performance functions in MATLAB's neural network toolbox.
I hope the above steps help you in resolving your issue.
Thank you.
  댓글 수: 1
Vivek Ranade
Vivek Ranade 2024년 2월 26일
Hi Namanendra,
  1. I tried modifying 'apply.m' as follows just to check whether weights are available.
function perfs = apply(t,y,e,param,net)
%MSE.APPLY Calculate performances
% Copyright 2012-2015 The MathWorks, Inc.
perfs = e .* e;
inputWeights = net.IW{1};
disp("hello");
end
This gives following error
Not enough input arguments.
Error in pgn.apply (line 7)
inputWeights = net.IW{1};
Error in nnMATLAB.bg
You have mentioned
3. Any modifications you make to the `apply.m` function are consistent with the expected input and output arguments for performance functions in MATLAB's neural network toolbox.
How to find out what is expected?
2. If I try the first way you have suggested by writing 'function perf = myCustomPerformance' in what way do I backpropagate the derivative as it is done in the 'backprop.m of +mse folder?
In other words, how do I integrate 'my performance function' to run with the MATLAB code?
Many thanks

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by