简体   繁体   English

倍频程最小化

[英]Octave repeated function minimisation

So I'm trying to perform k-fold cross-validation on a dataset, but am having problems getting octave to accept the input. 因此,我试图对数据集执行k倍交叉验证,但是在获取八度音阶来接受输入时遇到了问题。 First I tried using a nested squared loss function upon which to run fminunc, but Octave just says that isn't supported yet. 首先,我尝试使用嵌套平方损失函数来运行fminunc,但是Octave只是说尚不支持。 My next attempt has a squaredLoss function file that acts upon a global dataset that I change in my main function each time, but it keeps throwing back that the dataset is undefined. 我的下一个尝试是使用squaredLoss函数文件,该文件作用于我每次在主函数中更改的全局数据集,但是不断抛出该数据集未定义的情况。 As I can't pass the dataset as a parameter to fminunc, how should I work around this (or am I using globals wrong?) 由于我无法将数据集作为参数传递给fminunc,因此应如何解决(或者我是否使用全局变量错误?)

for i = 1:NUMBER_OF_FOLDS
    global funcdata;
    funcdata = data{i};
    [theta(i), ~] = fminunc(squaredLoss, theta0);
endfor

Where squaredLoss(theta) uses funcdata as if it's a local variable. 其中squaredLoss(theta)使用funcdata就像是局部变量一样。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Okay, so it would seem that while Octave does not support nested functions you can use anonymous functions instead see here . 好的,因此,似乎Octave不支持嵌套函数,您可以使用匿名函数代替, 请参见here So a solution to my given example would be: 因此,给定示例的解决方案是:

function loss = squaredLoss(coef, funcdata)
    ...
endfunction

for the squaredLoss function file and this in my cross-validation loop: 用于squaredLoss函数文件,这在我的交叉验证循环中:

for i = 1:NUMBER_OF_FOLDS
    funcdata = data{i};
    lossFunction = @(coef)squaredLoss(coef, funcdata);
    [theta(i), ~] = fminunc(lossFunction, theta0);
endfor

Good luck wandering souls! 祝你好运流浪的灵魂!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM