简体   繁体   English

Levenberg-Marquardt在Java中的最小化

[英]Levenberg-Marquardt minimization in Java

I generally code in MATLAB, but for some reasons I decided to switch to a JAVA approach. 我通常在MATLAB中编写代码,但出于某些原因我决定改用JAVA方法。

The question is quite easy: I'd like understanding how to translate the following MATLAB code into a working JAVA's one. 问题很简单:我想了解如何将以下MATLAB代码转换为可用的JAVA代码。

Within MATLAB I have a target function called findZ0 : 在MATLAB中我有一个名为findZ0的目标函数:

function F = findZ0(V, Z, Latitude, TI, x)
%%% Inputs
% V = Average Wind Speed at Hub Height
% Z = Hub Height;
% Latitude = Specific Site Latitude (default value equal to 50 deg);
% x = Tryout Roughness length;
% TI = Target Turbulent Intensity;
%%% Outputs
% F = Roughness Length tuned to match Target Turbulent Intensity

Latitude = deg2rad(Latitude);
omega = 72.9E-06;
f = 2*omega*sin(Latitude);
ustar = ( 0.4*V - 34.5*f*Z)/log(Z/x);
mu = 1 - ((6*f*Z)/(ustar));
p = mu^(16);
sigmaTarget = (V*TI)/100;

F = sigmaTarget - (( 7.5*mu*ustar*((0.538 + .09*log(Z/x))^p) )/(1 + .156*log(ustar/(f*x))));
end

I then called this lines: 然后我称这行:

Uhub = 8;
HubHt = 90;
Latitude = 50;
x_trial = 0.01;
TI_target = 24;

find_z0 = @(x) findZ0(Uhub,HubHt,Latitude,TI_target, x);
z0 = fsolve(find_z0,x_trial,{'fsolve','Jacobian','on','levenberg-marquardt',.005,'MaxIter',15000,'TolX',1e-07,'TolFun',1E-07,'Display','off'});

I am aware that Fortran packages have been imported in Java, but I don't really have a clue how to achieve my goal by applying the mentioned tools. 我知道Fortran软件包已经用Java导入了,但我并不知道如何通过应用上述工具来实现我的目标。 Hence, I'd welcome any suggestion on how to overcome this problem. 因此,我欢迎任何关于如何克服这个问题的建议。

I'd suggest using an existing solution like Apache Commons - it's a robust library containing a lot of tools you may find helpful. 我建议使用像Apache Commons这样的现有解决方案 - 它是一个强大的库,包含许多你可能会发现有用的工具。

The LM optimization method is implemented by this class - you can either use it directly or just look at it for inspiration. LM优化方法由此类实现 - 您可以直接使用它,也可以只看它以获得灵感。

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

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