How to use a self-made loss function for a simple Neural Net ?

6 Ansichten (letzte 30 Tage)
Neelabh Jyoti Saharia
Neelabh Jyoti Saharia am 28 Dez. 2021
Kommentiert: yanqi liu am 31 Dez. 2021
I have been using
net = feedforwardnet(10) %or
net = fitnet(10)
for my regression problem. I am using simple networks with 1 or 2 layers and ReLU activation function (net.transferFcn = 'poslin')
But now, I have to use a self-made custom loss functions instead of 'mse' (mean squared error). Could you please let me know how can I do this.
I have found the following document regarding using custom layers and loss functions: https://www.mathworks.com/help/deeplearning/ug/define-custom-regression-output-layer.html
But this is regarding to complex Neural Networks like CNN. I could not understand how to simplify this for a normal deep neural network.
Thanks!

Antworten (1)

yanqi liu
yanqi liu am 29 Dez. 2021
Bearbeitet: yanqi liu am 29 Dez. 2021
net=newff([0,1],[5,1],{'tansig','logsig'},'traingd')
Warning: NEWFF used in an obsolete way.
See help for NEWFF to update calls to the new argument list. net = Neural Network name: 'Custom Neural Network' userdata: (your custom info) dimensions: numInputs: 1 numLayers: 2 numOutputs: 1 numInputDelays: 0 numLayerDelays: 0 numFeedbackDelays: 0 numWeightElements: 16 sampleTime: 1 connections: biasConnect: [1; 1] inputConnect: [1; 0] layerConnect: [0 0; 1 0] outputConnect: [0 1] subobjects: input: Equivalent to inputs{1} output: Equivalent to outputs{2} inputs: {1x1 cell array of 1 input} layers: {2x1 cell array of 2 layers} outputs: {1x2 cell array of 1 output} biases: {2x1 cell array of 2 biases} inputWeights: {2x1 cell array of 1 weight} layerWeights: {2x2 cell array of 1 weight} functions: adaptFcn: 'adaptwb' adaptParam: (none) derivFcn: 'defaultderiv' divideFcn: (none) divideParam: (none) divideMode: 'sample' initFcn: 'initlay' performFcn: 'mse' performParam: .regularization, .normalization plotFcns: {'plotperform', 'plottrainstate', 'plotregression'} plotParams: {1x3 cell array of 3 params} trainFcn: 'traingd' trainParam: .showWindow, .showCommandLine, .show, .epochs, .time, .goal, .min_grad, .max_fail, .lr weight and bias values: IW: {2x1 cell} containing 1 input weight matrix LW: {2x2 cell} containing 1 layer weight matrix b: {2x1 cell} containing 2 bias vectors methods: adapt: Learn while in continuous use configure: Configure inputs & outputs gensim: Generate Simulink model init: Initialize weights & biases perform: Calculate performance sim: Evaluate network outputs given inputs train: Train network with examples view: View diagram unconfigure: Unconfigure inputs & outputs
net.performFcn
ans = 'mse'
for more information,please check
  2 Kommentare
Neelabh Jyoti Saharia
Neelabh Jyoti Saharia am 30 Dez. 2021
Hi sir,
I can see in line 141 that the performFcn is still 'mse'.
I want to replace 'mse' with my self-made loss function.
Can I get a template of the default mse.m file used by Matlab?
yanqi liu
yanqi liu am 31 Dez. 2021
yes,sir,just as
\toolbox\nnet\nnet\nnperformance
format,we can make the same functions,such as
then we use
clc; clear all; close all;
warning off all
net=newff([0,1],[5,1],{'tansig','logsig'},'traingd');
net.performFcn
net.performFcn = 'self_made_loss_function';
net.performFcn
can get result
ans =
'mse'
ans =
'self_made_loss_function'
>>

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by