简体   繁体   English

性能与计算粗麻布

[英]Performance w/ calculating Hessian

[edit] The part about "f" is solved. [编辑]关于“ f”的部分已解决。 Here is what I did: Instead of using: 这是我所做的:而不是使用:

X = (F * W' - Y);
f = X' * X;

I'm now using: 我现在正在使用:

X = F*W;
A = X'*F*W;
B = -2*X'*Y;
Y1 = Y'*Y;
f = A + B + Y1

This will give a massive speed up. 这将大大提高速度。 Still, the problem with the Hessian of f remains. 尽管如此,f的Hessian问题仍然存在。 [/edit] [/编辑]

So, I'm having some serious performance "problems" with a quadratic optimization problem I'm trying so solve in Matlab. 因此,我遇到了一些严重的性能“问题”,并尝试在Matlab中解决二次优化问题。 The problem is not the optimization per se, but the calculation of the target function and the Hessian. 问题不是优化本身,而是目标函数和Hessian的计算。 Right now it looks like this (F and Y aren't random at all and will have real data, also it is not neccesarily unconstrainted, because then the solution would of course be (F'F)^-1*F'*Y): 现在看起来像这样(F和Y根本不是随机的,并且将具有真实数据,并且也不一定不受限制,因为那样的话,解决方案当然是(F'F)^-1 * F'* Y ):

W_a = sym('w_a_%d', [1 96]);
W_b = sym('w_b_%d', [1 96]);

for i = 1:96
    W(1,2*(i-1)+1) = W_a(1,i);
    W(1,2*i) = W_b(1,i);
end
F = rand(10000,192);
Y = rand(10000,1);
q = [];
for i = 1:192
    q = [q sum(-Y(:).*F(:,i))];
end
q = 2*q;
q = double(q);

X = (F * W' - Y);
f = X' * X;

H = hessian(f);
H = double(H);

A=[]; b=[];
Aeq=[]; beq=[];
lb=[]; ub=[];
options=optimset('Algorithm', 'active-set', 'Display', 'off');
[xsol,~,exitflag,output]=quadprog(H, q, A, b, Aeq, beq, lb, ub, [], options);

The thing is: calculating f and H takes like forever. 问题是:计算f和H就像永远。

I'm not expecting that there are ways to significantly speed this up, since Matlab is optimized for stuff like this. 我不期望有任何方法可以显着加快此速度,因为Matlab针对此类问题进行了优化。 But maybe someone knows some open license software, that's almost as fast as Matlab, so that I could calculate f and H with that software on a faster machine (which unfortunately has no Matlab license ...) and then let Matlab do the optimization. 但是也许有人知道一些开放许可证的软件,其速度几乎与Matlab一样快,因此我可以在较快的计算机(不幸的是没有Matlab许可证...)上使用该软件来计算f和H,然后让Matlab进行优化。

Right now I'm kinda lost in this :/ 现在我有点迷失在这个:/

Thank you very much in advance. 提前非常感谢您。 Even some keywords could help me here like "Look for software xy" 甚至有些关键字也可以在这里为我提供帮助,例如“寻找软件xy”

If speed is your concern, using symbolic methods is usually the wrong approach (especially for large systems or if you need to run something repeatedly). 如果您关心速度,那么使用符号方法通常是错误的方法(尤其是对于大型系统或需要重复运行某些方法)。 You'll need to calculate your Hessian numerically. 您需要以数字方式计算您的Hessian。 There's an excellent utility on the MathWorks FileExchange that can do this for you: the DERIVESTsuite . MathWorks FileExchange上有一个出色的实用程序可以为您做到这一点: DERIVESTsuite It includes a numeric hessian function. 它包括一个数字hessian函数。 You'll need to formulate your f as a function of X . 您需要将fX的函数。

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

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