IonOne
IonOne

Reputation: 385

Custom performance function in Matlab

i want to add a custom perf function in my neural network to use wavelets functions as perf (i first decompose the signal using wavelets, then recompose the signal and compute the perf from it)

I've tried the academic way explained here: http://www.mathworks.fr/support/solutions/en/data/1-1BYOH/index.html?product=NN&solution=1-1BYOH

so i create a .m file called MyPerformanceFunction.m and add :

function perf = MyPerformanceFunction(e, x, pp)
perf = 1;

and change the perf function as :

net.performFcn = 'MyPerformanceFunction';

just for testing

but i got an error :

Error using struct
Conversion to struct from double is not possible.

Error in network/subsasgn>getDefaultParam (line 2023)
    param = struct(feval(fcn,'defaultParam'));

Error in network/subsasgn>setPerformFcn (line 1886)
net.performParam = getDefaultParam(performFcn);

Error in network/subsasgn>network_subsasgn (line 445)
    if isempty(err), [net,err]=setPerformFcn(net,performFcn); end

Error in network/subsasgn (line 13)
net = network_subsasgn(net,subscripts,v,netname);

Error in nntest3 (line 26)
net.performFcn = 'MyPerformanceFunction';

any one has an idea where it might come from?

i use R2013a

thanks

Jeff

Upvotes: 0

Views: 1941

Answers (1)

nkjt
nkjt

Reputation: 7817

Short answer: It won't work, because it's not enough to have just a single function to implement a custom performance function.

Long answer:

This line:

param = struct(feval(fcn,'defaultParam'));

Is equivalent to:

param = MyPerformanceFunction('defaultParam')

The inbuilt performance functions, such as mse, sse, mae etc. are set up such that in addition to returning perf as a number, they can return other information. For example, just calling mae without any inputs returns:

ans = 

         WARNING1: 'THIS IS AN IMPLEMENTATION STRUCTURE'
         WARNING2: 'THIS INFORMATION MAY CHANGE WITHOUT NOTICE'
             name: 'Mean Absolute Error'
        mfunction: 'mae'
             type: 'performance_fcn'
         typeName: 'Performance Function'
        normalize: 1
            apply: @mae.apply
         backprop: @mae.backprop
      forwardprop: @mae.forwardprop
        dperf_dwb: @mae.dperf_dwb
    parameterInfo: [1x2 nnetParamInfo]
     defaultParam: [1x1 struct]

A performance function is more than just a single function returning a value perf - there is also an associated subdirectory of additional functions which all need to be present. If you want to do this, the best way would be to use an existing performance function as a template.

Type help nncustom to see the advice about creating various custom functions for neural networks. For example my version gives:

Performance functions
    Functions created before R2012b must be updated.
    Use mse and its package of subfunctions +mse as templates.

Upvotes: 2

Related Questions