如何自定义MATLAB神经网络的误差函数
我想将此函数实现为训练神经网络的误差函数:
function err = MyErrorFunction(T,O)
d = T - O;
err = -d*( exp(-d) - 1 );
end
其中 T
是目标值,O
是输入的神经网络输出。
训练算法并不重要(显然 trainlm
的误差函数不可自定义,因此我可以使用 trainscg
)。
我发现 本文建议使用template_performance.m
文件来定义新的性能函数。我说我只是复制这个文件并根据需要自定义它。
显然,从 MATLAB 2010 开始,template_performance.m
已被弃用。
那么,在训练神经网络时如何改变计算/评估误差/性能的方式呢?
I want to implement this function as the error function for training a neural network:
function err = MyErrorFunction(T,O)
d = T - O;
err = -d*( exp(-d) - 1 );
end
where T
is target value and O
is neural network output for an input.
The training algorithm doesn't matter (apparently error function for trainlm
is not customizable, so I can go with the trainscg
).
I've found this article that suggests using the template_performance.m
file to define a new performance function. I says I just have copy this file and customize it as I want.
But as I have understood, `template_performance.m` is a template for **performance** function, not the **error** function: `template_performance.m` gets the error values and output a performance value, for instance it could sum up the square of the errors and output them (SSE).
Apparently, template_performance.m
have been deprecated starting from MATLAB 2010.
So, how I can change the way that error/performance is calculated/evaluated when training a neural network?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了类似的问题……定制性能函数的整个过程完全是一场灾难。很多东西都在贬值,而且关于我们应该做什么的文档为零。
我最终不得不破解我不打算使用的性能函数(SSE)的核心文件。在 matlab 目录
MATLAB\R2012b\toolbox\nnet\nnet\nnperformance
下您可以找到它们。我根据t
、t-1
的变化修改了 apply.m(在 SSE+ 文件夹中)函数,并使用了一些方向权重。但后来我遇到了训练算法以与perform()
不同的方式和格式向apply()
发送参数的问题。我最终没有使用perform()
并为此编写了自己的代码。天啊……一团糟。这是一个非常丑陋的黑客行为,我很想听听任何找到正确方法的人的意见。
I had a similar problem ... the whole thing about customizing a performance function is a total disaster. A lot of stuff is being depreciated and there is zero documentation on what we should do.
I ended up having to hack the core files of a performance function I wasn't planning on using (SSE). Under the matlab directory
MATLAB\R2012b\toolbox\nnet\nnet\nnperformance
you can find them. I modified the apply.m (in the SSE+ folder) function with some directional weights based ont
,t-1
change. But then I ran into the problem of training algorithms sending parameters toapply()
in a different way AND format thanperform()
. I ended up not usingperform()
and writing my own code for that. Jesus... Total mess.This was a very ugly hack and I'd love to hear from anyone who found the correct way to do this.
据我了解,性能函数既用于训练又用于测试/评估(除非某种训练算法被硬编码为特定函数)
From what I understand, the performance function is used both for training and testing/evaluation (unless a certain training algorithm is hard-coded to a specific function)